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
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
/**
* 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.
*/
--- /dev/null
+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);
+ }
+}
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;
* 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
* 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
* 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
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;
* @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)) {
* @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)) {
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)) {
* @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)) {
// 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);
}
*/
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) {
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
}
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);
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) {
if (mystate != ProgressState.inCHECK) {
return false;
}
- if (!_isauthor && !_user.equals(reviewer)) {
+ if (!_isauthor && !_user.equals(reviewer) && !_operand.getOwnerStudy().getAuthor().equals(_user)) {
return false;
}
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;
*
* @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 {
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();