From: mka Date: Thu, 12 Dec 2013 13:05:56 +0000 (+0000) Subject: Fix for some problems with definition uses. X-Git-Tag: V1_0_0~10 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;ds=sidebyside;h=6273a46aa9ca47e2a4f1eb08a0230ec9f1b44f57;p=tools%2Fsiman.git Fix for some problems with definition uses. --- diff --git a/Workspace/Siman-Common/src/org/splat/service/PublicationService.java b/Workspace/Siman-Common/src/org/splat/service/PublicationService.java index 06fabb7..0f78d44 100644 --- a/Workspace/Siman-Common/src/org/splat/service/PublicationService.java +++ b/Workspace/Siman-Common/src/org/splat/service/PublicationService.java @@ -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 list, + final Publication publication, final List 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); } + diff --git a/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java index 5439663..92652e8 100644 --- a/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java @@ -155,9 +155,12 @@ public class PublicationServiceImpl implements PublicationService { final List 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 list, + final Publication publication, final List defuses) { + for (Iterator 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 compatible = new HashSet(); - 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 compatible = new HashSet(); + 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 steps) { for (Iterator i = steps.iterator(); i.hasNext();) { List * published = i.next().getAllDocuments(); for (Iterator j = published.iterator(); j.hasNext();) { Publication found = diff --git a/Workspace/Siman/src/org/splat/simer/EditDocumentAction.java b/Workspace/Siman/src/org/splat/simer/EditDocumentAction.java index d168d5c..8602af8 100644 --- a/Workspace/Siman/src/org/splat/simer/EditDocumentAction.java +++ b/Workspace/Siman/src/org/splat/simer/EditDocumentAction.java @@ -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; diff --git a/Workspace/Siman/src/org/splat/simer/OpenStudy.java b/Workspace/Siman/src/org/splat/simer/OpenStudy.java index fc76dfd..ef99e32 100644 --- a/Workspace/Siman/src/org/splat/simer/OpenStudy.java +++ b/Workspace/Siman/src/org/splat/simer/OpenStudy.java @@ -139,7 +139,7 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices { _context = new ArrayList(); if (_selection.equals("0.1")) { _ustep = getProjectElementService().getFirstStep(_mystudy); - } + } _ustep.setActor(_cuser); if ((_involving.isEmpty()) || (_involving.get(0).getOwnerStudy().getIndex() != _ustep.getOwnerStudy().getIndex())) { diff --git a/Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java b/Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java index 9073364..1eeaabe 100644 --- a/Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java +++ b/Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java @@ -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(); @@ -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 = _defuses.iterator(); document.hasNext(); ) { - Publication pub = tag.getOwner().getPublication(document.next()); - if(pub != null && pub.getRelations(UsesRelation.class).contains(tag)) { - document.remove(); + List toDeleteFromDefuses = new ArrayList(); + getPublicationService().findSequenceUses(toDeleteFromDefuses, tag, + _defuses); + for (Document document : toDeleteFromDefuses) { + if (_defuses.contains(document)) { + _defuses.remove(document); } }