]> SALOME platform Git repositories - tools/siman.git/commitdiff
Salome HOME
Promote/Review/Validate functionality for author of the study is improved.
authormka <mka@opencascade.com>
Wed, 10 Jul 2013 12:26:52 +0000 (12:26 +0000)
committermka <mka@opencascade.com>
Wed, 10 Jul 2013 12:26:52 +0000 (12:26 +0000)
Workspace/Siman-Common/src/conf/log-messages.properties
Workspace/Siman-Common/src/conf/log-messages_en.properties
Workspace/Siman-Common/src/org/splat/common/properties/MessageKeyEnum.java
Workspace/Siman-Common/src/org/splat/exception/UserRightsException.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/service/PublicationService.java
Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java
Workspace/Siman-Common/src/org/splat/som/DocumentRights.java
Workspace/Siman/src/org/splat/simer/EditDocumentAction.java

index 7fec85490bf5431e421483f98dec31dd5e960f93..4eb8121bb77db67e0711843b99a01c2a6a1b7381 100644 (file)
@@ -23,4 +23,5 @@ DCT-000003=Can not save a document in {0} state. Check the validation cycle.
 DCT-000004=The source file can not be replaced. The document must be external or in In-Work state.
 DCT-000005=Document checked in by {0}
 PRM-000001=Parameter {0} is invalid with value: {1}
-IDT-000001=Incompatible data: X-units or Y-units are not the same for all comparable studies.
\ No newline at end of file
+IDT-000001=Incompatible data: X-units or Y-units are not the same for all comparable studies.
+USR-000002=User {0} has not rights to perform the required operation: {1}.
\ No newline at end of file
index 7fec85490bf5431e421483f98dec31dd5e960f93..4eb8121bb77db67e0711843b99a01c2a6a1b7381 100644 (file)
@@ -23,4 +23,5 @@ DCT-000003=Can not save a document in {0} state. Check the validation cycle.
 DCT-000004=The source file can not be replaced. The document must be external or in In-Work state.
 DCT-000005=Document checked in by {0}
 PRM-000001=Parameter {0} is invalid with value: {1}
