]> SALOME platform Git repositories - tools/siman.git/commitdiff
Salome HOME
Publish the study functionality is improved, protect the study functionality is imple...
authormka <mka@opencascade.com>
Thu, 17 Jan 2013 13:24:38 +0000 (13:24 +0000)
committermka <mka@opencascade.com>
Thu, 17 Jan 2013 13:24:38 +0000 (13:24 +0000)
Workspace/Siman-Common/src/org/splat/service/StudyService.java
Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java
Workspace/Siman-Common/src/org/splat/som/StudyRights.java
Workspace/Siman/src/labels.properties
Workspace/Siman/src/labels_en.properties
Workspace/Siman/src/org/splat/simer/ApplicationSettings.java
Workspace/Siman/src/org/splat/simer/EditStudyAction.java
Workspace/Siman/src/org/splat/simer/OpenStudy.java

index 051154e6eee0628618a34c0cc4a901becb623fd3..13dc7dfde866f89b77e126e4f746156b8904602e 100644 (file)
@@ -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
index 9223852bf8aa4802856333cf39dcab50550001d1..b5ad4006c19f91726685ab1312f76d6a6dbafdb9 100644 (file)
@@ -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;
index 617330f8e897d2950c8aa47fdf05c0a0df143fca..d90863d02263a91b0bdd81e1726cea33a3f45306 100644 (file)
@@ -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 () {
 //  --------------------------
index 778d10f62384b82a80571925bb9e4cb6797cf014..4a6a90ea9177cd919fe62561724095e2f224fef2 100644 (file)
@@ -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&#146;é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&#146;état de cette connaissance ?
 message.review.document   = Voulez-vous valider ce document ?
index ebb4c74f2c92b28cbdb693def4839f5da8b6ff11..95d7378a8efd9c8c8ec15d97fcdee5993d766d4f 100644 (file)
@@ -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 ?
index 8c8a6728d651f9077bb91f632779da47199e2f1a..e9e6fdb583be91a8b4dbb0ff5ba093f071153fc3 100644 (file)
@@ -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<String, PopupMenu>();
-               _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());
index 230f042d66d6ed588cb9d77c255bb3af5b91e816..afff22ef816af044e684e2ff66c55913cc5dd4be 100644 (file)
@@ -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);
                }
index c70d3b1a37827031fded9b8af6751c899e8ff866..86aaf534495bbe544ec3204ed31d06ddc8c4fd9a 100644 (file)
@@ -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);