]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman-Common/src/org/splat/som/StudyRights.java
Salome HOME
More business logic has been moved from BO to services. ServiceLocator is created...
[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 User     user;
20     private Study    operand;
21     private boolean  author = false;                    // For optimizing 
22         public StudyRights (User user, Study study) {
23 //  -------------------------------------------
24       this.user    = user;
25       this.operand = study;
26       this.author  = operand.getAuthor().equals(user);  // user may be null
27     }
28     public StudyRights (Study study) {
29 //  --------------------------------
30       this.user    = study.getAuthor();
31       this.operand = study;
32       this.author  = true;                              // In order to ignore the author in this context
33     }
34
35 //  ==============================================================================================================================
36 //  Public member functions
37 //  ==============================================================================================================================
38
39     public boolean canAddScenario () {
40 //  --------------------------------
41       if (operand.getProgressState() != ProgressState.inWORK && operand.getProgressState() != ProgressState.inDRAFT) return false;
42       return ServiceLocatorImpl.getInstance().getStudyService().isStaffedBy(operand, user);
43     }
44
45 /**
46  * Checks if the user has right to edit the description of the study.
47  * All actors of the study have such right, including the author, contributors, reviewers and approvers.
48  * 
49  * @return true if the user has right to edit the description.
50  */
51     public boolean canEditDescription () {
52 //  ------------------------------------
53       return (operand.getAuthor().equals(user) || ServiceLocatorImpl.getInstance().getStudyService().hasActor(operand, user));
54     }
55
56     public boolean canEditProperties () {
57 //  -----------------------------------
58       return author;
59     }
60
61 /**
62  * Checks if the user has right to move the study from the Private to the Public area of the repository.
63  * Only the author of the study have such right.
64  * 
65  * @return true if the user has right to edit the description.
66  */
67     public boolean canPublish () {
68 //  ----------------------------
69       if (!author) return false;
70       return (!operand.isPublic());
71     }
72
73     public boolean canPurge () {
74 //  --------------------------
75       if (!author) return false;
76       return operand.isVersioned();
77     }
78
79     public boolean canRemove () {
80 //  ---------------------------
81       if (operand.getProgressState() != ProgressState.inWORK && operand.getProgressState() != ProgressState.inDRAFT) return false;
82       return author;
83     }
84
85     public boolean canVersion () {
86 //  ----------------------------
87       if (operand.getProgressState() != ProgressState.inWORK && operand.getProgressState() != ProgressState.inDRAFT) return false;
88       return ServiceLocatorImpl.getInstance().getStudyService().isStaffedBy(operand, user);
89     }
90
91 //  ==============================================================================================================================
92 //  Getter
93 //  ==============================================================================================================================
94
95     public Study getOperand () {
96 //  --------------------------
97       return operand;
98     }
99 }