From 2fda19bf5edff110a9361da8c34f6a08c908e7c8 Mon Sep 17 00:00:00 2001 From: mka Date: Wed, 10 Jul 2013 12:26:52 +0000 Subject: [PATCH] Promote/Review/Validate functionality for author of the study is improved. --- .../src/conf/log-messages.properties | 3 +- .../src/conf/log-messages_en.properties | 3 +- .../common/properties/MessageKeyEnum.java | 7 +- .../splat/exception/UserRightsException.java | 26 +++++++ .../org/splat/service/PublicationService.java | 25 ++++++- .../splat/service/PublicationServiceImpl.java | 70 ++++++++++++------- .../src/org/splat/som/DocumentRights.java | 27 ++++--- .../org/splat/simer/EditDocumentAction.java | 10 +-- 8 files changed, 125 insertions(+), 46 deletions(-) create mode 100644 Workspace/Siman-Common/src/org/splat/exception/UserRightsException.java diff --git a/Workspace/Siman-Common/src/conf/log-messages.properties b/Workspace/Siman-Common/src/conf/log-messages.properties index 7fec854..4eb8121 100644 --- a/Workspace/Siman-Common/src/conf/log-messages.properties +++ b/Workspace/Siman-Common/src/conf/log-messages.properties @@ -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 diff --git a/Workspace/Siman-Common/src/conf/log-messages_en.properties b/Workspace/Siman-Common/src/conf/log-messages_en.properties index 7fec854..4eb8121 100644 --- a/Workspace/Siman-Common/src/conf/log-messages_en.properties +++ b/Workspace/Siman-Common/src/conf/log-messages_en.properties @@ -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 diff --git a/Workspace/Siman-Common/src/org/splat/common/properties/MessageKeyEnum.java b/Workspace/Siman-Common/src/org/splat/common/properties/MessageKeyEnum.java index 39483be..fcabd21 100644 --- a/Workspace/Siman-Common/src/org/splat/common/properties/MessageKeyEnum.java +++ b/Workspace/Siman-Common/src/org/splat/common/properties/MessageKeyEnum.java @@ -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 index 0000000..8a69ef5 --- /dev/null +++ b/Workspace/Siman-Common/src/org/splat/exception/UserRightsException.java @@ -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); + } +} diff --git a/Workspace/Siman-Common/src/org/splat/service/PublicationService.java b/Workspace/Siman-Common/src/org/splat/service/PublicationService.java index 62bca2e..06fabb7 100644 --- a/Workspace/Siman-Common/src/org/splat/service/PublicationService.java +++ b/Workspace/Siman-Common/src/org/splat/service/PublicationService.java @@ -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.
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 diff --git a/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java index e0bc6e6..dfb90dd 100644 --- a/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java @@ -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); } diff --git a/Workspace/Siman-Common/src/org/splat/som/DocumentRights.java b/Workspace/Siman-Common/src/org/splat/som/DocumentRights.java index 9e9d724..3eb7a9e 100644 --- a/Workspace/Siman-Common/src/org/splat/som/DocumentRights.java +++ b/Workspace/Siman-Common/src/org/splat/som/DocumentRights.java @@ -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 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; } diff --git a/Workspace/Siman/src/org/splat/simer/EditDocumentAction.java b/Workspace/Siman/src/org/splat/simer/EditDocumentAction.java index a904803..d168d5c 100644 --- a/Workspace/Siman/src/org/splat/simer/EditDocumentAction.java +++ b/Workspace/Siman/src/org/splat/simer/EditDocumentAction.java @@ -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(); -- 2.39.2