3 * Class defining the default rights related to operations on study steps.
5 * @author Daniel Brunier-Coulin
6 * @copyright OPEN CASCADE 2012
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 {
21 public StepRights (User user, Step step) {
22 // ----------------------------------------
26 public StepRights (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 // -----------------------------------
56 if (!isEnabled()) return false;
57 return ServiceLocatorImpl.getInstance().getStudyService().isStaffedBy(operand.getOwnerStudy(), user);
61 * Checks if the user has right to enter a knowledge into the selected step.
62 * Only the author and contributors have such right.
64 * @return true if the user has right to enter a knowledge.
66 public boolean canCreateKnowledge () {
67 // ------------------------------------
68 return ServiceLocatorImpl.getInstance().getStudyService().isStaffedBy(operand.getOwnerStudy(), user);
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.
75 * @return true if the user has right to edit the simulation contexts.
77 public boolean canEditSimulationContext () {
78 // ------------------------------------------
79 Study owner = operand.getOwnerStudy();
80 return (owner.getAuthor().equals(user) || ServiceLocatorImpl.getInstance().getStudyService().hasActor(owner, user));
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.
87 * @return true if the step is enabled for writing.
89 public boolean isEnabled () {
90 // ---------------------------
91 ProjectElement owner = operand.getOwner();
93 if (owner instanceof Scenario) {
94 Scenario scene = (Scenario)owner;
95 if (scene.isCheckedout()) return false;
100 // ==============================================================================================================================
102 // ==============================================================================================================================
104 public Step getOperand () {
105 // -------------------------