4 * Class defining the default rights related to operations on studies.
5 * On the contrary of documents, a study cannot directly be reviewed or approved. It is reviewed or approved through
8 * @author Daniel Brunier-Coulin
9 * @copyright OPEN CASCADE 2012
12 import org.splat.dal.bo.kernel.User;
13 import org.splat.dal.bo.som.ProgressState;
14 import org.splat.dal.bo.som.Publication;
15 import org.splat.dal.bo.som.Study;
16 import org.splat.dal.bo.som.ValidationCycle;
17 import org.splat.dal.bo.som.ValidationStep;
18 import org.splat.service.ServiceLocatorImpl;
19 import org.splat.service.StudyService;
22 * The class representing user rights for a selected study.
24 public class StudyRights {
29 private final transient User _user;
33 private final transient Study _operand;
35 * True if the current user is the author of the selected study.
37 private transient boolean _isauthor = false; // For optimizing
39 * The study validation cycle according to the validation cycle of a study result document.
41 private transient final ValidationCycle _cycle;
51 public StudyRights(final User user, final Study study) {
53 this._operand = study;
54 this._cycle = getStudyService().getValidationCycleOf(_operand,
55 getStudyService().getStudyResultType(_operand));
57 if (_operand != null && _operand.getAuthor() != null) {
58 this._isauthor = _operand.getAuthor().equals(user); // user may be null
63 * The constructor for the case when the user is the author of the study.
68 public StudyRights(final Study study) {
69 this._user = study.getAuthor();
70 this._operand = study;
71 this._isauthor = true; // In order to ignore the author in this context
72 this._cycle = getStudyService().getValidationCycleOf(_operand,
73 getStudyService().getStudyResultType(_operand));
76 // ==============================================================================================================================
77 // Public member functions
78 // ==============================================================================================================================
81 * Check if the user can add a new scenario to the study.
83 * @return true if the user can add a new scenario to the study
85 public boolean canAddScenario() {
86 return (_operand.getProgressState() == ProgressState.inWORK || _operand
87 .getProgressState() == ProgressState.inDRAFT)
88 && getStudyService().isStaffedBy(_operand, _user);
92 * Checks if the user has right to edit the description of the study. <BR>
93 * All actors of the study have such right, including the author, contributors,<BR>
94 * reviewers and approvers.
96 * @return true if the user has right to edit the description.
98 public boolean canEditDescription() {
99 return (_operand.getAuthor().equals(_user) || getStudyService()
100 .hasActor(_operand, _user));
104 * Check if the user can configure the study.
106 * @return true if the user can configure the study.
108 public boolean canEditProperties() {
113 * 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
116 * @return true if the user has right to edit the description.
118 public boolean canPublish() {
119 return (_operand.getProgressState() == ProgressState.APPROVED && !_operand
120 .isPublic()/* && "knowledgineer".equals(_user.getRole().getName()) */);
124 * 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
127 * @return true if the user has right to edit the description.
129 public boolean canProtect() {
130 return (_operand.getProgressState() == ProgressState.APPROVED && _operand
131 .isPublic()/* && "knowledgineer".equals(_user.getRole().getName()) */);
135 * Check if the user can remove old versions.
137 * @return true if the user can remove old versions
139 public boolean canPurge() {
140 return (_isauthor && _operand.isVersioned());
144 * Check if the user can remove the study.
146 * @return true if the user can remove the study
148 public boolean canRemove() {
149 return (_operand.getProgressState() == ProgressState.inWORK || _operand
150 .getProgressState() == ProgressState.inDRAFT)
155 * Check if the user can version the study.
157 * @return true if the user can version the study
159 public boolean canVersion() {
160 return (_operand.getProgressState() == ProgressState.inWORK || _operand
161 .getProgressState() == ProgressState.inDRAFT)
162 && getStudyService().isStaffedBy(_operand, _user);
166 * Can the given study be marked as reference or not.
168 * @return true/false.
170 public boolean canMarkStudyAsReference() {
171 return (_operand.getProgressState() == ProgressState.APPROVED /* && "knowledgineer".equals(_user.getRole().getName()) */);
175 * Can the given study be unmarked as reference or not.
177 * @return true/false.
179 public boolean canRemoveStudyAsReference() {
180 return (_operand.getProgressState() == ProgressState.TEMPLATE /* && "knowledgineer".equals(_user.getRole().getName()) */);
183 // ==========================================================================
184 // Operations from document validation cycle
185 // ==========================================================================
188 * Checks if the user has right to approve the selected document. Only the approver of the type of selected document has such right,
189 * providing that the document is candidate for approval and all document dependencies have already been approved.
191 * @return true if the user has right to approve the document.
192 * @see Publication#approve()
193 * @see ValidationCycle
195 public boolean canApprove() {
196 User approver = _cycle.getActor(ValidationStep.APPROVAL); // May be null if not approvable
197 return (_user.equals(approver))
198 && getStudyService().canBeApproved(_operand);
202 * Checks if the user has right to demote the selected document. A document can be demoted providing that it is In-Draft or In-Check and
203 * all documents using it have previously been demoted. In-Draft documents can be demoted by default by both, the author of the document
204 * and the responsible of study, while documents in approval process can be demoted by their approver only.
206 * @return true if the user has right to demote the document.
207 * @see #canInvalidate()
209 * @see Publication#demote()
210 * @see ValidationCycle
212 public boolean canDemote() {
213 User manager = _operand.getOwnerStudy().getAuthor();
214 User publisher = _cycle.getActor(ValidationStep.PROMOTION); // Null if the default users are involved
215 User reviewer = _cycle.getActor(ValidationStep.REVIEW); // May be null if not reviewable
216 User approver = _cycle.getActor(ValidationStep.APPROVAL); // May be null if not approvable
217 ProgressState mystate = _operand.getProgressState();
219 boolean res = (mystate == ProgressState.inDRAFT
220 && (_user.equals(publisher) || _user.equals(reviewer)
221 || _user.equals(manager) || (reviewer == null)
222 && _user.equals(approver)) || mystate == ProgressState.inCHECK
223 && (_user.equals(approver) || _user.equals(reviewer) || (reviewer == null)
224 && (_user.equals(publisher) || _user.equals(manager))));
230 * Checks if the user has right to promote the selected document. A document can be promoted providing that it is In-Work and all its
231 * dependencies have previously been promoted. By default, both the author of the document and the responsible of study has right to
232 * promote such document. Otherwise, only the user involved in the Promotion step of validation cycle of the selected document has such
235 * @return true if the user has right to promote the document.
237 * @see Publication#promote()
238 * @see ValidationCycle
240 public boolean canPromote() {
241 User manager = _operand.getOwnerStudy().getAuthor();
242 User publisher = _cycle.getActor(ValidationStep.PROMOTION); // Null if the default users are involved
244 if (_operand.getProgressState() != ProgressState.inWORK) {
245 if (_operand.getProgressState() == ProgressState.inDRAFT) {
250 if (publisher == null) {
251 if (!_isauthor && !_user.equals(manager)) {
255 if (!_user.equals(publisher)) {
259 return getStudyService().canBePromoted(_operand);
263 * Checks if the user has right to validate the selected document. Only the reviewer of the type of selected document has such right,
264 * providing that the document is being reviewed and all document dependencies have already been validated.
266 * @return true if the user has right to validate the document
267 * @see #canUnvalidate()
268 * @see Publication#review()
269 * @see ValidationCycle
271 public boolean canReview() {
272 User reviewer = _cycle.getActor(ValidationStep.REVIEW); // May be null if not reviewable
275 if (((reviewer == null) && ((_operand.getProgressState() == ProgressState.inWORK) || (_operand
276 .getProgressState() == ProgressState.inDRAFT)))
277 || (_user.equals(reviewer) && (_operand.getProgressState() == ProgressState.inDRAFT))) {
278 res = getStudyService().canBeReviewed(_operand);
284 // ==============================================================================================================================
286 // ==============================================================================================================================
289 * Get the selected study.
291 * @return the selected study
293 public Study getOperand() {
298 * Get the study service.
300 * @return the study service
302 private StudyService getStudyService() {
303 return ServiceLocatorImpl.getInstance().getStudyService();