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 / 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 import org.splat.service.ServiceLocatorImpl;
15
16
17 public class StepRights {
18
19     private User     user;
20     private Step     operand;
21         public StepRights (User user, Step step) {
22 //  ----------------------------------------
23       this.user    = user;
24       this.operand = step;
25     }
26     public StepRights (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()) return false;
57       return ServiceLocatorImpl.getInstance().getStudyService().isStaffedBy(operand.getOwnerStudy(), user);
58     }
59
60 /**
61  * Checks if the user has right to enter a knowledge into the selected step.
62  * Only the author and contributors have such right.
63  * 
64  * @return true if the user has right to enter a knowledge.
65  */
66     public boolean canCreateKnowledge () {
67 //  ------------------------------------
68       return ServiceLocatorImpl.getInstance().getStudyService().isStaffedBy(operand.getOwnerStudy(), user);
69     }
70
71 /**
72  * Checks if the user has right to edit the simulation contexts attached to the selected step.
73  * All actors of the study have such right, including the author, contributors, reviewers and approvers.
74  * 
75  * @return true if the user has right to edit the simulation contexts.
76  */
77     public boolean canEditSimulationContext () {
78 //  ------------------------------------------
79       Study   owner = operand.getOwnerStudy();
80       return (owner.getAuthor().equals(user) || ServiceLocatorImpl.getInstance().getStudyService().hasActor(owner, user));
81     }
82
83 /**
84  * Checks if the selected step is enabled for writing.
85  * A step may be disabled for writing, or locked, following a check-out of the owner scenario.
86  * 
87  * @return true if the step is enabled for writing.
88  */
89     public boolean isEnabled () {
90 //  ---------------------------
91       ProjectElement  owner = operand.getOwner();
92       
93       if (owner instanceof Scenario) {
94         Scenario  scene = (Scenario)owner;
95         if (scene.isCheckedout()) return false;
96       }
97       return true;
98     }
99
100 //  ==============================================================================================================================
101 //  Getters
102 //  ==============================================================================================================================
103
104     public Step getOperand () {
105 //  -------------------------
106       return operand;
107     }
108 }