]> SALOME platform Git repositories - tools/siman.git/commitdiff
Salome HOME
Fix for some problems with definition uses.
authormka <mka@opencascade.com>
Thu, 12 Dec 2013 13:05:56 +0000 (13:05 +0000)
committermka <mka@opencascade.com>
Thu, 12 Dec 2013 13:05:56 +0000 (13:05 +0000)
Workspace/Siman-Common/src/org/splat/service/PublicationService.java
Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java
Workspace/Siman/src/org/splat/simer/EditDocumentAction.java
Workspace/Siman/src/org/splat/simer/OpenStudy.java
Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java

index 06fabb779624f99a9600be6a7cfea28b102d44f1..0f78d446f596069a8294b8e64d0875280e892a32 100644 (file)
@@ -367,4 +367,36 @@ public interface PublicationService {
         * @return true if succeeded
         */
        boolean canBeActualized(Publication aPublication);
+       
+       /**
+     * Find the documents, which using the old version of document.
+     *
+     * @param list
+     *            the list of documents uses versioning document
+     * @param publication
+     *            publication, which is check by use the documents in _defuses list
+     * @param defuses
+     *            the list of default uses documents
+     */
+    void findSequenceUses(final List<Document> list,
+            final Publication publication, final List<Document> defuses);
+
+       /**
+     * Update relations after creation of a new document version.
+     *
+     * @param step
+     *            current Step
+     * @param current
+     *            the current version
+     * @param next
+     *            the new version
+     * @param docuses
+     *            ids of used documents
+     * @param docusedby
+     *            ids of documents used by the versioned one.
+     */
+    public void updateRelations(final Step step, final Publication current,
+            final Publication next, final String[] docuses,
+            final long[] docusedby);
 }
