Salome HOME
Refactoring: kernel and som are moved to Siman-Common.
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / som / StepRights.java
diff --git a/Workspace/Siman-Common/src/org/splat/som/StepRights.java b/Workspace/Siman-Common/src/org/splat/som/StepRights.java
new file mode 100644 (file)
index 0000000..af15d5c
--- /dev/null
@@ -0,0 +1,109 @@
+package org.splat.som;
+/**
+ * Class defining the default rights related to operations on study steps.
+ * 
+ * @author    Daniel Brunier-Coulin
+ * @copyright OPEN CASCADE 2012
+ */
+//TODO: Review this rights according to the state of the owner study.
+
+import org.splat.kernel.User;
+
+
+public class StepRights {
+
+    private User     user;
+    private Step     operand;
+
+//  ==============================================================================================================================
+//  Construction
+//  ==============================================================================================================================
+
+    public StepRights (User user, Step step) {
+//  ----------------------------------------
+      this.user    = user;
+      this.operand = step;
+    }
+    public StepRights (Step step) {
+//  -----------------------------
+      this.user    = step.getOwner().getAuthor();
+      this.operand = step;
+    }
+
+//  ==============================================================================================================================
+//  Public member functions
+//  ==============================================================================================================================
+
+/**
+ * Checks if the user has right to add a comment attached to the selected step.
+ * All actors of the study have such right, including the author, contributors, reviewers and approvers.
+ * 
+ * @return true if the user has right to add a comment.
+ */
+    public boolean canAddComment () {
+//  -------------------------------
+      Study   owner = operand.getOwnerStudy();
+      return (owner.getAuthor().equals(user) || owner.hasActor(user));
+    }
+
+/**
+ * Checks if the user has right to create or import a document into the selected step.
+ * Only the author and contributors have such right, providing that the study step is enabled for writing.
+ * 
+ * @return true if the user has right to create or import a document.
+ */
+    public boolean canCreateDocument () {
+//  -----------------------------------
+      if (!isEnabled()) return false;
+      return operand.getOwnerStudy().isStaffedBy(user);
+    }
+
+/**
+ * Checks if the user has right to enter a knowledge into the selected step.
+ * Only the author and contributors have such right.
+ * 
+ * @return true if the user has right to enter a knowledge.
+ */
+    public boolean canCreateKnowledge () {
+//  ------------------------------------
+      return operand.getOwnerStudy().isStaffedBy(user);
+    }
+
+/**
+ * Checks if the user has right to edit the simulation contexts attached to the selected step.
+ * All actors of the study have such right, including the author, contributors, reviewers and approvers.
+ * 
+ * @return true if the user has right to edit the simulation contexts.
+ */
+    public boolean canEditSimulationContext () {
+//  ------------------------------------------
+      Study   owner = operand.getOwnerStudy();
+      return (owner.getAuthor().equals(user) || owner.hasActor(user));
+    }
+
+/**
+ * Checks if the selected step is enabled for writing.
+ * A step may be disabled for writing, or locked, following a check-out of the owner scenario.
+ * 
+ * @return true if the step is enabled for writing.
+ */
+    public boolean isEnabled () {
+//  ---------------------------
+      ProjectElement  owner = operand.getOwner();
+      
+      if (owner instanceof Scenario) {
+        Scenario  scene = (Scenario)owner;
+        if (scene.isCheckedout()) return false;
+      }
+      return true;
+    }
+
+//  ==============================================================================================================================
+//  Getters
+//  ==============================================================================================================================
+
+    public Step getOperand () {
+//  -------------------------
+      return operand;
+    }
+}
\ No newline at end of file