]> SALOME platform Git repositories - tools/siman.git/blobdiff - Workspace/Siman-Common/src/org/splat/som/StudyRights.java
Salome HOME
Refactoring: kernel and som are moved to Siman-Common.
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / som / StudyRights.java
diff --git a/Workspace/Siman-Common/src/org/splat/som/StudyRights.java b/Workspace/Siman-Common/src/org/splat/som/StudyRights.java
new file mode 100644 (file)
index 0000000..4b23afc
--- /dev/null
@@ -0,0 +1,101 @@
+package org.splat.som;
+/**
+ * Class defining the default rights related to operations on studies.
+ * On the contrary of documents, a study cannot directly be reviewed or approved. It is reviewed or approved through
+ * its final report.
+ * 
+ * @author    Daniel Brunier-Coulin
+ * @copyright OPEN CASCADE 2012
+ */
+
+import org.splat.kernel.User;
+
+
+public class StudyRights {
+
+    private User     user;
+    private Study    operand;
+    private boolean  author = false;                    // For optimizing 
+
+//  ==============================================================================================================================
+//  Construction
+//  ==============================================================================================================================
+
+    public StudyRights (User user, Study study) {
+//  -------------------------------------------
+      this.user    = user;
+      this.operand = study;
+      this.author  = operand.getAuthor().equals(user);  // user may be null
+    }
+    public StudyRights (Study study) {
+//  --------------------------------
+      this.user    = study.getAuthor();
+      this.operand = study;
+      this.author  = true;                              // In order to ignore the author in this context
+    }
+
+//  ==============================================================================================================================
+//  Public member functions
+//  ==============================================================================================================================
+
+    public boolean canAddScenario () {
+//  --------------------------------
+      if (operand.getProgressState() != ProgressState.inWORK && operand.getProgressState() != ProgressState.inDRAFT) return false;
+      return operand.isStaffedBy(user);
+    }
+
+/**
+ * Checks if the user has right to edit the description of the study.
+ * 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 description.
+ */
+    public boolean canEditDescription () {
+//  ------------------------------------
+      return (operand.getAuthor().equals(user) || operand.hasActor(user));
+    }
+
+    public boolean canEditProperties () {
+//  -----------------------------------
+      return author;
+    }
+
+/**
+ * Checks if the user has right to move the study from the Private to the Public area of the repository.
+ * Only the author of the study have such right.
+ * 
+ * @return true if the user has right to edit the description.
+ */
+    public boolean canPublish () {
+//  ----------------------------
+      if (!author) return false;
+      return (!operand.isPublic());
+    }
+
+    public boolean canPurge () {
+//  --------------------------
+      if (!author) return false;
+      return operand.isVersioned();
+    }
+
+    public boolean canRemove () {
+//  ---------------------------
+      if (operand.getProgressState() != ProgressState.inWORK && operand.getProgressState() != ProgressState.inDRAFT) return false;
+      return author;
+    }
+
+    public boolean canVersion () {
+//  ----------------------------
+      if (operand.getProgressState() != ProgressState.inWORK && operand.getProgressState() != ProgressState.inDRAFT) return false;
+      return operand.isStaffedBy(user);
+    }
+
+//  ==============================================================================================================================
+//  Getter
+//  ==============================================================================================================================
+
+    public Study getOperand () {
+//  --------------------------
+      return operand;
+    }
+}
\ No newline at end of file