+
index 5439663040c205e4316f2a9ddf9ac79c429ae2d0..92652e8d0056eaf050e335ba0bf6ef1f4e0e3809 100644 (file)
@@ -155,9 +155,12 @@ public class PublicationServiceImpl implements PublicationService {
                        final List<Long> docuses) throws MissedPropertyException,
                        InvalidPropertyException, MultiplyDefinedException, IOException,
                        NotApplicableException, InterruptedException, ParseException {
+               DocumentType type = getDocumentTypeService().selectType(
+                               (int) documentTypeId);
                User user = getUserService().selectUser(userId);
                File updir = getRepositoryService().getDownloadDirectory(user);
                File upfile = new File(updir.getPath() + "/" + fname);
+               String[] table = fname.split("\\x2E");
 
                // Creation of the document
                Document.Properties dprop = new Document.Properties();
@@ -166,9 +169,6 @@ public class PublicationServiceImpl implements PublicationService {
 
                if (reference.length() == 0) { // Importation of a foreign document
                        // TODO: Extract property of supported documents (DOCX, ODT...)
-                       DocumentType type = getDocumentTypeService().selectType(
-                                       (int) documentTypeId);
-                       String[] table = fname.split("\\x2E");
                        addoc = getStepService().createDocument(
                                        step,
                                        dprop.setName(doctitle).setType(type).setFormat(
@@ -209,8 +209,10 @@ public class PublicationServiceImpl implements PublicationService {
                // Creation of uses relations
                if (docuses != null) {
                        for (Long index : docuses) {
-                               Document used = getDocumentService().selectDocument(index);
+                               Document used = getDocumentService().
+                                       selectDocument(index);
                                Publication pub = step.getDocument(index);
+                               // updating uses relations on publication in step
                                if (pub == null) {
                                    for (Publication doc : step.getOwner().
                                            getDocums()) {
@@ -221,7 +223,8 @@ public class PublicationServiceImpl implements PublicationService {
                                    }
                                }
                                if (pub == null) {
-                                   for (Publication doc : step.getOwnerStudy().getDocums()) {
+                                   for (Publication doc : step.getOwnerStudy().
+                                           getDocums()) {
                         if (doc.value().getIndex() == index) {
                             pub = doc;
                             break;
@@ -302,12 +305,39 @@ public class PublicationServiceImpl implements PublicationService {
 
                // Creation of uses relations
                Publication syncronizedCurrent = _publicationDAO.get(current.getIndex());
-               updateRelations(syncronizedCurrent, next, docuses, docusedby);
+               updateRelations(step, syncronizedCurrent, next, docuses, docusedby);
        }
 
+       /**
+     * Find the documents, which using the old version of document.
+     *
+     * @param list
+     *            the list of documents uses versioning document
+     * @param publication
+     *            publication, which is check by use the documents in _defuses list
+     * @param defuses
+     *            the list of default uses documents
+     */
+    public final void findSequenceUses(final List<Document> list,
+            final Publication publication, final List<Document> defuses) {
+        for (Iterator<Document> document = defuses.iterator(); document
+                .hasNext();) {
+            Publication pub = publication.getOwner().getPublication(
+                    document.next());
+            if (pub != null
+                    && pub.getRelations(UsesRelation.class).
+                    contains(publication)) {
+                findSequenceUses(list, pub, defuses);
+                list.add(pub.value());
+            }
+        }
+    }
+
        /**
         * Update relations after creation of a new document version.
-        * 
+        *
+        * @param step
+     *            current Step
         * @param current
         *            the current version
         * @param next
@@ -317,30 +347,40 @@ public class PublicationServiceImpl implements PublicationService {
         * @param docusedby
         *            ids of documents used by the versioned one.
         */
-       private void updateRelations(final Publication current,
-                       final Publication next, final String[] docuses,
-                       final long[] docusedby) {
-               if (docuses != null) {
-                       for (int i = 0; i < docuses.length; i++) {
-                               Long index = Long.valueOf(docuses[i].trim());
-                               Document used = getDocumentService().selectDocument(index);// RKV: getPublication(index, steps);
-                               next.addDependency(used);
-                       }
-               }
-               // Outdating impacted document
-               HashSet<Long> compatible = new HashSet<Long>();
-               if (docusedby != null) {
-                       for (int i = 0; i < docusedby.length; i++) {
-                               compatible.add(docusedby[i]);
-                       }
-               }
-               for (Publication using : current.getRelations(UsedByRelation.class)) {
-                       if (!compatible.contains(using.getIndex())) {
-                               outdate(using);
-                       }
-               }
-       }
-
+    public void updateRelations(final Step step, final Publication current,
+            final Publication next, final String[] docuses,
+            final long[] docusedby) {
+        if (docuses != null) {
+            for (int i = 0; i < docuses.length; i++) {
+                Long index = Long.valueOf(docuses[i].trim());
+                Document used = getDocumentService().selectDocument(index);// RKV:getPublication(index, steps);
+                next.addDependency(used);
+                if (used.getStep() == step.getNumber()) {
+                    step.getDocument(used.getIndex()).setValue(used);
+                }
+            }
+        }
+        // Outdating impacted document
+        HashSet<Long> compatible = new HashSet<Long>();
+        if (docusedby != null) {
+            for (int i = 0; i < docusedby.length; i++) {
+                compatible.add(docusedby[i]);
+            }
+        }
+        for (Publication using : current.getRelations(UsedByRelation.class)) {
+            if (compatible.contains(using.getIndex())) {
+                current.value().removeRelation(UsedByRelation.class,
+                        using.value());
+                using.addDependency(next);
+                if (step.getNumber() == using.value().getStep()) {
+                    step.getDocument(using.value().getIndex()).setValue(
+                            using.value());
+                }
+            } else {
+                outdate(using);
+            }
+        }
+    }
        /*
         * protected Publication getPublication(int index, List<Step> steps) { for (Iterator<Step> i = steps.iterator(); i.hasNext();) { List<Publication>
         * published = i.next().getAllDocuments(); for (Iterator<Publication> j = published.iterator(); j.hasNext();) { Publication found =
index d168d5c4678d635e38b42cb5624b93c1042a9142..8602af85bf3da48d50b83b7d7f24c5e365182765 100644 (file)
@@ -207,6 +207,8 @@ public class EditDocumentAction extends DisplayStudyStepAction {
 
                setMenu();
                _openStudy = getOpenStudy();
+               // updating current step and doc relations
+               _openStudy.updateCurrentStep();
                Step step = _openStudy.getSelectedStep();
 
                if (getStepService().removeDocument(step, Long.valueOf(_index))) { // Updates the data structure
@@ -216,6 +218,8 @@ public class EditDocumentAction extends DisplayStudyStepAction {
                        }
                        _openStudy = open(getStudyService().selectStudy(
                                        _openStudy.getIndex())); // Closes the previously open study
+                       //updating relations and pop-up menu
+                       _openStudy.updateCurrentStep();
                        _openStudy.setSelection(_selection);
                }
                return SUCCESS;
index fc76dfddef8ed3a51389afe8d3dbb1c23c775a48..ef99e321fb468b7dccef9ca75f7534a6d8eb18ce 100644 (file)
@@ -139,7 +139,7 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
                _context = new ArrayList<SimulationContextFacade>();
                if (_selection.equals("0.1")) {
                        _ustep = getProjectElementService().getFirstStep(_mystudy);
-               }               
+               }
                _ustep.setActor(_cuser);        
                if ((_involving.isEmpty()) || (_involving.get(0).getOwnerStudy().getIndex()
                                != _ustep.getOwnerStudy().getIndex())) {
index 90733644a26a13fa2c333d2f464ab4891df951f6..1eeaabe06b8dfeabc5f4be792f2d9b03391f5ce6 100644 (file)
@@ -21,6 +21,8 @@ import org.splat.dal.bo.som.ValidationStep;
 import org.splat.kernel.InvalidPropertyException;
 import org.splat.manox.Reader;
 import org.splat.manox.Toolbox;
+import org.splat.service.PublicationService;
+import org.splat.service.StudyService;
 import org.splat.som.Revision;
 import org.splat.som.Step;
 import org.splat.wapp.Constants;
@@ -65,6 +67,7 @@ public class VersionDocumentAction extends BaseUploadDocumentAction {
                File upfile = commonInitialize(Constants.TRUE);
 
                _mystudy = getOpenStudy();
+               //updating relations of docs
                _mystudy.updateCurrentStep();
                _defuses = new ArrayList<Document>();
                
@@ -95,10 +98,12 @@ public class VersionDocumentAction extends BaseUploadDocumentAction {
                        
                        // Avoid using of documents dependent on the current version of the document being versioned
                        // (This case is possible only if both documents belong to the step of the same Project Element)
-                       for(Iterator<Document> document = _defuses.iterator(); document.hasNext(); ) {
-                               Publication pub = tag.getOwner().getPublication(document.next());
-                               if(pub != null && pub.getRelations(UsesRelation.class).contains(tag)) {
-                                       document.remove();
+                       List<Document> toDeleteFromDefuses = new ArrayList<Document>();
+                       getPublicationService().findSequenceUses(toDeleteFromDefuses, tag,
+                                       _defuses);
+                       for (Document document : toDeleteFromDefuses) {
+                               if (_defuses.contains(document)) {
+                                       _defuses.remove(document);
                                }
                        }