From d0e88002ed4c1973854db1b02c8593531521c349 Mon Sep 17 00:00:00 2001 From: mka Date: Thu, 17 Jan 2013 13:24:38 +0000 Subject: [PATCH] Publish the study functionality is improved, protect the study functionality is implemented . --- .../src/org/splat/service/StudyService.java | 9 ++ .../org/splat/service/StudyServiceImpl.java | 22 ++- .../src/org/splat/som/StudyRights.java | 38 +++-- Workspace/Siman/src/labels.properties | 2 + Workspace/Siman/src/labels_en.properties | 2 + .../org/splat/simer/ApplicationSettings.java | 142 ++++++------------ .../src/org/splat/simer/EditStudyAction.java | 4 +- .../Siman/src/org/splat/simer/OpenStudy.java | 31 +++- 8 files changed, 132 insertions(+), 118 deletions(-) diff --git a/Workspace/Siman-Common/src/org/splat/service/StudyService.java b/Workspace/Siman-Common/src/org/splat/service/StudyService.java index 051154e..13dc7df 100644 --- a/Workspace/Siman-Common/src/org/splat/service/StudyService.java +++ b/Workspace/Siman-Common/src/org/splat/service/StudyService.java @@ -171,6 +171,15 @@ public interface StudyService { * @see #isPublic() */ boolean moveToPublic(Study aStudy); + + /** + * Moves this study from the Public to the Private area of the repository. + * + * @param aStudy + * the study to move + * @return true if the move succeeded. + */ + boolean moveToPrivate(Study aStudy); /** * Moves this study from the Public to the Reference area of the repository. For being moved to the Reference area, the study must diff --git a/Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java index 9223852..b5ad400 100644 --- a/Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java @@ -436,6 +436,7 @@ public class StudyServiceImpl implements StudyService { * @return true if the move succeeded. * @see #isPublic() */ + @Transactional public boolean moveToPublic(final Study aStudy) { boolean isOk = false; if (aStudy.getVisibility() == Visibility.PRIVATE) { @@ -446,6 +447,25 @@ public class StudyServiceImpl implements StudyService { } return isOk; } + + /** + * Moves this study from the Public to the Private area of the repository. + * + * @param aStudy + * a study to move + * @return true if the move succeeded. + */ + @Transactional + public boolean moveToPrivate(final Study aStudy) { + boolean isOk = false; + if (aStudy.getVisibility() == Visibility.PUBLIC) { + aStudy.setVisibility(Visibility.PRIVATE); + if (update(aStudy)) { + isOk = updateKnowledgeElementsIndex(aStudy); // If fails, the database roll-back is under responsibility of the caller + } + } + return isOk; + } /** * Update a study in the database. @@ -458,7 +478,7 @@ public class StudyServiceImpl implements StudyService { private boolean update(final Study aStudy) { boolean isOk = false; try { - getStudyDAO().update(aStudy); // Update of relational base + getStudyDAO().merge(aStudy); // Update of relational base setShortCuts(aStudy); // RKV: initialize transient actors set getIndex().update(aStudy); // Update of Lucene index isOk = true; diff --git a/Workspace/Siman-Common/src/org/splat/som/StudyRights.java b/Workspace/Siman-Common/src/org/splat/som/StudyRights.java index 617330f..d90863d 100644 --- a/Workspace/Siman-Common/src/org/splat/som/StudyRights.java +++ b/Workspace/Siman-Common/src/org/splat/som/StudyRights.java @@ -63,19 +63,35 @@ public class StudyRights { return _author; } -/** - * Checks if the user has right to move the study from the Private to the Public area of the repository. - * Only the author of the study have such right. - * - * @return true if the user has right to edit the description. - */ - public boolean canPublish () { -// ---------------------------- - if (!_author) { + /** + * Checks if the user has right to move the study from the Private to the Public area of the repository. Only the author of the study + * have such right. + * + * @return true if the user has right to edit the description. + */ + public boolean canPublish() { + // ---------------------------- + if (_operand.getProgressState() == ProgressState.APPROVED + && !_operand.isPublic()/* && "knowledgineer".equals(_user.getRole().getName()) */) { + return true; + } + return false; + } + + /** + * Checks if the user has right to move the study from the Public to the Private area of the repository. Only the author of the study + * have such right. + * + * @return true if the user has right to edit the description. + */ + public boolean canProtect() { + // ---------------------------- + if (_operand.getProgressState() == ProgressState.APPROVED + && _operand.isPublic()/* && "knowledgineer".equals(_user.getRole().getName()) */) { + return true; + } return false; } - return (!_operand.isPublic()); - } public boolean canPurge () { // -------------------------- diff --git a/Workspace/Siman/src/labels.properties b/Workspace/Siman/src/labels.properties index 778d10f..4a6a90e 100644 --- a/Workspace/Siman/src/labels.properties +++ b/Workspace/Siman/src/labels.properties @@ -24,6 +24,7 @@ menu.newcontype = Nouveau type de contexte menu.newdoctype = Nouveau type de document menu.accept = Accepter les modifications menu.publish = Publier +menu.protect = Protect menu.archive = Archiver menu.promote = Promouvoir menu.review = Valider @@ -267,6 +268,7 @@ message.nocontext = Aucun contexte de simulation n''est en attente d''ap message.emptydocument = Aucun document n''a été créé à cette étape. message.accept.document = Voulez-vous accepter les modifications des documents utilisés ? message.publish.study = Voulez-vous publier l’étude ? +message.protect.study = Do you really want to protect the study ? message.promote.document = Voulez-vous promouvoir ce document ? message.promote.knowledge = Voulez-vous avancer l’état de cette connaissance ? message.review.document = Voulez-vous valider ce document ? diff --git a/Workspace/Siman/src/labels_en.properties b/Workspace/Siman/src/labels_en.properties index ebb4c74..95d7378 100644 --- a/Workspace/Siman/src/labels_en.properties +++ b/Workspace/Siman/src/labels_en.properties @@ -24,6 +24,7 @@ menu.newcontype = New context type menu.newdoctype = New document type menu.accept = Set up-to-date menu.publish = Publish +menu.protect = Protect menu.archive = Archive menu.promote = Promote menu.review = Validate @@ -268,6 +269,7 @@ message.nocontext = No simulation context is pending for approval. message.emptydocument = No document has been created at this step. message.accept.document = Do you really want to accept the modifications of dependent documents ? message.publish.study = Do you really want to publish the study ? +message.protect.study = Do you really want to protect the study ? message.promote.document = Do you really want to promote this document ? message.promote.knowledge = Do you really want to promote this knowledge ? message.review.document = Do you really want to validate this document ? diff --git a/Workspace/Siman/src/org/splat/simer/ApplicationSettings.java b/Workspace/Siman/src/org/splat/simer/ApplicationSettings.java index 8c8a672..e9e6fdb 100644 --- a/Workspace/Siman/src/org/splat/simer/ApplicationSettings.java +++ b/Workspace/Siman/src/org/splat/simer/ApplicationSettings.java @@ -23,6 +23,7 @@ import org.splat.dal.bo.som.DocumentType; import org.splat.dal.bo.som.KnowledgeElement; import org.splat.dal.bo.som.ProgressState; import org.splat.dal.bo.som.SimulationContext; +import org.splat.dal.bo.som.Visibility; import org.splat.manox.XDOM; import org.splat.service.DocumentTypeService; import org.splat.service.technical.ProjectSettingsService; @@ -205,6 +206,10 @@ public class ApplicationSettings { * Publish menu item name. */ private static final String MNU_NAME_PUBLISH = "menu.publish"; + /** + * Protect menu item name. + */ + private static final String MNU_NAME_PROTECT = "menu.protect"; /** * Edit menu item name. */ @@ -473,14 +478,30 @@ public class ApplicationSettings { private static class EditableMarkedStudyPopup extends PopupMenu { private transient StudyRights _user = null; - private EditableMarkedStudyPopup() { + private EditableMarkedStudyPopup(final boolean isPublic, final boolean isMarked) { super(); - addItem(MNU_MARK_AS_REFERENCE, new PopupItem(MNU_NAME_MARK_AS_REFERENCE) - .action(ACT_MARK_AS_REFERENCE).confirmation( - "message.markasreference.study")); - addItem(MNU_PUBLISH, new PopupItem(MNU_NAME_PUBLISH).icon( - "image.publish.png").action("edit-study?action=publish") - .confirmation("message.publish.study")); + + if (isMarked) { + addItem(MNU_MARK_AS_REFERENCE, new PopupItem( + MNU_NAME_REMOVE_AS_REFERENCE).action(ACT_REMOVE_AS_REFERENCE) + .confirmation("message.removeasreference.study")); + } else { + addItem(MNU_MARK_AS_REFERENCE, new PopupItem(MNU_NAME_MARK_AS_REFERENCE) + .action(ACT_MARK_AS_REFERENCE).confirmation( + "message.markasreference.study")); + } + + LOG.debug("MKA isPublic = " + isPublic); + if (isPublic) { + addItem(MNU_PUBLISH, new PopupItem(MNU_NAME_PROTECT).icon( + "image.publish.png").action("edit-study?action=protect") + .confirmation("message.protect.study")); + } else { + addItem(MNU_PUBLISH, new PopupItem(MNU_NAME_PUBLISH).icon( + "image.publish.png").action("edit-study?action=publish") + .confirmation("message.publish.study")); + } + /* addItem(MNU_PROMOTE, new PopupItem("menu.archive")); */ addSeparator(); addItem(MNU_EDIT, new PopupItem("menu.properties").icon( @@ -512,96 +533,11 @@ public class ApplicationSettings { Item item = Item.valueOf(name); switch (item) { case publish: - res = _user.canPublish(); - break; - case edit: - res = _user.canEditProperties(); - break; - case script: - res = _user.canAddScenario(); - break; - case version: - res = _user.canVersion(); - break; - case remove: - res = _user.canRemove(); - break; - case purge: - res = _user.canPurge(); - break; - case markasreference: - res = _user.canMarkStudyAsReference(); - break; - default: - res = false; - } - } - return res; - } - - @Override - public void setContext(final String name, final Object context) { - if (context instanceof StudyRights) { - _user = (StudyRights) context; // Just for optimizing - boolean history = _user.getOperand().isVersioned(); - PopupItem item = this.item(MNU_REMOVE); - if (history) { - item.rename(MNU_NAME_REMOVE); - } else { - item.rename("menu.remove.study"); - } - } - } - } - - // Resources relative to studies - private static class EditableUnmarkedStudyPopup extends PopupMenu { - private transient StudyRights _user = null; - - private EditableUnmarkedStudyPopup() { - super(); - addItem(MNU_MARK_AS_REFERENCE, new PopupItem( - MNU_NAME_REMOVE_AS_REFERENCE).action(ACT_REMOVE_AS_REFERENCE) - .confirmation("message.removeasreference.study")); - addItem(MNU_PUBLISH, - new PopupItem(MNU_NAME_PUBLISH).icon("image.publish.png") - .action("edit-study?action=publish") - .confirmation("message.publish.study")); - /* addItem(MNU_PROMOTE, new PopupItem("menu.archive")); */ - addSeparator(); - addItem(MNU_EDIT, - new PopupItem("menu.properties").icon("icon.ed.png") - .action("../select?menu=properties")); - addSeparator(); - addItem(MNU_SCRIPT, - new PopupItem(MNU_NAME_SCRIPT).action("add-scenario")); - /* - * addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon( IMG_VERSION).action(ACT_NOT_YET_IMPLEMENTED)); - */ - addSeparator(); - /* - * addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE) .confirmation("message.purge.study")); addItem("export", new - * PopupItem("menu.export") .icon("image.export.png")); // For future needs - */addItem( - MNU_REMOVE, - new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE) - .action(ACT_NOT_YET_IMPLEMENTED) - .confirmation("message.delete.study")); - } - - /** - * {@inheritDoc} - * - * @see org.splat.wapp.ContextualMenu#isEnabled(java.lang.String) - */ - @Override - public boolean isEnabled(final String name) { - boolean res = (_user != null); - if (res) { - Item item = Item.valueOf(name); - switch (item) { - case publish: - res = _user.canPublish(); + if (_user.getOperand().getVisibility() == Visibility.PRIVATE) { + res = _user.canPublish(); + } else { + res = _user.canProtect(); + } break; case edit: res = _user.canEditProperties(); @@ -619,7 +555,11 @@ public class ApplicationSettings { res = _user.canPurge(); break; case markasreference: - res = _user.canRemoveStudyAsReference(); + if (_user.getOperand().getMarkreference() == 0) { + res = _user.canMarkStudyAsReference(); + } else { + res = _user.canRemoveStudyAsReference(); + } break; default: res = false; @@ -1048,8 +988,10 @@ public class ApplicationSettings { _menus.put(menu.getName(), menu); _popups = new HashMap(); - _popups.put("steditablemark", new EditableMarkedStudyPopup()); - _popups.put("steditableunmark", new EditableUnmarkedStudyPopup()); + _popups.put("steditablemarkpublic", new EditableMarkedStudyPopup(false, false)); + _popups.put("steditableunmarkpublic", new EditableMarkedStudyPopup(false, true)); + _popups.put("steditablemarkprivate", new EditableMarkedStudyPopup(true, false)); + _popups.put("steditableunmarkprivate", new EditableMarkedStudyPopup(true, true)); _popups.put("editable", new EditableDocumentPopup()); _popups.put("notresult", new NotResultDocumentPopup()); _popups.put("reviewable", new ReviewableDocumentPopup()); diff --git a/Workspace/Siman/src/org/splat/simer/EditStudyAction.java b/Workspace/Siman/src/org/splat/simer/EditStudyAction.java index 230f042..afff22e 100644 --- a/Workspace/Siman/src/org/splat/simer/EditStudyAction.java +++ b/Workspace/Siman/src/org/splat/simer/EditStudyAction.java @@ -16,7 +16,7 @@ public class EditStudyAction extends DisplayStudyStepAction { private StudyService _studyService; private enum Execute { - publish, promote + publish, protect, promote } // ============================================================================================================================== @@ -31,6 +31,8 @@ public class EditStudyAction extends DisplayStudyStepAction { if (todo == Execute.publish) { getStudyService().moveToPublic(study); + } else if (todo == Execute.protect) { + getStudyService().moveToPrivate(study); } else if (todo == Execute.promote) { getStudyService().moveToReference(study); } diff --git a/Workspace/Siman/src/org/splat/simer/OpenStudy.java b/Workspace/Siman/src/org/splat/simer/OpenStudy.java index c70d3b1..86aaf53 100644 --- a/Workspace/Siman/src/org/splat/simer/OpenStudy.java +++ b/Workspace/Siman/src/org/splat/simer/OpenStudy.java @@ -135,12 +135,25 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices { // if (state == ProgressState.inCHECK) popup = getApplicationSettings().getPopupMenu("stapprovable"); // else if (state == ProgressState.APPROVED) popup = getApplicationSettings().getPopupMenu("stapproved"); /* else */ + if (_mystudy.getProgressState() == ProgressState.TEMPLATE) { - _popup = getApplicationSettings().getPopupMenu( - "steditableunmark"); + if (_mystudy.isPublic()) { + _popup = getApplicationSettings().getPopupMenu( + "steditableunmarkprivate"); + } else { + _popup = getApplicationSettings().getPopupMenu( + "steditableunmarkpublic"); + } } else { - _popup = getApplicationSettings().getPopupMenu( - "steditablemark"); + + if (_mystudy.isPublic()) { + _popup = getApplicationSettings().getPopupMenu( + "steditablemarkprivate"); + } else { + _popup = getApplicationSettings().getPopupMenu( + "steditablemarkpublic"); + } + } _popup.setContext("study", new StudyRights(_cuser, _mystudy)); } @@ -158,10 +171,12 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices { // Getters // ============================================================================================================================== + @Override public String getAuthorName() { return _mystudy.getAuthor().toString(); } + @Override public Long getIndex() { return _mystudy.getIndex(); } @@ -179,6 +194,7 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices { _menu = aMenu; } + @Override public ProgressState getProgressState() { return _mystudy.getProgressState(); } @@ -191,10 +207,12 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices { return getApplicationSettings().getModuleBar(getSelectedStep()); } + @Override public String getReference() { return _mystudy.getReference(); } + @Override public Publication getSelectedDocument() { return _selecdoc; } @@ -211,10 +229,12 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices { return _mystudy; } + @Override public String getTitle() { return _mystudy.getTitle(); } + @Override public String getType() { /* * RKV: return ResourceBundle.getBundle("labels", getApplicationSettings().getCurrentLocale()).getString( "label.study"); @@ -234,6 +254,7 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices { // Public services // ============================================================================================================================== + @Override public URL newTemplateBasedDocument(final String typename, final User author) { String filename = typename + ".xml"; // Only XML templates are writeable File template = new File(getRepositoryService().getTemplatePath() @@ -393,7 +414,7 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices { _cuser = user; _popup = null; if (getStudyService().isStaffedBy(_mystudy, _cuser)) { - _popup = getApplicationSettings().getPopupMenu("steditablemark"); + _popup = getApplicationSettings().getPopupMenu("steditablemarkpublic"); _popup.setContext("study", new StudyRights(_cuser, _mystudy)); } // ustep = getProjectElementService().getFirstStep(mystudy); -- 2.39.2