3 * Class defining the default rights related to operations on study steps.
5 * @author Daniel Brunier-Coulin
6 * @copyright OPEN CASCADE 2012-2015
8 //TODO: Review this rights according to the state of the owner study.
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;
17 public class StepRights {
19 private final transient User _user;
20 private final transient Step _operand;
21 public StepRights (final User user, final Step step) {
22 // ----------------------------------------
26 public StepRights (final Step step) {
27 // -----------------------------
28 this._user = step.getOwner().getAuthor();
32 // ==============================================================================================================================
33 // Public member functions
34 // ==============================================================================================================================
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.
40 * @return true if the user has right to add a comment.
42 public boolean canAddComment () {
43 // -------------------------------
44 Study owner = _operand.getOwnerStudy();
45 return (owner.getAuthor().equals(_user) || ServiceLocatorImpl.getInstance().getStudyService().hasActor(owner, _user));
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.
52 * @return true if the user has right to create or import a document.
54 public boolean canCreateDocument () {
55 // -----------------------------------
59 return ServiceLocatorImpl.getInstance().getStudyService().isStaffedBy(_operand.getOwnerStudy(), _user);
63 * Checks if the user has right to enter a knowledge into the selected step.
64 * Only the author and contributors have such right.
66 * @return true if the user has right to enter a knowledge.
68 public boolean canCreateKnowledge () {
69 // ------------------------------------
70 return ServiceLocatorImpl.getInstance().getStudyService().isStaffedBy(_operand.getOwnerStudy(), _user);
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.
77 * @return true if the user has right to edit the simulation contexts.
79 public boolean canEditSimulationContext () {
80 // ------------------------------------------
81 Study owner = _operand.getOwnerStudy();
82 return (owner.getAuthor().equals(_user) || ServiceLocatorImpl.getInstance().getStudyService().hasActor(owner, _user));
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.
89 * @return true if the step is enabled for writing.
91 public boolean isEnabled () {
92 // ---------------------------
93 ProjectElement owner = _operand.getOwner();
95 if (owner instanceof Scenario) {
96 Scenario scene = (Scenario)owner;
97 if (scene.isCheckedout()) {
104 // ==============================================================================================================================
106 // ==============================================================================================================================
108 public Step getOperand () {
109 // -------------------------