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 int roleIndex = _user.getRole().getName().indexOf("knowledgineer");
120 return (_operand.getProgressState() == ProgressState.APPROVED && !_operand
121 .isPublic() && (roleIndex > -1));
125 * 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
128 * @return true if the user has right to edit the description.
130 public boolean canProtect() {
131 int roleIndex = _user.getRole().getName().indexOf("knowledgineer");
132 return (_operand.getProgressState() == ProgressState.APPROVED && _operand
133 .isPublic() && (roleIndex > -1));
137 * Check if the user can remove old versions.
139 * @return true if the user can remove old versions
141 public boolean canPurge() {
142 return (_isauthor && _operand.isVersioned());
146 * Check if the user can remove the study.
148 * @return true if the user can remove the study
150 public boolean canRemove() {
151 return (_operand.getProgressState() == ProgressState.inWORK || _operand
152 .getProgressState() == ProgressState.inDRAFT)
157 * Check if the user can remove the selected scenario.
159 * @return true if the user can remove the scenario
161 public boolean canRemoveScenario() {
162 return (_operand.getProgressState() == ProgressState.inWORK
163 || _operand.getProgressState() == ProgressState.inDRAFT)
164 && _isauthor && _operand.getScenariiList().size() > 1;
168 * Check if the user can version the study.
170 * @return true if the user can version the study
172 public boolean canVersion() {
173 return (_operand.getProgressState() == ProgressState.inWORK || _operand
174 .getProgressState() == ProgressState.inDRAFT)
175 && getStudyService().isStaffedBy(_operand, _user);
179 * Can the given study be marked as reference or not.
181 * @return true/false.
183 public boolean canMarkStudyAsReference() {
184 int roleIndex = _user.getRole().getName().indexOf("knowledgineer");
185 return (_operand.getProgressState() == ProgressState.APPROVED && (roleIndex > -1));
189 * Can the given study be unmarked as reference or not.
191 * @return true/false.
193 public boolean canRemoveStudyAsReference() {
194 int roleIndex = _user.getRole().getName().indexOf("knowledgineer");
195 return (_operand.getProgressState() == ProgressState.TEMPLATE && (roleIndex > -1));
198 // ==========================================================================
199 // Operations from document validation cycle
200 // ==========================================================================
203 * Checks if the user has right to approve the selected document. Only the approver of the type of selected document has such right,
204 * providing that the document is candidate for approval and all document dependencies have already been approved.
206 * @return true if the user has right to approve the document.
207 * @see Publication#approve()
208 * @see ValidationCycle
210 public boolean canApprove() {
211 User approver = _cycle.getActor(ValidationStep.APPROVAL); // May be null if not approvable
212 return (_user.equals(approver) || _isauthor)
213 && getStudyService().canBeApproved(_operand);
217 * 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
218 * all documents using it have previously been demoted. In-Draft documents can be demoted by default by both, the author of the document
219 * and the responsible of study, while documents in approval process can be demoted by their approver only.
221 * @return true if the user has right to demote the document.
222 * @see #canInvalidate()
224 * @see Publication#demote()
225 * @see ValidationCycle
227 public boolean canDemote() {
228 User manager = _operand.getOwnerStudy().getAuthor();
229 User publisher = _cycle.getActor(ValidationStep.PROMOTION); // Null if the default users are involved
230 User reviewer = _cycle.getActor(ValidationStep.REVIEW); // May be null if not reviewable
231 User approver = _cycle.getActor(ValidationStep.APPROVAL); // May be null if not approvable
232 ProgressState mystate = _operand.getProgressState();
234 boolean res = (mystate == ProgressState.inDRAFT
235 && (_user.equals(publisher) || _user.equals(reviewer)
236 || _user.equals(manager) || (reviewer == null)
237 && _user.equals(approver)) || mystate == ProgressState.inCHECK
238 && (_user.equals(approver) || _user.equals(reviewer) || (reviewer == null)
239 && (_user.equals(publisher) || _user.equals(manager))));
245 * 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
246 * dependencies have previously been promoted. By default, both the author of the document and the responsible of study has right to
247 * promote such document. Otherwise, only the user involved in the Promotion step of validation cycle of the selected document has such
250 * @return true if the user has right to promote the document.
252 * @see Publication#promote()
253 * @see ValidationCycle
255 public boolean canPromote() {
256 User manager = _operand.getOwnerStudy().getAuthor();
257 User publisher = _cycle.getActor(ValidationStep.PROMOTION); // Null if the default users are involved
259 if (_operand.getProgressState() != ProgressState.inWORK) {
260 if (_operand.getProgressState() == ProgressState.inDRAFT) {
265 if (publisher == null) {
266 if (!_isauthor && !_user.equals(manager)) {
270 if (!_user.equals(publisher)) {
274 return getStudyService().canBePromoted(_operand);
278 * Checks if the user has right to validate the selected document. Only the reviewer of the type of selected document has such right,
279 * providing that the document is being reviewed and all document dependencies have already been validated.
281 * @return true if the user has right to validate the document
282 * @see #canUnvalidate()
283 * @see Publication#review()
284 * @see ValidationCycle
286 public boolean canReview() {
287 User reviewer = _cycle.getActor(ValidationStep.REVIEW); // May be null if not reviewable
290 if (((reviewer == null) && ((_operand.getProgressState() == ProgressState.inWORK) || (_operand
291 .getProgressState() == ProgressState.inDRAFT)))
292 || (_user.equals(reviewer) && (_operand.getProgressState() == ProgressState.inDRAFT))) {
293 res = getStudyService().canBeReviewed(_operand);
300 * Checks if the user has right to rename a scenario of the study.
302 * @return true if user in an author, contributor or a validation cycle member of the study.
304 public boolean canRenameScenario() {
305 return _isauthor || getStudyService().hasActor(_operand, _user);
308 // ==============================================================================================================================
310 // ==============================================================================================================================
313 * Get the selected study.
315 * @return the selected study
317 public Study getOperand() {
322 * Get the study service.
324 * @return the study service
326 private StudyService getStudyService() {
327 return ServiceLocatorImpl.getInstance().getStudyService();