-IDT-000001=Incompatible data: X-units or Y-units are not the same for all comparable studies.
\ No newline at end of file
+IDT-000001=Incompatible data: X-units or Y-units are not the same for all comparable studies.
+USR-000002=User {0} has not rights to perform the required operation: {1}.
\ No newline at end of file
index 39483be5a3cfc6e94e9dbc9f31313598e7027024..fcabd21622dadf268026df21c81ca3cbd7aff962 100644 (file)
@@ -116,7 +116,12 @@ public enum MessageKeyEnum {
        /**
         * Incompatible data: X-units or Y-units are not the same for all comparable studies.
         */
-       IDT_000001("IDT-000001");
+       IDT_000001("IDT-000001"),
+       /**
+        * User {0} has not rights to perform the required operation: {1}.
+        */
+       USR_000002("USR-000002");
+       
        /**
        * Value.
        */
diff --git a/Workspace/Siman-Common/src/org/splat/exception/UserRightsException.java b/Workspace/Siman-Common/src/org/splat/exception/UserRightsException.java
new file mode 100644 (file)
index 0000000..8a69ef5
--- /dev/null
@@ -0,0 +1,26 @@
+package org.splat.exception; 
+
+import org.splat.common.properties.MessageKeyEnum;
+
+/**
+ * Exception thrown when the user passed to a method hasn't got rights for required operation.
+ *
+ */
+public class UserRightsException extends BusinessException {
+
+       /**
+        * Version id for serialization.
+        */
+       private static final long serialVersionUID = -4596111071538834057L;
+       
+       /**
+        * Constructor.
+        * @param user
+        *              the user 
+        * @param operation
+        *              the name of required operation
+        */
+       public UserRightsException(final String userName, final String operation){
+               super(MessageKeyEnum.USR_000002.toString(), userName, operation);
+       }
+}
index 62bca2ee9e52fab4404cdb2a0837d900e16f72a8..06fabb779624f99a9600be6a7cfea28b102d44f1 100644 (file)
@@ -27,6 +27,7 @@ import org.splat.dal.bo.som.Study;
 import org.splat.dal.bo.som.Timestamp;
 import org.splat.exception.IncompatibleDataException;
 import org.splat.exception.InvalidParameterException;
+import org.splat.exception.UserRightsException;
 import org.splat.kernel.InvalidPropertyException;
 import org.splat.kernel.MismatchException;
 import org.splat.kernel.MissedPropertyException;
@@ -126,13 +127,20 @@ public interface PublicationService {
         *            the document publication
         * @param adate
         *            the date of approval
+        * @param user
+        *                        the user approving the publication
+        * @throws UserRightsException
+        *                        if the user hasn't got rights to perform the operation
+        * @throws InvalidParameterException
+        *                        if the user is null
         * @return true if the approval succeeded
         * @see #getProgressState()
         * @see DocumentRights#canApprove()
         * @see DocumentType#isStudyResult()
         * @see Study#getApproverOf(Publication)
         */
-       Timestamp approve(Publication aPublication, Date adate);
+       Timestamp approve(Publication aPublication, Date adate, User user)
+       throws UserRightsException, InvalidParameterException;
 
        /**
         * Demotes the document referenced by this publication to In-Work state, and removes the Promoter of the document, if exist.<br/> The
@@ -175,13 +183,17 @@ public interface PublicationService {
         *            the document publication
         * @param pdate
         *            the date of promotion
+        * @param user
+        *                        the user promoting the publication (if null then publication is promoted by the promoter if exists, otherwise by author)
         * @return true if the promotion succeeded
+        * @throws UserRightsException
+        *                        if the user hasn't got rights to perform the operation
         * @see #getProgressState()
         * @see #demote()
         * @see DocumentRights#canPromote()
         * @see DocumentType#isStudyResult()
         */
-       Timestamp promote(Publication aPublication, Date pdate);
+       Timestamp promote(Publication aPublication, Date pdate, User user) throws UserRightsException;
 
        /**
         * Promotes the document referenced by this publication from In-Draft to In-Check state, if not out-dated, and attaches the
@@ -193,14 +205,21 @@ public interface PublicationService {
         *            the document publication
         * @param rdate
         *            the date of review
+        * @param user
+        *                        the user reviewing the publication
         * @return true if the review succeeded
+        * @throws UserRightsException
+        *                        if the user hasn't got rights to perform the operation
+        * @throws InvalidParameterException
+        *                        if the user is null
         * @see #getProgressState()
         * @see #invalidate()
         * @see DocumentRights#canReview()
         * @see DocumentType#isStudyResult()
         * @see Study#getReviewerOf(Publication)
         */
-       Timestamp review(Publication aPublication, Date rdate);
+       Timestamp review(Publication aPublication, Date rdate, User user)
+       throws UserRightsException, InvalidParameterException;
 
        /**
         * Publishes the document referenced by this publication into the owner Project Element under the given state, the revision number of
index e0bc6e6c55ed6c94c0aba667fc7c9c51d56b11bf..dfb90ddf211102aad6af5ecc716e614245f262f9 100644 (file)
@@ -44,8 +44,10 @@ import org.splat.dal.dao.som.ProjectElementDAO;
 import org.splat.dal.dao.som.PublicationDAO;
 import org.splat.dal.dao.som.TimestampDAO;
 import org.splat.dal.dao.som.VersionsRelationDAO;
+import org.splat.exception.BusinessException;
 import org.splat.exception.IncompatibleDataException;
 import org.splat.exception.InvalidParameterException;
+import org.splat.exception.UserRightsException;
 import org.splat.kernel.InvalidPropertyException;
 import org.splat.kernel.MismatchException;
 import org.splat.kernel.MissedPropertyException;
@@ -333,17 +335,20 @@ public class PublicationServiceImpl implements PublicationService {
         * @see org.splat.service.PublicationService#approve(org.splat.dal.bo.som.Publication, java.util.Date)
         */
        @Transactional
-       public Timestamp approve(final Publication aPublication, final Date adate) {
+       public Timestamp approve(final Publication aPublication, final Date adate, final User user)
+                               throws UserRightsException, InvalidParameterException {
                Timestamp res = null;
+               if(user == null){
+                       throw new InvalidParameterException("user", user.toString());
+               }
                if (!(aPublication.isOutdated() || (aPublication.value()
                                .getProgressState() != ProgressState.inCHECK))) {
-                       DocumentType type = aPublication.value().getType();
-                       Study owner = aPublication.getOwnerStudy();
-                       ValidationCycle cycle = getStudyService().getValidationCycleOf(
-                                       owner, type);
-                       User approver = cycle.getActor(ValidationStep.APPROVAL);
+                       DocumentRights rights = new DocumentRights(user, aPublication);
+                       if(!rights.canApprove()) {
+                               throw new UserRightsException(user.toString(), "approve");
+                       }
                        Timestamp stamp = new Timestamp(ValidationStep.APPROVAL,
-                                       aPublication.value(), approver, adate);
+                                       aPublication.value(), user, adate);
                        getTimestampDAO().create(stamp);
 
                        if (getDocumentService().promote(aPublication.value(), stamp)) {
@@ -424,7 +429,8 @@ public class PublicationServiceImpl implements PublicationService {
         * @see org.splat.service.PublicationService#promote(org.splat.dal.bo.som.Publication, java.util.Date)
         */
        @Transactional
-       public Timestamp promote(final Publication aPublication, final Date pdate) {
+       public Timestamp promote(final Publication aPublication, final Date pdate, User user)
+                               throws UserRightsException {
                Timestamp res = null;
                if ((!aPublication.isOutdated())
                                && (aPublication.value().getProgressState() == ProgressState.inWORK)) {
@@ -432,15 +438,22 @@ public class PublicationServiceImpl implements PublicationService {
                        Study owner = aPublication.getOwnerStudy();
                        ValidationCycle cycle = getStudyService().getValidationCycleOf(
                                        owner, type);
-                       User promoter = cycle.getActor(ValidationStep.PROMOTION);
-                       if (promoter == null) {
-                               promoter = getInvolvedStep(aPublication).getActor();
-                       }
-                       if (promoter == null) {
-                               promoter = owner.getAuthor();
+                       if(user == null) {
+                               user = cycle.getActor(ValidationStep.PROMOTION);
+                               if (user == null) {
+                                       getInvolvedStep(aPublication).getActor();
+                               }
+                               if (user == null) {
+                                       user = owner.getAuthor();
+                               }
+                       } else {
+                               DocumentRights rights = new DocumentRights(user, aPublication);
+                               if(!rights.canPromote()) {
+                                       throw new UserRightsException(user.toString(), "promote");
+                               }
                        }
                        Timestamp stamp = new Timestamp(ValidationStep.PROMOTION,
-                                       aPublication.value(), promoter, pdate);
+                                       aPublication.value(), user, pdate);
                        getTimestampDAO().create(stamp);
 
                        if (getDocumentService().promote(aPublication.value(), stamp)) {
@@ -463,18 +476,21 @@ public class PublicationServiceImpl implements PublicationService {
         * @see org.splat.service.PublicationService#review(org.splat.dal.bo.som.Publication, java.util.Date)
         */
        @Transactional
-       public Timestamp review(final Publication aPublication, final Date rdate) {
+       public Timestamp review(final Publication aPublication, final Date rdate, final User user)
+                               throws UserRightsException, InvalidParameterException {
                Timestamp res = null;
+               if(user == null){
+                       throw new InvalidParameterException("user", user.toString());
+               }
                if (!aPublication.isOutdated()
                                && !(aPublication.value().getProgressState() != ProgressState.inDRAFT)) {
 
-                       DocumentType type = aPublication.value().getType();
-                       Study owner = aPublication.getOwnerStudy();
-                       ValidationCycle cycle = getStudyService().getValidationCycleOf(
-                                       owner, type);
-                       User reviewer = cycle.getActor(ValidationStep.REVIEW);
+                       DocumentRights rights = new DocumentRights(user, aPublication);
+                       if(!rights.canReview()) {
+                               throw new UserRightsException(user.toString(), "review");
+                       }
                        Timestamp stamp = new Timestamp(ValidationStep.REVIEW, aPublication
-                                       .value(), reviewer, rdate);
+                                       .value(), user, rdate);
                        getTimestampDAO().create(stamp);
 
                        if (getDocumentService().promote(aPublication.value(), stamp)) {
@@ -548,9 +564,13 @@ public class PublicationServiceImpl implements PublicationService {
                        // hascode
                        getDocumentService().updateAs(aPublication.value(),
                                        ProgressState.inWORK);
-
-                       promote(aPublication, aPublication.value()
-                                       .getLastModificationDate()); // Promotes to the appropriate state in accordance to the validation cycle
+                       
+                       try {
+                               promote(aPublication, aPublication.value()
+                                               .getLastModificationDate(), null); // Promotes to the appropriate state in accordance to the validation cycle
+                       } catch(UserRightsException e) {
+                               LOG.info("a BusinessException is thrown.");
+                       }
                }
                updateOwner(aPublication);
        }
index 9e9d7242092e5d7c87b5ebeb29374b75eee4ff0a..3eb7a9e5da2cc724b045a63cb0df52cd0d7f5377 100644 (file)
@@ -113,7 +113,8 @@ public class DocumentRights {
         */
        public boolean canApprove() {
                User approver = _cycle.getActor(ValidationStep.APPROVAL); // May be null if not approvable
-               boolean res = (_user.equals(approver))
+               boolean res = (_operand.getOwnerStudy().getAuthor().equals(_user) ||
+                                       _user.equals(approver))
                                && (_operand.getProgressState() == ProgressState.inCHECK)
                                && !_operand.isOutdated();
                if (res) {
@@ -170,7 +171,8 @@ public class DocumentRights {
                User approver = _cycle.getActor(ValidationStep.APPROVAL); // May be null if not approvable
                ProgressState mystate = _operand.value().getProgressState();
 
-               boolean res = (mystate == ProgressState.inDRAFT
+               boolean res = _operand.getOwnerStudy().getAuthor().equals(_user) ||
+                               (mystate == ProgressState.inDRAFT
                                && (_user.equals(publisher) || _user.equals(reviewer)
                                                || _user.equals(manager) || (reviewer == null)
                                                && _user.equals(approver)) || mystate == ProgressState.inCHECK
@@ -241,13 +243,15 @@ public class DocumentRights {
                        }
                        return false;
                }
-               if (publisher == null) {
-                       if (!_isauthor && !_user.equals(manager)) {
-                               return false;
-                       }
-               } else {
-                       if (!_user.equals(publisher)) {
-                               return false;
+               if(!_operand.getOwnerStudy().getAuthor().equals(_user)) {
+                       if (publisher == null) {
+                               if (!_isauthor && !_user.equals(manager)) {
+                                       return false;
+                               }
+                       } else {
+                               if (!_user.equals(publisher)) {
+                                       return false;
+                               }
                        }
                }
                List<Relation> use = _operand.value().getRelations(UsesRelation.class);
@@ -360,7 +364,8 @@ public class DocumentRights {
        public boolean canReview() {
                User reviewer = _cycle.getActor(ValidationStep.REVIEW); // May be null if not reviewable
 
-               if (!_user.equals(reviewer) || _operand.isOutdated()) {
+               if (!_user.equals(reviewer) && !_operand.getOwnerStudy().getAuthor().equals(_user)
+                               || _operand.isOutdated()) {
                        return false;
                }
                if (_operand.getProgressState() != ProgressState.inDRAFT) {
@@ -398,7 +403,7 @@ public class DocumentRights {
                if (mystate != ProgressState.inCHECK) {
                        return false;
                }
-               if (!_isauthor && !_user.equals(reviewer)) {
+               if (!_isauthor && !_user.equals(reviewer) && !_operand.getOwnerStudy().getAuthor().equals(_user)) {
                        return false;
                }
 
index a9048035e93d956b609b39c380435af4877a3b55..d168d5c4678d635e38b42cb5624b93c1042a9142 100644 (file)
@@ -8,6 +8,8 @@ import org.splat.dal.bo.kernel.User;
 import org.splat.dal.bo.som.ConvertsRelation;
 import org.splat.dal.bo.som.Publication;
 import org.splat.exception.DocumentIsUsedException;
+import org.splat.exception.InvalidParameterException;
+import org.splat.exception.UserRightsException;
 import org.splat.kernel.InvalidPropertyException;
 import org.splat.service.PublicationService;
 import org.splat.service.StepService;
@@ -79,7 +81,7 @@ public class EditDocumentAction extends DisplayStudyStepAction {
         * 
         * @return SUCCESS if succeeded, INPUT if input data are invalid, ERROR if failed
         */
-       public String doSetDocument() {
+       public String doSetDocument() throws InvalidParameterException, UserRightsException {
                setMenu();
                String res = ERROR;
                try {
@@ -98,21 +100,21 @@ public class EditDocumentAction extends DisplayStudyStepAction {
                                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());
+                                               Calendar.getInstance().getTime(), getConnectedUser());
                                _openStudy.update(doc);
                        } else if (todo == Execute.demote) {
                                getPublicationService().demote(doc);
                                _openStudy.update(doc);
                        } else if (todo == Execute.review) {
                                getPublicationService().review(doc,
-                                               Calendar.getInstance().getTime());
+                                               Calendar.getInstance().getTime(), getConnectedUser());
                                _openStudy.update(doc);
                        } else if (todo == Execute.invalidate) {
                                getPublicationService().invalidate(doc);
                                _openStudy.update(doc);
                        } else if (todo == Execute.approve) {
                                getPublicationService().approve(doc,
-                                               Calendar.getInstance().getTime());
+                                               Calendar.getInstance().getTime(), getConnectedUser());
                                _openStudy.update(doc);
                                // Update the menu icon, in case of other documents in approved state
                                _openStudy.getMenu().refreshSelectedItem();