Salome HOME
d90863d02263a91b0bdd81e1726cea33a3f45306
[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. Only the author of the study
68          * have such right.
69          * 
70          * @return true if the user has right to edit the description.
71          */
72         public boolean canPublish() {
73                 // ----------------------------
74                 if (_operand.getProgressState() == ProgressState.APPROVED
75                                 && !_operand.isPublic()/* && "knowledgineer".equals(_user.getRole().getName()) */) {
76                         return true;
77                 }
78                 return false;
79         }
80
81         /**
82          * 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
83          * have such right.
84          * 
85          * @return true if the user has right to edit the description.
86          */
87         public boolean canProtect() {
88                 // ----------------------------
89                 if (_operand.getProgressState() == ProgressState.APPROVED
90                                 && _operand.isPublic()/* && "knowledgineer".equals(_user.getRole().getName()) */) {
91                         return true;
92                 }
93                 return false;
94         }
95
96     public boolean canPurge () {
97 //  --------------------------
98       if (!_author) {
99                 return false;
100         }
101       return _operand.isVersioned();
102     }
103
104     public boolean canRemove () {
105 //  ---------------------------
106       if (_operand.getProgressState() != ProgressState.inWORK && _operand.getProgressState() != ProgressState.inDRAFT) {
107                 return false;
108         }
109       return _author;
110     }
111
112     public boolean canVersion () {
113 //  ----------------------------
114       if (_operand.getProgressState() != ProgressState.inWORK && _operand.getProgressState() != ProgressState.inDRAFT) {
115                 return false;
116         }
117       return ServiceLocatorImpl.getInstance().getStudyService().isStaffedBy(_operand, _user);
118     }
119     
120     /**
121      * Can the given study be marked as reference or not.
122      * @return true/false.
123      */
124     public boolean canMarkStudyAsReference() {
125         
126         if (_operand.getProgressState() == ProgressState.APPROVED /*&& "knowledgineer".equals(_user.getRole().getName())*/) {
127                 return true;
128         }
129         return false;
130     }
131     
132     /**
133      * Can the given study be unmarked as reference or not.
134      * @return true/false.
135      */
136     public boolean canRemoveStudyAsReference() {
137         
138         if (_operand.getProgressState() == ProgressState.TEMPLATE /*&& "knowledgineer".equals(_user.getRole().getName())*/) {
139                 return true;
140         }
141         return false;
142     }
143
144 //  ==============================================================================================================================
145 //  Getter
146 //  ==============================================================================================================================
147
148     public Study getOperand () {
149 //  --------------------------
150       return _operand;
151     }
152 }