Salome HOME
Creation of a new study from an existing one is implemented.
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / dal / bo / som / ValidationCycle.java
index 5c67d1e10f03e2c8ecc8ddafdf15223e918257a6..f08829bea1d5acc4455e653f6126e0ab01931ece 100644 (file)
@@ -1,4 +1,5 @@
 package org.splat.dal.bo.som;
+
 /**
  * Class defining the validation cycle applicable to documents of a given type.<br/>
  * A validation cycle specifies the validation steps of documents complying with by this cycle, as well as the actors
@@ -26,7 +27,8 @@ package org.splat.dal.bo.som;
  * @copyright OPEN CASCADE 2012
  */
 
-import java.util.Vector;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.splat.dal.bo.kernel.Persistent;
 import org.splat.dal.bo.kernel.User;
@@ -36,277 +38,307 @@ import org.splat.kernel.MultiplyDefinedException;
 
 public class ValidationCycle extends Persistent {
 
-       private  ValidationCycleRelation context;
-    private  DocumentType            mytype;      // Null if the referenced validation cycle is a default one
-       private  User                    publisher;
-    private  User                    reviewer;    // Null if no REVIEW validation step
-    private  User                    approver;    // Null if no APPROVAL validation step
-    private  User                    signatory;   // Null if no ACCEPTANCE validation step
-
-    public enum Actor {
-      manager,                                    // Responsible of study 
-      Nx1,                                        // N+1 manager of the responsible of study
-      Nx2,                                        // N+2 manager of the responsible of study
-      customer                                    // Customer
-    }
-
-//  ==============================================================================================================================
-//  Construction
-//  ==============================================================================================================================
-    
-//  Fields initialization class
-    public static class Properties extends Persistent.Properties {
-//  ------------------------------------------------------------
-      DocumentType doctype   = null;
-      User         publisher = null;
-      User         reviewer  = null;
-      User         approver  = null;
-      User         signatory = null;
-
-//  - Public services
-
-      @Override
-       public void clear () {
-        super.clear();
-        doctype   = null;
-        publisher = null;
-        reviewer  = null;
-        approver  = null;
-        signatory = null;
-      }
-//  - Protected services
-
-      public Properties setDocumentType (final DocumentType type)
-      {
-        doctype = type;
-       return this;
-      }
-//  - Properties setter
-
-      public Properties setActor (final ValidationStep step, final User actor)
-      {
-        if      (step == ValidationStep.PROMOTION) {
-                       publisher = actor;
-               } else if (step == ValidationStep.REVIEW) {
-                       reviewer  = actor;
-               } else if (step == ValidationStep.APPROVAL) {
-                       approver  = actor;
-               } else if (step == ValidationStep.ACCEPTANCE || step == ValidationStep.REFUSAL) {
-                       signatory = actor;
+       private ValidationCycleRelation context;
+       private DocumentType mytype; // Null if the referenced validation cycle is a default one
+       private User publisher;
+       private User reviewer; // Null if no REVIEW validation step
+       private User approver; // Null if no APPROVAL validation step
+       private User signatory; // Null if no ACCEPTANCE validation step
+
+       public enum Actor {
+               manager, // Responsible of study
+               Nx1, // N+1 manager of the responsible of study
+               Nx2, // N+2 manager of the responsible of study
+               customer
+               // Customer
+       }
+
+       // ==============================================================================================================================
+       // Construction
+       // ==============================================================================================================================
+
+       // Fields initialization class
+       public static class Properties extends Persistent.Properties {
+               DocumentType doctype = null;
+               User publisher = null;
+               User reviewer = null;
+               User approver = null;
+               User signatory = null;
+
+               // - Public services
+
+               @Override
+               public void clear() {
+                       super.clear();
+                       doctype = null;
+                       publisher = null;
+                       reviewer = null;
+                       approver = null;
+                       signatory = null;
+               }
+
+               // - Protected services
+
+               public Properties setDocumentType(final DocumentType type) {
+                       doctype = type;
+                       return this;
+               }
+
+               // - Properties setter
+
+               public Properties setActor(final ValidationStep step, final User actor) {
+                       if (step == ValidationStep.PROMOTION) {
+                               publisher = actor;
+                       } else if (step == ValidationStep.REVIEW) {
+                               reviewer = actor;
+                       } else if (step == ValidationStep.APPROVAL) {
+                               approver = actor;
+                       } else if (step == ValidationStep.ACCEPTANCE
+                                       || step == ValidationStep.REFUSAL) {
+                               signatory = actor;
+                       }
+                       return this;
+               }
+
+               // - Global validity check
+
+               public void checkValidity() throws MissedPropertyException {
+                       if (doctype == null) {
+                               throw new MissedPropertyException("type");
+                       }
+               }
+
+               /**
+                * Get the publisher.
+                * 
+                * @return the publisher
+                */
+               public User getPublisher() {
+                       return publisher;
+               }
+
+               /**
+                * Get the reviewer.
+                * 
+                * @return the reviewer
+                */
+               public User getReviewer() {
+                       return reviewer;
+               }
+
+               /**
+                * Get the approver.
+                * 
+                * @return the approver
+                */
+               public User getApprover() {
+                       return approver;
                }
-        return this;
-      }
-//  - Global validity check
-        
-      public void checkValidity() throws MissedPropertyException
-      { 
-        if (doctype == null) {
-                       throw new MissedPropertyException("type");
+
+               /**
+                * Get the signatory.
+                * 
+                * @return the signatory
+                */
+               public User getSignatory() {
+                       return signatory;
                }
-      }
+       }
+
+       // Database fetch constructor
+       public ValidationCycle() {
+               super();
+       }
+
+       public ValidationCycle(final Study from, final Properties vprop)
+                       throws MissedPropertyException, InvalidPropertyException,
+                       MultiplyDefinedException {
+               super(vprop); // Throws one of the above exception if not valid
+               mytype = vprop.doctype;
+               publisher = vprop.publisher; // May be null
+               reviewer = vprop.reviewer; // May be null
+               approver = vprop.approver; // May be null
+               signatory = vprop.signatory; // May be null
+               context = new ValidationCycleRelation(from, this);
+       }
 
        /**
-        * Get the publisher.
-        * @return the publisher
+        * Create a copy of the given cycle for the given study.
+        * 
+        * @param study
+        *            the owner study
+        * @return the cloned validation cycle
         */
-       public User getPublisher() {
-               return publisher;
+       public ValidationCycle clone(final Study study) {
+               ValidationCycle res = new ValidationCycle();
+               res.mytype = this.mytype;
+               res.publisher = this.publisher; // May be null
+               res.reviewer = this.reviewer; // May be null
+               res.approver = this.approver; // May be null
+               res.signatory = this.signatory; // May be null
+               res.context = new ValidationCycleRelation(study, res);
+               return res;
        }
 
+       // ==============================================================================================================================
+       // Public member functions
+       // ==============================================================================================================================
        /**
-        * Get the reviewer.
-        * @return the reviewer
+        * Checks if a given validation step is enabled in this validation cycle.
+        * 
+        * @param step
+        *            the validation step checked.
+        * @return true if the given validation step is enabled.
         */
-       public User getReviewer() {
-               return reviewer;
+       public boolean enables(final ValidationStep step) {
+               boolean res = false;
+               if (step == ValidationStep.PROMOTION) {
+                       res = true;
+               } else if (step == ValidationStep.REVIEW) {
+                       res = (reviewer != null);
+               } else if (step == ValidationStep.APPROVAL) {
+                       res = (approver != null);
+               } else if (step == ValidationStep.ACCEPTANCE
+                               || step == ValidationStep.REFUSAL) {
+                       res = (signatory != null);
+               }
+               return res;
        }
 
        /**
-        * Get the approver.
-        * @return the approver
+        * Returns the user involved in a given step of this document validation cycle. When enabled, the Review and Approval steps have one
+        * explicit actor returned by this function. On the other hand, Promotion and Acceptance have default actors - they respectively are the
+        * author of the document or the responsible of study, and the customer or its representative internal user. In this context, a null
+        * user is returned.
+        * 
+        * @param step
+        *            the validation step
+        * @return the user involved by the given step or null if the step is disabled or the actors are the default ones
+        * @see #getAllActors()
+        * @see #enables
         */
-       public User getApprover() {
-               return approver;
+       public User getActor(final ValidationStep step) {
+               User res = null;
+               if (step == ValidationStep.PROMOTION) {
+                       res = publisher;
+               } else if (step == ValidationStep.REVIEW) {
+                       res = reviewer;
+               } else if (step == ValidationStep.APPROVAL) {
+                       res = approver;
+               } else if (step == ValidationStep.ACCEPTANCE
+                               || step == ValidationStep.REFUSAL) {
+                       res = signatory;
+               }
+               return res;
        }
 
        /**
-        * Get the signatory.
-        * @return the signatory
+        * Returns all explicit actors of this document validation cycle, that is, actors of enabled validation cycles, excluding the default
+        * actors.
+        * 
+        * @return the users explicitly involved by the steps of this validation cycle
+        * @see #getActor(ValidationStep)
+        * @see #enables(ValidationStep)
         */
-       public User getSignatory() {
-               return signatory;
-       }
-    }
-//  Database fetch constructor
-    public ValidationCycle () {
-    }
-    public ValidationCycle (final Study from, final Properties vprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException {
-        super(vprop);                  // Throws one of the above exception if not valid
-        mytype    = vprop.doctype;
-        publisher = vprop.publisher;   // May be null
-        reviewer  = vprop.reviewer;    // May be null
-        approver  = vprop.approver;    // May be null
-        signatory = vprop.signatory;   // May be null
-        context   = new ValidationCycleRelation(from, this);
-      }
-
-    /**
-     * Create a copy of the given cycle for the given study.
-     * @param study the owner study
-     * @param src the original validation cycle
-     */
-    public ValidationCycle (final Study study, final ValidationCycle src) {
-        super();                  // Throws one of the above exception if not valid
-        mytype    = src.getDocumentType();
-        publisher = src.publisher;   // May be null
-        reviewer  = src.reviewer;    // May be null
-        approver  = src.approver;    // May be null
-        signatory = src.signatory;   // May be null
-        context   = new ValidationCycleRelation(study, this);
-      }
-
-//  ==============================================================================================================================
-//  Public member functions
-//  ==============================================================================================================================
-/**
- * Checks if a given validation step is enabled in this validation cycle.
- * 
- * @param  step the validation step checked.
- * @return true if the given validation step is enabled.
- */
-    public boolean enables (final ValidationStep step) {
-      if      (step == ValidationStep.PROMOTION) {
-               return true;
-       } else if (step == ValidationStep.REVIEW) {
-               return (reviewer  != null);
-       } else if (step == ValidationStep.APPROVAL) {
-               return (approver  != null);
-       } else if (step == ValidationStep.ACCEPTANCE || step == ValidationStep.REFUSAL) {
-               return (signatory != null);
+       public User[] getAllActors() {
+               List<User> result = new ArrayList<User>();
+               if (publisher != null) {
+                       result.add(publisher);
+               }
+               if (reviewer != null) {
+                       result.add(reviewer);
+               }
+               if (approver != null) {
+                       result.add(approver);
+               }
+               if (signatory != null) {
+                       result.add(signatory);
+               }
+               return result.toArray(new User[result.size()]);
        }
-      return false;
-    }
 
-/**
- * Returns the user involved in a given step of this document validation cycle.
- * When enabled, the Review and Approval steps have one explicit actor returned by this function. On the other hand,
- * Promotion and Acceptance have default actors - they respectively are the author of the document or the responsible of study,
- * and the customer or its representative internal user. In this context, a null user is returned.
- * 
- * @param  step the validation step
- * @return the user involved by the given step or null if the step is disabled or the actors are the default ones
- * @see    #getAllActors()
- * @see    #enables
- */
-    public User getActor (final ValidationStep step) {
-      if      (step == ValidationStep.PROMOTION) {
-               return publisher;
-       } else if (step == ValidationStep.REVIEW) {
-               return reviewer;
-       } else if (step == ValidationStep.APPROVAL) {
-               return approver;
-       } else if (step == ValidationStep.ACCEPTANCE || step == ValidationStep.REFUSAL) {
-               return signatory;
+       /**
+        * Return the document type to which this validation cycle applies. If this validation cycle is a default one, the document type is not
+        * defined.
+        * 
+        * @return the document type involved by this validation cycle, or null if this validation cycle is a default one.
+        * @see #isDefault()
+        */
+       public DocumentType getDocumentType() {
+               return mytype; // May be null
        }
-      return null;
-    }
 
-/**
- * Returns all explicit actors of this document validation cycle, that is, actors of enabled validation cycles, excluding
- * the default actors.
- * 
- * @return the users explicitly involved by the steps of this validation cycle
- * @see    #getActor(ValidationStep)
- * @see    #enables(ValidationStep)
- */
-    public User[] getAllActors () {
-//  -----------------------------
-      Vector<User> result = new Vector<User>();
-      if (publisher != null) {
-               result.add(publisher);
-       }
-      if (reviewer  != null) {
-               result.add(reviewer);
-       }
-      if (approver  != null) {
-               result.add(approver);
+       /**
+        * Set a document type for the validation cycle.
+        * 
+        * @param aType
+        *            the document type
+        */
+       public void setDocumentType(final DocumentType aType) {
+               mytype = aType; // May be null
        }
-      if (signatory != null) {
-               result.add(signatory);
+
+       /**
+        * Checks if this validation cycle is assigned to a study. If not, it is common to all studies of the workflow in which it has been
+        * defined.
+        * 
+        * @return true if this validation cycle is assigned to a study.
+        */
+       public boolean isAssigned() {
+               return (context != null);
        }
-      return  result.toArray(new User[result.size()]);
-    }
 
-/**
- * Return the document type to which this validation cycle applies. If this validation cycle is a default one, the document
- * type is not defined.
- * 
- * @return the document type involved by this validation cycle, or null if this validation cycle is a default one.
- * @see    #isDefault()
- */
-    public DocumentType getDocumentType () {
-          return mytype;                    // May be null
-        }
-
-    /**
-     * Set a document type for the validation cycle.
-     * @param aType the document type
-     */
-    public void setDocumentType (final DocumentType aType) {
-          mytype = aType;                    // May be null
-    }
+       /**
+        * Checks if this validation cycle is a default one, either specific to a Study or defined in the configuration workflow or built-in.<br/>
+        * Default validation cycle are not attached to any document type. As for built-in ones, they doesn't include any validation step other
+        * than Promotion.
+        * 
+        * @return true if this validation cycle is a default one.
+        * @see #getDocumentType()
+        */
+       public boolean isDefault() {
+               return (mytype == null);
+       }
 
-/**
- * Checks if this validation cycle is assigned to a study. If not, it is common to all studies of the workflow in which it has
- * been defined.
- * 
- * @return true if this validation cycle is assigned to a study.
- */
-    public boolean isAssigned () {
-      return (context != null);
-    }
+       public ValidationCycleRelation getContext() {
+               return context;
+       }
 
-/**
- * Checks if this validation cycle is a default one, either specific to a Study or defined in the configuration workflow or
- * built-in.<br/>
- * Default validation cycle are not attached to any document type. As for built-in ones, they doesn't include any validation step
- * other than Promotion.
- * 
- * @return true if this validation cycle is a default one.
- * @see    #getDocumentType()
- */
-    public boolean isDefault () {
-     return (mytype == null);
-    }
-
-    public ValidationCycleRelation getContext () {
-//  -----------------------------------------------
-      return context;
-    }
        /**
         * Set the publisher.
-        * @param publisher the publisher to set
+        * 
+        * @param publisher
+        *            the publisher to set
         */
        public void setPublisher(final User publisher) {
                this.publisher = publisher;
        }
+
        /**
         * Set the reviewer.
-        * @param reviewer the reviewer to set
+        * 
+        * @param reviewer
+        *            the reviewer to set
         */
        public void setReviewer(final User reviewer) {
                this.reviewer = reviewer;
        }
+
        /**
         * Set the approver.
-        * @param approver the approver to set
+        * 
+        * @param approver
+        *            the approver to set
         */
        public void setApprover(final User approver) {
                this.approver = approver;
        }
+
        /**
         * Set the signatory.
-        * @param signatory the signatory to set
+        * 
+        * @param signatory
+        *            the signatory to set
         */
        public void setSignatory(final User signatory) {
                this.signatory = signatory;