From b590a5c3fa6cb304104cbb1e75a57cf0ca31999c Mon Sep 17 00:00:00 2001 From: mka Date: Mon, 1 Jul 2013 11:38:33 +0000 Subject: [PATCH] Correction of the uses variants during version operation --- .../org/splat/service/PublicationService.java | 11 +++ .../splat/service/PublicationServiceImpl.java | 87 ++++++++++++++++++- .../src/spring/businessServiceContext.xml | 2 + .../src/org/splat/simer/DocumentFacade.java | 28 +++--- .../splat/simer/VersionDocumentAction.java | 2 +- 5 files changed, 114 insertions(+), 16 deletions(-) diff --git a/Workspace/Siman-Common/src/org/splat/service/PublicationService.java b/Workspace/Siman-Common/src/org/splat/service/PublicationService.java index 1bc4082..bc5ccc3 100644 --- a/Workspace/Siman-Common/src/org/splat/service/PublicationService.java +++ b/Workspace/Siman-Common/src/org/splat/service/PublicationService.java @@ -18,6 +18,7 @@ import java.util.List; import org.splat.dal.bo.kernel.User; import org.splat.dal.bo.som.ConvertsRelation; +import org.splat.dal.bo.som.Document; import org.splat.dal.bo.som.DocumentType; import org.splat.dal.bo.som.ProgressState; import org.splat.dal.bo.som.ProjectElement; @@ -293,6 +294,16 @@ public interface PublicationService { */ ConvertsRelation attach(Publication aPublication, String format, String description); + + /** + * Searches for a document which is connected by chain of versioning operations with the given + * and belongs to a publication from given project element. + * If the given document is the last version, it will be returned. + * @param doc the document + * @param owner the project element + * @return the document if found, null otherwise + */ + Document getLastVersion(final Document doc, final ProjectElement owner); /** * Undo the out-date operation. diff --git a/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java index dd01f84..60ca0a7 100644 --- a/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java @@ -20,7 +20,9 @@ import java.util.Iterator; import java.util.List; import org.apache.log4j.Logger; +import org.hibernate.criterion.Restrictions; import org.splat.common.properties.MessageKeyEnum; +import org.splat.dal.bo.kernel.Relation; import org.splat.dal.bo.kernel.User; import org.splat.dal.bo.som.ConvertsRelation; import org.splat.dal.bo.som.Document; @@ -33,11 +35,14 @@ import org.splat.dal.bo.som.SimulationContextType; import org.splat.dal.bo.som.Study; import org.splat.dal.bo.som.Timestamp; import org.splat.dal.bo.som.UsedByRelation; +import org.splat.dal.bo.som.UsesRelation; import org.splat.dal.bo.som.ValidationCycle; import org.splat.dal.bo.som.ValidationStep; +import org.splat.dal.bo.som.VersionsRelation; import org.splat.dal.dao.som.ProjectElementDAO; import org.splat.dal.dao.som.PublicationDAO; import org.splat.dal.dao.som.TimestampDAO; +import org.splat.dal.dao.som.VersionsRelationDAO; import org.splat.exception.IncompatibleDataException; import org.splat.exception.InvalidParameterException; import org.splat.kernel.InvalidPropertyException; @@ -111,6 +116,10 @@ public class PublicationServiceImpl implements PublicationService { * Injected repository service. */ private RepositoryService _repositoryService; + /** + * Injected versions relation DAO. + */ + private VersionsRelationDAO _versionsRelationDAO; /** * {@inheritDoc} @@ -655,6 +664,50 @@ public class PublicationServiceImpl implements PublicationService { return aPublication.getStep(); } + /** + * {@inheritDoc} + * @see org.splat.service.PublicationService#getLastVersion(org.splat.dal.bo.som.Document, org.splat.dal.bo.som.ProjectElement) + */ + @Transactional(readOnly=true) + public Document getLastVersion(final Document doc, final ProjectElement owner) { + Document theLastVersion = _documentService.selectDocument(doc.getIndex()); //get document attached to hibernate session + ProjectElement trueOwner = _projectElementDAO.merge(owner); + if(trueOwner.getPublication(theLastVersion) == null) { //start recursive search + List relations = _versionsRelationDAO + .getFilteredList(Restrictions.eq("refer", theLastVersion)); + //there may be several next versions if document is shared between scenarios, + //but only one leads to a publication from given project elements. + for(Relation relation : relations) { + Document candidate = getLastVersion((Document)(relation.getFrom()), trueOwner); + if(candidate != null ) { + theLastVersion = candidate; + } + } + } + if(theLastVersion != null && trueOwner.getPublication(theLastVersion) == null) { + theLastVersion = null; + } + return theLastVersion; + } + + /** + * Check if this publication is outdated and other publications used by it are up-to-date. + * + * @param aPublication + * the publication + * @return true if succeeded + */ + @Transactional(readOnly=true) + private boolean canBeActualized(final Publication aPublication) { + boolean res = aPublication.isOutdated(); + for(Publication used : aPublication.getRelations(UsesRelation.class)) { + if(used.isOutdated()) { + res = false; + } + } + return res; + } + /** * Undo the out-date operation. * @@ -666,10 +719,26 @@ public class PublicationServiceImpl implements PublicationService { */ @Transactional public boolean actualize(final Publication aPublication) { - boolean res = aPublication.isOutdated(); + boolean res = aPublication.isOutdated() && canBeActualized(aPublication); if (res) { + //Replace dependencies to old versions of documents with dependencies to the latest versions. + for(Relation rel : aPublication.value().getRelations(UsesRelation.class)) { + Document used = (Document)rel.getTo(); + if(aPublication.getOwnerStudy().getPublication(used) == null) { + aPublication.value().removeRelation(UsesRelation.class, used); + //There is always a last version + Document theLastVersion = getLastVersion(used, aPublication.getOwner()); + aPublication.addDependency(theLastVersion); + } + } + aPublication.setIsnew('Y'); getPublicationDAO().update(aPublication); + + //recursively actualize all documents that don't use any more outdated documents. + for(Publication using : aPublication.getRelations(UsedByRelation.class)) { + actualize(using); + } } return res; } @@ -1021,4 +1090,20 @@ public class PublicationServiceImpl implements PublicationService { } return res; } + + /** + * Get the versionsRelationDAO. + * @return the versionsRelationDAO + */ + public VersionsRelationDAO getVersionsRelationDAO() { + return _versionsRelationDAO; + } + + /** + * Set the versionsRelationDAO. + * @param versionsRelationDAO the versionsRelationDAO to set + */ + public void setVersionsRelationDAO(final VersionsRelationDAO versionsRelationDAO) { + _versionsRelationDAO = versionsRelationDAO; + } } diff --git a/Workspace/Siman-Common/src/spring/businessServiceContext.xml b/Workspace/Siman-Common/src/spring/businessServiceContext.xml index cb66222..37a4c9e 100644 --- a/Workspace/Siman-Common/src/spring/businessServiceContext.xml +++ b/Workspace/Siman-Common/src/spring/businessServiceContext.xml @@ -74,6 +74,8 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> + relist = _me.getRelations(UsesRelation.class); - - _uses = new ArrayList(relist.size()); - for (Iterator i = relist.iterator(); i.hasNext();) { - Publication used = i.next(); - long index = used.getIndex(); - DocumentFacade facade = _owner._docpres.get(index); - if (facade == null) { - facade = new DocumentFacade(_owner, used, + List used = _me.value().getRelations(UsesRelation.class); + + _uses = new ArrayList(); + for(Relation relation : used) { + Document doc = (Document)relation.getTo(); + Publication pub = _me.getOwner().getPublication( + _publicationService.getLastVersion(doc, _me.getOwner())); + DocumentFacade facade = _owner._docpres.get(pub.getIndex()); + if (facade == null && pub != null) { + facade = new DocumentFacade(_owner, pub, getProjectSettings(), getPublicationService(), getApplicationSettings()); - _owner._docpres.put(index, facade); + _owner._docpres.put(pub.getIndex(), facade); } _uses.add(facade); } @@ -565,9 +565,9 @@ public class DocumentFacade implements HistoryFacade { _sharing = "image.share.png"; _updated = "icon.hold.png"; } - if (_me.isOutdated()) { - _state = ProgressState.inWORK; // Overrides the document state - } + //if (_me.isOutdated()) { + // _state = ProgressState.inWORK; // Overrides the document state + //} } } diff --git a/Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java b/Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java index 5c41b26..b4ec29a 100644 --- a/Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java +++ b/Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java @@ -81,7 +81,7 @@ public class VersionDocumentAction extends BaseUploadDocumentAction { // Add additional documents used by the current version for (Relation usesRel : doc.getRelations(UsesRelation.class)) { Document used = (Document) usesRel.getTo(); - if (!_defuses.contains(used)) { + if (!_defuses.contains(getPublicationService().getLastVersion(used, tag.getOwner()))) { _defuses.add(used); } } -- 2.39.2