Salome HOME
Modifications done to respect PMD rules. Versioning a document is fixed. Validation...
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / som / StudyRights.java
1 package org.splat.som;
2 /**
3  * Class defining the default rights related to operations on studies.
4  * On the contrary of documents, a study cannot directly be reviewed or approved. It is reviewed or approved through
5  * its final report.
6  * 
7  * @author    Daniel Brunier-Coulin
8  * @copyright OPEN CASCADE 2012
9  */
10
11 import org.splat.dal.bo.kernel.User;
12 import org.splat.dal.bo.som.ProgressState;
13 import org.splat.dal.bo.som.Study;
14 import org.splat.service.ServiceLocatorImpl;
15
16
17 public class StudyRights {
18
19     private final transient User     _user;
20     private final transient Study    _operand;
21     private transient boolean  _author = false;                    // For optimizing 
22         public StudyRights (final User user, final Study study) {
23 //  -------------------------------------------
24       this._user    = user;
25       this._operand = study;
26
27       if (_operand != null && _operand.getAuthor() != null) {
28           this._author  = _operand.getAuthor().equals(user);  // user may be null
29       }
30     }
31     public StudyRights (final Study study) {
32 //  --------------------------------
33       this._user    = study.getAuthor();
34       this._operand = study;
35       this._author  = true;                              // In order to ignore the author in this context
36     }
37
38 //  ==============================================================================================================================
39 //  Public member functions
40 //  ==============================================================================================================================
41
42     public boolean canAddScenario () {
43 //  --------------------------------
44       if (_operand.getProgressState() != ProgressState.inWORK && _operand.getProgressState() != ProgressState.inDRAFT) {
45                 return false;
46         }
47       return ServiceLocatorImpl.getInstance().getStudyService().isStaffedBy(_operand, _user);
48     }
49
50 /**
51  * Checks if the user has right to edit the description of the study.
52  * All actors of the study have such right, including the author, contributors, reviewers and approvers.
53  * 
54  * @return true if the user has right to edit the description.
55  */
56     public boolean canEditDescription () {
57 //  ------------------------------------
58       return (_operand.getAuthor().equals(_user) || ServiceLocatorImpl.getInstance().getStudyService().hasActor(_operand, _user));
59     }
60
61     public boolean canEditProperties () {
62 //  -----------------------------------
63       return _author;
64     }
65
66 /**
67  * Checks if the user has right to move the study from the Private to the Public area of the repository.
68  * Only the author of the study have such right.
69  * 
70  * @return true if the user has right to edit the description.
71  */
72     public boolean canPublish () {
73 //  ----------------------------
74       if (!_author) {
75                 return false;
76         }
77       return (!_operand.isPublic());
78     }
79
80     public boolean canPurge () {
81 //  --------------------------
82       if (!_author) {
83                 return false;
84         }
85       return _operand.isVersioned();
86     }
87
88     public boolean canRemove () {
89 //  ---------------------------
90       if (_operand.getProgressState() != ProgressState.inWORK && _operand.getProgressState() != ProgressState.inDRAFT) {
91                 return false;
92         }
93       return _author;
94     }
95
96     public boolean canVersion () {
97 //  ----------------------------
98       if (_operand.getProgressState() != ProgressState.inWORK && _operand.getProgressState() != ProgressState.inDRAFT) {
99                 return false;
100         }
101       return ServiceLocatorImpl.getInstance().getStudyService().isStaffedBy(_operand, _user);
102     }
103
104 //  ==============================================================================================================================
105 //  Getter
106 //  ==============================================================================================================================
107
108     public Study getOperand () {
109 //  --------------------------
110       return _operand;
111     }
112 }