Salome HOME
Siman codebase is refactored. Spring beans are introduced in the context.
[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
15
16 public class StudyRights {
17
18     private User     user;
19     private Study    operand;
20     private boolean  author = false;                    // For optimizing 
21
22 //  ==============================================================================================================================
23 //  Construction
24 //  ==============================================================================================================================
25
26     public StudyRights (User user, Study study) {
27 //  -------------------------------------------
28       this.user    = user;
29       this.operand = study;
30       this.author  = operand.getAuthor().equals(user);  // user may be null
31     }
32     public StudyRights (Study study) {
33 //  --------------------------------
34       this.user    = study.getAuthor();
35       this.operand = study;
36       this.author  = true;                              // In order to ignore the author in this context
37     }
38
39 //  ==============================================================================================================================
40 //  Public member functions
41 //  ==============================================================================================================================
42
43     public boolean canAddScenario () {
44 //  --------------------------------
45       if (operand.getProgressState() != ProgressState.inWORK && operand.getProgressState() != ProgressState.inDRAFT) return false;
46       return operand.isStaffedBy(user);
47     }
48
49 /**
50  * Checks if the user has right to edit the description of the study.
51  * All actors of the study have such right, including the author, contributors, reviewers and approvers.
52  * 
53  * @return true if the user has right to edit the description.
54  */
55     public boolean canEditDescription () {
56 //  ------------------------------------
57       return (operand.getAuthor().equals(user) || operand.hasActor(user));
58     }
59
60     public boolean canEditProperties () {
61 //  -----------------------------------
62       return author;
63     }
64
65 /**
66  * Checks if the user has right to move the study from the Private to the Public area of the repository.
67  * Only the author of the study have such right.
68  * 
69  * @return true if the user has right to edit the description.
70  */
71     public boolean canPublish () {
72 //  ----------------------------
73       if (!author) return false;
74       return (!operand.isPublic());
75     }
76
77     public boolean canPurge () {
78 //  --------------------------
79       if (!author) return false;
80       return operand.isVersioned();
81     }
82
83     public boolean canRemove () {
84 //  ---------------------------
85       if (operand.getProgressState() != ProgressState.inWORK && operand.getProgressState() != ProgressState.inDRAFT) return false;
86       return author;
87     }
88
89     public boolean canVersion () {
90 //  ----------------------------
91       if (operand.getProgressState() != ProgressState.inWORK && operand.getProgressState() != ProgressState.inDRAFT) return false;
92       return operand.isStaffedBy(user);
93     }
94
95 //  ==============================================================================================================================
96 //  Getter
97 //  ==============================================================================================================================
98
99     public Study getOperand () {
100 //  --------------------------
101       return operand;
102     }
103 }