Salome HOME
Copyrights update 2015.
[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-2015
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 import org.splat.service.ServiceLocatorImpl;
15
16
17 public class StepRights {
18
19     private final transient User     _user;
20     private final transient Step     _operand;
21         public StepRights (final User user, final Step step) {
22 //  ----------------------------------------
23       this._user    = user;
24       this._operand = step;
25     }
26     public StepRights (final Step step) {
27 //  -----------------------------
28       this._user    = step.getOwner().getAuthor();
29       this._operand = step;
30     }
31
32 //  ==============================================================================================================================
33 //  Public member functions
34 //  ==============================================================================================================================
35
36 /**
37  * Checks if the user has right to add a comment attached to the selected step.
38  * All actors of the study have such right, including the author, contributors, reviewers and approvers.
39  * 
40  * @return true if the user has right to add a comment.
41  */
42     public boolean canAddComment () {
43 //  -------------------------------
44       Study   owner = _operand.getOwnerStudy();
45       return (owner.getAuthor().equals(_user) || ServiceLocatorImpl.getInstance().getStudyService().hasActor(owner, _user));
46     }
47
48 /**
49  * Checks if the user has right to create or import a document into the selected step.
50  * Only the author and contributors have such right, providing that the study step is enabled for writing.
51  * 
52  * @return true if the user has right to create or import a document.
53  */
54     public boolean canCreateDocument () {
55 //  -----------------------------------
56       if (!isEnabled()) {
57                 return false;
58         }
59       return ServiceLocatorImpl.getInstance().getStudyService().isStaffedBy(_operand.getOwnerStudy(), _user);
60     }
61
62 /**
63  * Checks if the user has right to enter a knowledge into the selected step.
64  * Only the author and contributors have such right.
65  * 
66  * @return true if the user has right to enter a knowledge.
67  */
68     public boolean canCreateKnowledge () {
69 //  ------------------------------------
70       return ServiceLocatorImpl.getInstance().getStudyService().isStaffedBy(_operand.getOwnerStudy(), _user);
71     }
72
73 /**
74  * Checks if the user has right to edit the simulation contexts attached to the selected step.
75  * All actors of the study have such right, including the author, contributors, reviewers and approvers.
76  * 
77  * @return true if the user has right to edit the simulation contexts.
78  */
79     public boolean canEditSimulationContext () {
80 //  ------------------------------------------
81       Study   owner = _operand.getOwnerStudy();
82       return (owner.getAuthor().equals(_user) || ServiceLocatorImpl.getInstance().getStudyService().hasActor(owner, _user));
83     }
84
85 /**
86  * Checks if the selected step is enabled for writing.
87  * A step may be disabled for writing, or locked, following a check-out of the owner scenario.
88  * 
89  * @return true if the step is enabled for writing.
90  */
91     public boolean isEnabled () {
92 //  ---------------------------
93       ProjectElement  owner = _operand.getOwner();
94       
95       if (owner instanceof Scenario) {
96         Scenario  scene = (Scenario)owner;
97         if (scene.isCheckedout()) {
98                         return false;
99                 }
100       }
101       return true;
102     }
103
104 //  ==============================================================================================================================
105 //  Getters
106 //  ==============================================================================================================================
107
108     public Step getOperand () {
109 //  -------------------------
110       return _operand;
111     }
112 }