]> SALOME platform Git repositories - tools/siman.git/commitdiff
Salome HOME
Correction of the uses variants during version operation
authormka <mka@opencascade.com>
Mon, 1 Jul 2013 11:38:33 +0000 (11:38 +0000)
committermka <mka@opencascade.com>
Mon, 1 Jul 2013 11:38:33 +0000 (11:38 +0000)
Workspace/Siman-Common/src/org/splat/service/PublicationService.java
Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java
Workspace/Siman-Common/src/spring/businessServiceContext.xml
Workspace/Siman/src/org/splat/simer/DocumentFacade.java
Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java

index 1bc4082e4f3a9c98ac171b811c0b0cddd9b02254..bc5ccc3d1e229b0ca9053f3ec8bf62092d77e4b9 100644 (file)
@@ -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.
index dd01f84b6133acfc24185fd0ddbfe01841d38269..60ca0a7c8c8890a24ef9a57c0a547a2ae6e0f5d9 100644 (file)
@@ -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<VersionsRelation> 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;
+       }
 }
index cb6622239785d841969ab56d9ae0f27d5f1a22b3..37a4c9ebe1df3e44402c2f5994e234b08d1bb14b 100644 (file)
@@ -74,6 +74,8 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
                <property name="timestampDAO" ref="timestampDAO" />
         <property name="simulationContextService"
             ref="simulationContextService" />
+        <property name="versionsRelationDAO"
+            ref="versionsRelationDAO" />  
        </bean>
 
        <bean id="scenarioService"
index 8f9e1c6f123592d0dbcf5c869ab73540ab09e15e..9b19f6f4ba156cfd86f037a4d4a5c5ad63e03d12 100644 (file)
@@ -10,7 +10,6 @@ import java.io.File;
 import java.text.DecimalFormat;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 import java.util.ResourceBundle;
 
@@ -226,18 +225,19 @@ public class DocumentFacade implements HistoryFacade {
                        _display = State.deepopen;
                } else { // Opening the document
                        if (_uses == null) {
-                               List<Publication> relist = _me.getRelations(UsesRelation.class);
-
-                               _uses = new ArrayList<DocumentFacade>(relist.size());
-                               for (Iterator<Publication> 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<Relation> used = _me.value().getRelations(UsesRelation.class);
+                               
+                               _uses = new ArrayList<DocumentFacade>();
+                               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
+                       //}
                }
        }
 
index 5c41b269c4e91e2b1ad41ddc5657573e76a8f276..b4ec29adfe25e4226b3e38287c1a5ce3c5869117 100644 (file)
@@ -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);
                                }
                        }