Salome HOME
Siman codebase is refactored. Spring beans are introduced in the context.
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / som / StepRights.java
1 package org.splat.som;
2 /**
3  * Class defining the default rights related to operations on study steps.
4  * 
5  * @author    Daniel Brunier-Coulin
6  * @copyright OPEN CASCADE 2012
7  */
8 //TODO: Review this rights according to the state of the owner study.
9
10 import org.splat.dal.bo.kernel.User;
11 import org.splat.dal.bo.som.ProjectElement;
12 import org.splat.dal.bo.som.Scenario;
13 import org.splat.dal.bo.som.Study;
14
15
16 public class StepRights {
17
18     private User     user;
19     private Step     operand;
20
21 //  ==============================================================================================================================
22 //  Construction
23 //  ==============================================================================================================================
24
25     public StepRights (User user, Step step) {
26 //  ----------------------------------------
27       this.user    = user;
28       this.operand = step;
29     }
30     public StepRights (Step step) {
31 //  -----------------------------
32       this.user    = step.getOwner().getAuthor();
33       this.operand = step;
34     }
35
36 //  ==============================================================================================================================
37 //  Public member functions
38 //  ==============================================================================================================================
39
40 /**
41  * Checks if the user has right to add a comment attached to the selected step.
42  * All actors of the study have such right, including the author, contributors, reviewers and approvers.
43  * 
44  * @return true if the user has right to add a comment.
45  */
46     public boolean canAddComment () {
47 //  -------------------------------
48       Study   owner = operand.getOwnerStudy();
49       return (owner.getAuthor().equals(user) || owner.hasActor(user));
50     }
51
52 /**
53  * Checks if the user has right to create or import a document into the selected step.
54  * Only the author and contributors have such right, providing that the study step is enabled for writing.
55  * 
56  * @return true if the user has right to create or import a document.
57  */
58     public boolean canCreateDocument () {
59 //  -----------------------------------
60       if (!isEnabled()) return false;
61       return operand.getOwnerStudy().isStaffedBy(user);
62     }
63
64 /**
65  * Checks if the user has right to enter a knowledge into the selected step.
66  * Only the author and contributors have such right.
67  * 
68  * @return true if the user has right to enter a knowledge.
69  */
70     public boolean canCreateKnowledge () {
71 //  ------------------------------------
72       return operand.getOwnerStudy().isStaffedBy(user);
73     }
74
75 /**
76  * Checks if the user has right to edit the simulation contexts attached to the selected step.
77  * All actors of the study have such right, including the author, contributors, reviewers and approvers.
78  * 
79  * @return true if the user has right to edit the simulation contexts.
80  */
81     public boolean canEditSimulationContext () {
82 //  ------------------------------------------
83       Study   owner = operand.getOwnerStudy();
84       return (owner.getAuthor().equals(user) || owner.hasActor(user));
85     }
86
87 /**
88  * Checks if the selected step is enabled for writing.
89  * A step may be disabled for writing, or locked, following a check-out of the owner scenario.
90  * 
91  * @return true if the step is enabled for writing.
92  */
93     public boolean isEnabled () {
94 //  ---------------------------
95       ProjectElement  owner = operand.getOwner();
96       
97       if (owner instanceof Scenario) {
98         Scenario  scene = (Scenario)owner;
99         if (scene.isCheckedout()) return false;
100       }
101       return true;
102     }
103
104 //  ==============================================================================================================================
105 //  Getters
106 //  ==============================================================================================================================
107
108     public Step getOperand () {
109 //  -------------------------
110       return operand;
111     }
112 }