From 82ea07cf236f5245a69fb31ebbae7f76ce3ae03c Mon Sep 17 00:00:00 2001 From: mka Date: Mon, 1 Jul 2013 13:51:59 +0000 Subject: [PATCH] - Set up-to date functionality is implemented; - Uses presentation during version operation functionality is implemented; - Add new simulation context functionality is improved; - Author can approve the study; - Reader cannot rename the scenario; --- .../splat/dal/bo/som/SimulationContext.java | 3 +- .../org/splat/service/PublicationService.java | 9 ++++ .../splat/service/PublicationServiceImpl.java | 50 ++++++++++--------- .../src/org/splat/service/ServiceLocator.java | 14 ++++++ .../org/splat/service/ServiceLocatorImpl.java | 20 ++++++++ .../org/splat/service/StepServiceImpl.java | 1 + .../src/org/splat/som/DocumentRights.java | 11 ++-- .../src/org/splat/som/StudyRights.java | 11 +++- .../src/spring/businessServiceContext.xml | 1 + .../Siman/WebContent/jsp/editContents.jsp | 5 +- .../Siman/WebContent/jsp/readContents.jsp | 5 +- .../study/editScenarioProperties.jsp | 13 ++++- .../org/splat/simer/ApplicationSettings.java | 36 +++++++++++-- .../src/org/splat/simer/DocumentFacade.java | 29 +++++++---- .../org/splat/simer/EditDocumentAction.java | 2 +- .../simer/EditSimulationContextAction.java | 3 ++ .../Siman/src/org/splat/simer/OpenStudy.java | 7 ++- .../splat/simer/VersionDocumentAction.java | 16 +++++- 18 files changed, 183 insertions(+), 53 deletions(-) diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/som/SimulationContext.java b/Workspace/Siman-Common/src/org/splat/dal/bo/som/SimulationContext.java index ab900bd..88698b9 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/som/SimulationContext.java +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/som/SimulationContext.java @@ -88,8 +88,7 @@ public class SimulationContext extends Persistent implements Serializable { { if (type == null) throw new MissedPropertyException("type"); if (step == null) throw new MissedPropertyException("step"); - if (value == null) throw new MissedPropertyException("value"); - if (!type.isAttachedTo(step)) throw new InvalidPropertyException("step"); + if (value == null) throw new MissedPropertyException("value"); } } // Database fetch constructor diff --git a/Workspace/Siman-Common/src/org/splat/service/PublicationService.java b/Workspace/Siman-Common/src/org/splat/service/PublicationService.java index bc5ccc3..62bca2e 100644 --- a/Workspace/Siman-Common/src/org/splat/service/PublicationService.java +++ b/Workspace/Siman-Common/src/org/splat/service/PublicationService.java @@ -339,4 +339,13 @@ public interface PublicationService { */ DocToCompareDTO getDocToCompareDTO(long publicationId) throws InvalidParameterException; + + /** + * Check if this publication is outdated and other publications used by it are up-to-date. + * + * @param aPublication + * the publication + * @return true if succeeded + */ + boolean canBeActualized(Publication aPublication); } diff --git a/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java index 60ca0a7..e0bc6e6 100644 --- a/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java @@ -30,6 +30,7 @@ import org.splat.dal.bo.som.DocumentType; import org.splat.dal.bo.som.ProgressState; import org.splat.dal.bo.som.ProjectElement; import org.splat.dal.bo.som.Publication; +import org.splat.dal.bo.som.Scenario; import org.splat.dal.bo.som.SimulationContext; import org.splat.dal.bo.som.SimulationContextType; import org.splat.dal.bo.som.Study; @@ -670,9 +671,12 @@ public class PublicationServiceImpl implements PublicationService { */ @Transactional(readOnly=true) public Document getLastVersion(final Document doc, final ProjectElement owner) { - Document theLastVersion = _documentService.selectDocument(doc.getIndex()); //get document attached to hibernate session + Document document = _documentService.selectDocument(doc.getIndex()); //get document attached to hibernate session ProjectElement trueOwner = _projectElementDAO.merge(owner); - if(trueOwner.getPublication(theLastVersion) == null) { //start recursive search + Document theLastVersion = null; + if(trueOwner.getPublication(document) != null) { + theLastVersion = document; + } else { //start recursive search List relations = _versionsRelationDAO .getFilteredList(Restrictions.eq("refer", theLastVersion)); //there may be several next versions if document is shared between scenarios, @@ -684,21 +688,18 @@ public class PublicationServiceImpl implements PublicationService { } } } - if(theLastVersion != null && trueOwner.getPublication(theLastVersion) == null) { - theLastVersion = null; + if(theLastVersion == null && owner instanceof Scenario) { + theLastVersion = getLastVersion(doc, ((Scenario)owner).getOwnerStudy()); } 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 + /** + * {@inheritDoc} + * @see org.splat.service.PublicationService#canBeActualized(org.splat.dal.bo.som.Publication) */ @Transactional(readOnly=true) - private boolean canBeActualized(final Publication aPublication) { + public boolean canBeActualized(final Publication aPublication) { boolean res = aPublication.isOutdated(); for(Publication used : aPublication.getRelations(UsesRelation.class)) { if(used.isOutdated()) { @@ -719,26 +720,27 @@ public class PublicationServiceImpl implements PublicationService { */ @Transactional public boolean actualize(final Publication aPublication) { - boolean res = aPublication.isOutdated() && canBeActualized(aPublication); + Publication mergedPublication = getPublicationDAO().merge(aPublication); + boolean res = aPublication.isOutdated(); if (res) { //Replace dependencies to old versions of documents with dependencies to the latest versions. - for(Relation rel : aPublication.value().getRelations(UsesRelation.class)) { + for(Relation rel : mergedPublication.value().getRelations(UsesRelation.class)) { Document used = (Document)rel.getTo(); - if(aPublication.getOwnerStudy().getPublication(used) == null) { - aPublication.value().removeRelation(UsesRelation.class, used); + if(mergedPublication.getOwnerStudy().getPublication(used) == null) { + mergedPublication.value().removeRelation(UsesRelation.class, used); //There is always a last version - Document theLastVersion = getLastVersion(used, aPublication.getOwner()); - aPublication.addDependency(theLastVersion); + Document theLastVersion = getLastVersion(used, mergedPublication.getOwner()); + mergedPublication.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); - } + mergedPublication.setIsnew('Y'); + getPublicationDAO().update(mergedPublication); + +// //recursively actualize all documents that don't use any more outdated documents. +// for(Publication using : aPublication.getRelations(UsedByRelation.class)) { +// actualize(using); //by the way, the recursive call won't be transactional as it is not called via spring proxy +// } } return res; } diff --git a/Workspace/Siman-Common/src/org/splat/service/ServiceLocator.java b/Workspace/Siman-Common/src/org/splat/service/ServiceLocator.java index b4f0ae1..482733a 100644 --- a/Workspace/Siman-Common/src/org/splat/service/ServiceLocator.java +++ b/Workspace/Siman-Common/src/org/splat/service/ServiceLocator.java @@ -46,4 +46,18 @@ public interface ServiceLocator { * the userService to set */ void setUserService(UserService userService); + + /** + * Get the publicationService. + * + * @return the publicationService + */ + PublicationService getPublicationService(); + /** + * Set the publicationService. + * + * @param publicationService + * the publicationService to set + */ + void setPublicationService(PublicationService publicationService); } diff --git a/Workspace/Siman-Common/src/org/splat/service/ServiceLocatorImpl.java b/Workspace/Siman-Common/src/org/splat/service/ServiceLocatorImpl.java index 966d882..5a0965f 100644 --- a/Workspace/Siman-Common/src/org/splat/service/ServiceLocatorImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/ServiceLocatorImpl.java @@ -45,6 +45,10 @@ public final class ServiceLocatorImpl implements ServiceLocator { * Injected user service. */ private UserService _userService; + /** + * Injected publication service. + */ + private PublicationService _publicationService; /** * Get the studyService. @@ -77,4 +81,20 @@ public final class ServiceLocatorImpl implements ServiceLocator { public void setUserService(final UserService userService) { _userService = userService; } + + /** + * Get the publicationService. + * @return the publicationService + */ + public PublicationService getPublicationService() { + return _publicationService; + } + + /** + * Set the publicationService. + * @param publicationService the publicationService to set + */ + public void setPublicationService(final PublicationService publicationService) { + _publicationService = publicationService; + } } diff --git a/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java index 29d53c0..db9ec2c 100644 --- a/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java @@ -131,6 +131,7 @@ public class StepServiceImpl implements StepService { * @see org.splat.service.StepService#addSimulationContext(org.splat.som.Step, org.splat.dal.bo.som.SimulationContext.Properties) */ @Override + @Transactional public SimulationContext addSimulationContext(final Step aStep, final SimulationContext.Properties dprop) throws MissedPropertyException, InvalidPropertyException, diff --git a/Workspace/Siman-Common/src/org/splat/som/DocumentRights.java b/Workspace/Siman-Common/src/org/splat/som/DocumentRights.java index b757a49..9e9d724 100644 --- a/Workspace/Siman-Common/src/org/splat/som/DocumentRights.java +++ b/Workspace/Siman-Common/src/org/splat/som/DocumentRights.java @@ -99,7 +99,8 @@ public class DocumentRights { * @see Publication#accept() */ public boolean canAccept() { - return _isauthor && _operand.isOutdated(); + return _isauthor && ServiceLocatorImpl.getInstance() + .getPublicationService().canBeActualized(_operand); } /** @@ -113,7 +114,8 @@ public class DocumentRights { public boolean canApprove() { User approver = _cycle.getActor(ValidationStep.APPROVAL); // May be null if not approvable boolean res = (_user.equals(approver)) - && (_operand.getProgressState() == ProgressState.inCHECK); + && (_operand.getProgressState() == ProgressState.inCHECK) + && !_operand.isOutdated(); if (res) { List use = _operand.value().getRelations( UsesRelation.class); @@ -230,6 +232,9 @@ public class DocumentRights { User manager = _operand.getOwnerStudy().getAuthor(); User publisher = _cycle.getActor(ValidationStep.PROMOTION); // Null if the default users are involved + if(_operand.isOutdated()) { + return false; + } if (_operand.getProgressState() != ProgressState.inWORK) { if (_operand.getProgressState() == ProgressState.inDRAFT) { return canReview(); @@ -355,7 +360,7 @@ public class DocumentRights { public boolean canReview() { User reviewer = _cycle.getActor(ValidationStep.REVIEW); // May be null if not reviewable - if (!_user.equals(reviewer)) { + if (!_user.equals(reviewer) || _operand.isOutdated()) { return false; } if (_operand.getProgressState() != ProgressState.inDRAFT) { diff --git a/Workspace/Siman-Common/src/org/splat/som/StudyRights.java b/Workspace/Siman-Common/src/org/splat/som/StudyRights.java index 2eeff0e..62c0a1e 100644 --- a/Workspace/Siman-Common/src/org/splat/som/StudyRights.java +++ b/Workspace/Siman-Common/src/org/splat/som/StudyRights.java @@ -198,7 +198,7 @@ public class StudyRights { */ public boolean canApprove() { User approver = _cycle.getActor(ValidationStep.APPROVAL); // May be null if not approvable - return (_user.equals(approver)) + return (_user.equals(approver) || _isauthor) && getStudyService().canBeApproved(_operand); } @@ -284,6 +284,15 @@ public class StudyRights { return res; } + + /** + * Checks if the user has right to rename a scenario of the study. + * + * @return true if user in an author, contributor or a validation cycle member of the study. + */ + public boolean canRenameScenario() { + return _isauthor || getStudyService().hasActor(_operand, _user); + } // ============================================================================================================================== // Getter diff --git a/Workspace/Siman-Common/src/spring/businessServiceContext.xml b/Workspace/Siman-Common/src/spring/businessServiceContext.xml index 37a4c9e..7f911ca 100644 --- a/Workspace/Siman-Common/src/spring/businessServiceContext.xml +++ b/Workspace/Siman-Common/src/spring/businessServiceContext.xml @@ -16,6 +16,7 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> factory-method="getInstance"> + diff --git a/Workspace/Siman/WebContent/jsp/editContents.jsp b/Workspace/Siman/WebContent/jsp/editContents.jsp index 91797a1..c32ca88 100644 --- a/Workspace/Siman/WebContent/jsp/editContents.jsp +++ b/Workspace/Siman/WebContent/jsp/editContents.jsp @@ -59,7 +59,10 @@ " width=14 height=14 border="none" title=""/> - " border="none" title=""/> + + + " border="none" title=""/> + diff --git a/Workspace/Siman/WebContent/jsp/readContents.jsp b/Workspace/Siman/WebContent/jsp/readContents.jsp index c8c4d47..29cca49 100644 --- a/Workspace/Siman/WebContent/jsp/readContents.jsp +++ b/Workspace/Siman/WebContent/jsp/readContents.jsp @@ -40,7 +40,10 @@ " width=14 height=14 border="none" title=""/> - " border="none" title=""/> + + + " border="none" title=""/> + diff --git a/Workspace/Siman/WebContent/study/editScenarioProperties.jsp b/Workspace/Siman/WebContent/study/editScenarioProperties.jsp index 9fc64c4..4d4a2e9 100644 --- a/Workspace/Siman/WebContent/study/editScenarioProperties.jsp +++ b/Workspace/Siman/WebContent/study/editScenarioProperties.jsp @@ -52,7 +52,7 @@ + --> * @@ -64,7 +64,16 @@ - + + + + + + +
+ +
+
diff --git a/Workspace/Siman/src/org/splat/simer/ApplicationSettings.java b/Workspace/Siman/src/org/splat/simer/ApplicationSettings.java index 8b0e905..001e781 100644 --- a/Workspace/Siman/src/org/splat/simer/ApplicationSettings.java +++ b/Workspace/Siman/src/org/splat/simer/ApplicationSettings.java @@ -156,6 +156,10 @@ public class ApplicationSettings { * Demote icon file name. */ private static final String IMG_DEMOTE = "image.demote.png"; + /** + * Accept icon file name. + */ + private static final String IMG_ACCEPT = "image.accept.png"; /** * Attach menu item name. @@ -197,6 +201,10 @@ public class ApplicationSettings { * Rename menu item name. */ private static final String MNU_RENAME = "rename"; + /** + * Set up-to-date menu item name. + */ + private static final String MNU_ACTUALIZE = "accept"; /** * Attach menu item name. @@ -258,6 +266,10 @@ public class ApplicationSettings { * Remove as reference menu item label key. */ private static final String MNU_NAME_REMOVE_AS_REFERENCE = "menu.removeasreference"; + /** + * Set up-to-date menu item label key. + */ + private static final String MNU_NAME_ACTUALIZE = "menu.actualize"; // /** // * Not yet implemented action name. // */ @@ -282,6 +294,10 @@ public class ApplicationSettings { * Promote the study action name. */ private static final String ACT_PROMOTE_STUDY = "edit-study?action=promote"; + /** + * Set up-to-date action name. + */ + private static final String ACT_ACTUALIZE = "setDocument?action=accept"; /** * Siman application server name. @@ -826,10 +842,9 @@ public class ApplicationSettings { */ private EditableDocumentPopup() { super(); - /* - * addItem("accept", new PopupItem("menu.accept").icon( "image.accept.png").action("setDocument?action=accept") - * .confirmation("message.accept.document")); - */ + addItem(MNU_ACTUALIZE, new PopupItem(MNU_NAME_ACTUALIZE) + .icon(IMG_ACCEPT).action(ACT_ACTUALIZE) + .confirmation("message.actualize.document")); addItem(MNU_PROMOTE, new PopupItem(MNU_NAME_PROMOTE).icon( IMG_PROMOTE).action("setDocument?action=promote") .confirmation("message.promote.document")); @@ -863,6 +878,9 @@ public class ApplicationSettings { */ private ReviewableDocumentPopup() { super(); + addItem(MNU_ACTUALIZE, new PopupItem(MNU_NAME_ACTUALIZE) + .icon(IMG_ACCEPT).action(ACT_ACTUALIZE) + .confirmation("message.actualize.document")); addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon( IMG_DEMOTE).action("setDocument?action=demote") .confirmation("message.demote.document")); @@ -891,6 +909,9 @@ public class ApplicationSettings { */ private NotResultDocumentPopup() { super(); + addItem(MNU_ACTUALIZE, new PopupItem(MNU_NAME_ACTUALIZE) + .icon(IMG_ACCEPT).action(ACT_ACTUALIZE) + .confirmation("message.actualize.document")); addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon( IMG_DEMOTE).action("setDocument?action=demote") .confirmation("message.demote.document")); @@ -919,6 +940,10 @@ public class ApplicationSettings { */ private ApprovableDocumentPopup() { super(); + addItem(MNU_ACTUALIZE, new PopupItem(MNU_NAME_ACTUALIZE) + .icon(IMG_ACCEPT).action(ACT_ACTUALIZE) + .confirmation("message.actualize.document")); + /*addItem("undo", new PopupItem(MNU_NAME_DEMOTE).icon( "image.invalidate.png").action( "setDocument?action=invalidate").confirmation( @@ -941,6 +966,9 @@ public class ApplicationSettings { */ private ApprovedPopup() { super(); + addItem(MNU_ACTUALIZE, new PopupItem(MNU_NAME_ACTUALIZE) + .icon(IMG_ACCEPT).action(ACT_ACTUALIZE) + .confirmation("message.actualize.document")); addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH) .action(ACT_ATTACH)); addSeparator(); diff --git a/Workspace/Siman/src/org/splat/simer/DocumentFacade.java b/Workspace/Siman/src/org/splat/simer/DocumentFacade.java index 9b19f6f..accc56b 100644 --- a/Workspace/Siman/src/org/splat/simer/DocumentFacade.java +++ b/Workspace/Siman/src/org/splat/simer/DocumentFacade.java @@ -225,19 +225,26 @@ public class DocumentFacade implements HistoryFacade { _display = State.deepopen; } else { // Opening the document if (_uses == null) { - 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, + List relist = _me.value().getRelations(UsesRelation.class); + + _uses = new ArrayList(relist.size()); + for (Relation relation : relist) { + Document used = ((UsesRelation)relation).getTo(); + + DocumentFacade facade = null; + + Publication publication = _me.getOwner().getPublication(used); + if(publication == null) { + publication = _me.getOwnerStudy().getPublication(used); + } + if(publication != null) { + facade = _owner._docpres.get(publication.getIndex()); + } + + if (facade == null) { + facade = new DocumentFacade(_owner, used, getProjectSettings(), getPublicationService(), getApplicationSettings()); - _owner._docpres.put(pub.getIndex(), facade); } _uses.add(facade); } diff --git a/Workspace/Siman/src/org/splat/simer/EditDocumentAction.java b/Workspace/Siman/src/org/splat/simer/EditDocumentAction.java index ab8b2fb..a904803 100644 --- a/Workspace/Siman/src/org/splat/simer/EditDocumentAction.java +++ b/Workspace/Siman/src/org/splat/simer/EditDocumentAction.java @@ -95,7 +95,7 @@ public class EditDocumentAction extends DisplayStudyStepAction { setAction(null); } else if (todo == Execute.accept) { getPublicationService().actualize(doc); - _openStudy.update(doc); + doOpen(); //so pop-up menus of documents depending on this one will be updated } else if (todo == Execute.promote) { getPublicationService().promote(doc, Calendar.getInstance().getTime()); diff --git a/Workspace/Siman/src/org/splat/simer/EditSimulationContextAction.java b/Workspace/Siman/src/org/splat/simer/EditSimulationContextAction.java index f1a0740..b38efc2 100644 --- a/Workspace/Siman/src/org/splat/simer/EditSimulationContextAction.java +++ b/Workspace/Siman/src/org/splat/simer/EditSimulationContextAction.java @@ -1,6 +1,8 @@ package org.splat.simer; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Iterator; import java.util.List; import org.splat.dal.bo.som.ProjectElement; @@ -132,6 +134,7 @@ public class EditSimulationContextAction extends DisplayStudyStepAction { if (_newtype.length() == 0 || _value.length() == 0) { res = INPUT; + setAction("newContext"); } else { Step step = _openStudy.getSelectedStep(); diff --git a/Workspace/Siman/src/org/splat/simer/OpenStudy.java b/Workspace/Siman/src/org/splat/simer/OpenStudy.java index 46d1085..cad212a 100644 --- a/Workspace/Siman/src/org/splat/simer/OpenStudy.java +++ b/Workspace/Siman/src/org/splat/simer/OpenStudy.java @@ -646,7 +646,12 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices { protected void update(final Publication doc) { DocumentFacade facade = _docpres.get(doc.getIndex()); if (facade != null) { - facade.refresh(); + _contents.remove(facade); + facade = new DocumentFacade(this, doc, + getProjectSettings(), getPublicationService(), + getApplicationSettings()); + _docpres.put(doc.getIndex(), facade); + _contents.add(facade); } } diff --git a/Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java b/Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java index b4ec29a..f533f66 100644 --- a/Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java +++ b/Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java @@ -5,6 +5,7 @@ import java.io.FileNotFoundException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; +import java.util.Iterator; import java.util.List; import java.util.ResourceBundle; @@ -81,14 +82,25 @@ 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(getPublicationService().getLastVersion(used, tag.getOwner()))) { - _defuses.add(used); + Document lastVersion = getPublicationService().getLastVersion(used, tag.getOwner()); + if (lastVersion != null && !_defuses.contains(lastVersion)) { + _defuses.add(lastVersion); } } // Avoid recursive using of the document if (_defuses.contains(doc)) { _defuses.remove(doc); } + + // 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(); + } + } + // Setup dependencies _usedby.addAll(tag.getRelations(UsedByRelation.class)); -- 2.39.2