3 * Class defining the default rights related to operations on studies.
4 * On the contrary of documents, a study cannot directly be reviewed or approved. It is reviewed or approved through
7 * @author Daniel Brunier-Coulin
8 * @copyright OPEN CASCADE 2012
11 import org.splat.dal.bo.kernel.User;
12 import org.splat.dal.bo.som.ProgressState;
13 import org.splat.dal.bo.som.Study;
14 import org.splat.service.ServiceLocatorImpl;
17 public class StudyRights {
19 private final transient User _user;
20 private final transient Study _operand;
21 private transient boolean _author = false; // For optimizing
22 public StudyRights (final User user, final Study study) {
23 // -------------------------------------------
25 this._operand = study;
27 if (_operand != null && _operand.getAuthor() != null) {
28 this._author = _operand.getAuthor().equals(user); // user may be null
31 public StudyRights (final Study study) {
32 // --------------------------------
33 this._user = study.getAuthor();
34 this._operand = study;
35 this._author = true; // In order to ignore the author in this context
38 // ==============================================================================================================================
39 // Public member functions
40 // ==============================================================================================================================
42 public boolean canAddScenario () {
43 // --------------------------------
44 if (_operand.getProgressState() != ProgressState.inWORK && _operand.getProgressState() != ProgressState.inDRAFT) {
47 return ServiceLocatorImpl.getInstance().getStudyService().isStaffedBy(_operand, _user);
51 * Checks if the user has right to edit the description of the study.
52 * All actors of the study have such right, including the author, contributors, reviewers and approvers.
54 * @return true if the user has right to edit the description.
56 public boolean canEditDescription () {
57 // ------------------------------------
58 return (_operand.getAuthor().equals(_user) || ServiceLocatorImpl.getInstance().getStudyService().hasActor(_operand, _user));
61 public boolean canEditProperties () {
62 // -----------------------------------
67 * 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
70 * @return true if the user has right to edit the description.
72 public boolean canPublish() {
73 // ----------------------------
74 if (_operand.getProgressState() == ProgressState.APPROVED
75 && !_operand.isPublic()/* && "knowledgineer".equals(_user.getRole().getName()) */) {
82 * Checks if the user has right to move the study from the Public to the Private area of the repository. Only the author of the study
85 * @return true if the user has right to edit the description.
87 public boolean canProtect() {
88 // ----------------------------
89 if (_operand.getProgressState() == ProgressState.APPROVED
90 && _operand.isPublic()/* && "knowledgineer".equals(_user.getRole().getName()) */) {
96 public boolean canPurge () {
97 // --------------------------
101 return _operand.isVersioned();
104 public boolean canRemove () {
105 // ---------------------------
106 if (_operand.getProgressState() != ProgressState.inWORK && _operand.getProgressState() != ProgressState.inDRAFT) {
112 public boolean canVersion () {
113 // ----------------------------
114 if (_operand.getProgressState() != ProgressState.inWORK && _operand.getProgressState() != ProgressState.inDRAFT) {
117 return ServiceLocatorImpl.getInstance().getStudyService().isStaffedBy(_operand, _user);
121 * Can the given study be marked as reference or not.
122 * @return true/false.
124 public boolean canMarkStudyAsReference() {
126 if (_operand.getProgressState() == ProgressState.APPROVED /*&& "knowledgineer".equals(_user.getRole().getName())*/) {
133 * Can the given study be unmarked as reference or not.
134 * @return true/false.
136 public boolean canRemoveStudyAsReference() {
138 if (_operand.getProgressState() == ProgressState.TEMPLATE /*&& "knowledgineer".equals(_user.getRole().getName())*/) {
144 // ==============================================================================================================================
146 // ==============================================================================================================================
148 public Study getOperand () {
149 // --------------------------