Salome HOME
Refactoring continues: UserService is created instead of UserDirectory. Database...
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / dal / bo / som / ValidationCycle.java
1 package org.splat.dal.bo.som;
2 /**
3  * Class defining the validation cycle applicable to documents of a given type.<br/>
4  * A validation cycle specifies the validation steps of documents complying with by this cycle, as well as the actors
5  * involved in such validations. Once past, each validation step is written down by a time-stamp attached to the validated
6  * document.<br/>
7  * <br/>
8  * The possible validation steps are Promotion, Review, Approval and Acceptance (or Refusal), all being optional,
9  * except Promotion.<br/>
10  * When enabled, Review and Approval involve one given user while Promotion and Acceptance have default actors defined by
11  * the application. The default actors are:
12  * <ul>
13  * <li>Promotion by either the author of the document or the responsible of study</li>
14  * <li>Acceptance by the customer, possibly represented by an internal user</li>
15  * </ul>
16  * Explicit Promotion and Acceptance actors can be defined, for example to force some documents to be published by the
17  * responsible of study only.<br/> 
18  * <br/>
19  * Default validation cycles are defined in the configuration workflow, the responsible of studies overriding them when necessary.
20  * They are attached to studies at a given document type.<br/>
21  * 
22  * @see Study#addValidationCycle(DocumentType,Properties)
23  * @see Study#getValidationCycleOf(DocumentType)
24  * @see Timestamp
25  * @author    Daniel Brunier-Coulin
26  * @copyright OPEN CASCADE 2012
27  */
28
29 import java.util.Vector;
30
31 import org.splat.dal.bo.kernel.Persistent;
32 import org.splat.dal.bo.kernel.User;
33 import org.splat.kernel.InvalidPropertyException;
34 import org.splat.kernel.MissedPropertyException;
35 import org.splat.kernel.MultiplyDefinedException;
36 import org.splat.service.technical.ProjectSettingsServiceImpl;
37
38 public class ValidationCycle extends Persistent {
39
40         private  ValidationCycleRelation context;
41     private  DocumentType            mytype;      // Null if the referenced validation cycle is a default one
42         private  User                    publisher;
43     private  User                    reviewer;    // Null if no REVIEW validation step
44     private  User                    approver;    // Null if no APPROVAL validation step
45     private  User                    signatory;   // Null if no ACCEPTANCE validation step
46
47     public enum Actor {
48       manager,                                    // Responsible of study 
49       Nx1,                                        // N+1 manager of the responsible of study
50       Nx2,                                        // N+2 manager of the responsible of study
51       customer                                    // Customer
52     }
53
54 //  ==============================================================================================================================
55 //  Construction
56 //  ==============================================================================================================================
57     
58 //  Fields initialization class
59     public static class Properties extends Persistent.Properties {
60 //  ------------------------------------------------------------
61       DocumentType doctype   = null;
62       User         publisher = null;
63       User         reviewer  = null;
64       User         approver  = null;
65       User         signatory = null;
66
67 //  - Public services
68
69       public void clear () {
70         super.clear();
71         doctype   = null;
72         publisher = null;
73         reviewer  = null;
74         approver  = null;
75         signatory = null;
76       }
77 //  - Protected services
78
79       public Properties setDocumentType (DocumentType type)
80       {
81         doctype = type;
82         return this;
83       }
84 //  - Properties setter
85
86       public Properties setActor (ValidationStep step, User actor)
87       {
88         if      (step == ValidationStep.PROMOTION) publisher = actor;
89         else if (step == ValidationStep.REVIEW)    reviewer  = actor;
90         else if (step == ValidationStep.APPROVAL)  approver  = actor;
91         else if (step == ValidationStep.ACCEPTANCE || step == ValidationStep.REFUSAL) signatory = actor;
92         return this;
93       }
94 //  - Global validity check
95         
96       public void checkValidity() throws MissedPropertyException
97       { 
98         if (doctype == null) throw new MissedPropertyException("type");
99       }
100
101         /**
102          * Get the publisher.
103          * @return the publisher
104          */
105         public User getPublisher() {
106                 return publisher;
107         }
108
109         /**
110          * Get the reviewer.
111          * @return the reviewer
112          */
113         public User getReviewer() {
114                 return reviewer;
115         }
116
117         /**
118          * Get the approver.
119          * @return the approver
120          */
121         public User getApprover() {
122                 return approver;
123         }
124
125         /**
126          * Get the signatory.
127          * @return the signatory
128          */
129         public User getSignatory() {
130                 return signatory;
131         }
132     }
133 //  Database fetch constructor
134     public ValidationCycle () {
135     }
136     public ValidationCycle (Study from, Properties vprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException {
137 //  --------------------------------------------------------
138       super(vprop);                  // Throws one of the above exception if not valid
139       mytype    = vprop.doctype;
140       publisher = vprop.publisher;   // May be null
141       reviewer  = vprop.reviewer;    // May be null
142       approver  = vprop.approver;    // May be null
143       signatory = vprop.signatory;   // May be null
144       context   = new ValidationCycleRelation(from, this);
145     }
146
147 //  ==============================================================================================================================
148 //  Public member functions
149 //  ==============================================================================================================================
150 /**
151  * Checks if a given validation step is enabled in this validation cycle.
152  * 
153  * @param  step the validation step checked.
154  * @return true if the given validation step is enabled.
155  */
156     public boolean enables (ValidationStep step) {
157 //  -------------------------------------------
158       if      (step == ValidationStep.PROMOTION) return true;
159       else if (step == ValidationStep.REVIEW)    return (reviewer  != null);
160       else if (step == ValidationStep.APPROVAL)  return (approver  != null);
161       else if (step == ValidationStep.ACCEPTANCE || step == ValidationStep.REFUSAL) return (signatory != null);
162       return false;
163     }
164
165 /**
166  * Returns the user involved in a given step of this document validation cycle.
167  * When enabled, the Review and Approval steps have one explicit actor returned by this function. On the other hand,
168  * Promotion and Acceptance have default actors - they respectively are the author of the document or the responsible of study,
169  * and the customer or its representative internal user. In this context, a null user is returned.
170  * 
171  * @param  step the validation step
172  * @return the user involved by the given step or null if the step is disabled or the actors are the default ones
173  * @see    #getAllActors()
174  * @see    #enables
175  */
176     public User getActor (ValidationStep step) {
177 //  -----------------------------------------
178       if      (step == ValidationStep.PROMOTION) return publisher;
179       else if (step == ValidationStep.REVIEW)    return reviewer;
180       else if (step == ValidationStep.APPROVAL)  return approver;
181       else if (step == ValidationStep.ACCEPTANCE || step == ValidationStep.REFUSAL) return signatory;
182       return null;
183     }
184
185 /**
186  * Returns all explicit actors of this document validation cycle, that is, actors of enabled validation cycles, excluding
187  * the default actors.
188  * 
189  * @return the users explicitly involved by the steps of this validation cycle
190  * @see    #getActor(ValidationStep)
191  * @see    #enables(ValidationStep)
192  */
193     public User[] getAllActors () {
194 //  -----------------------------
195       Vector<User> result = new Vector<User>();
196       if (publisher != null) result.add(publisher);
197       if (reviewer  != null) result.add(reviewer);
198       if (approver  != null) result.add(approver);
199       if (signatory != null) result.add(signatory);
200       return  result.toArray(new User[result.size()]);
201     }
202
203 /**
204  * Return the document type to which this validation cycle applies. If this validation cycle is a default one, the document
205  * type is not defined.
206  * 
207  * @return the document type involved by this validation cycle, or null if this validation cycle is a default one.
208  * @see    #isDefault()
209  */
210     public DocumentType getDocumentType () {
211     //  --------------------------------------
212           return mytype;                    // May be null
213         }
214
215     /**
216      * Set a document type for the validation cycle.
217      * @param aType the document type
218      */
219     public void setDocumentType (DocumentType aType) {
220           mytype = aType;                    // May be null
221     }
222
223 /**
224  * 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
225  * been defined.
226  * 
227  * @return true if this validation cycle is assigned to a study.
228  */
229     public boolean isAssigned () {
230 //  ----------------------------
231       return (context != null);
232     }
233
234 /**
235  * Checks if this validation cycle is a default one, either specific to a Study or defined in the configuration workflow or
236  * built-in.<br/>
237  * Default validation cycle are not attached to any document type. As for built-in ones, they doesn't include any validation step
238  * other than Promotion.
239  * 
240  * @return true if this validation cycle is a default one.
241  * @see    #getDocumentType()
242  * @see    ProjectSettingsServiceImpl#getNewValidationCycle()
243  */
244     public boolean isDefault () {
245 //  ---------------------------
246      return (mytype == null);
247     }
248
249 //  ==============================================================================================================================
250 //  Protected services
251 //  ==============================================================================================================================
252
253     public ValidationCycleRelation getContext () {
254 //  -----------------------------------------------
255       return context;
256     }
257         /**
258          * Set the publisher.
259          * @param publisher the publisher to set
260          */
261         public void setPublisher(User publisher) {
262                 this.publisher = publisher;
263         }
264         /**
265          * Set the reviewer.
266          * @param reviewer the reviewer to set
267          */
268         public void setReviewer(User reviewer) {
269                 this.reviewer = reviewer;
270         }
271         /**
272          * Set the approver.
273          * @param approver the approver to set
274          */
275         public void setApprover(User approver) {
276                 this.approver = approver;
277         }
278         /**
279          * Set the signatory.
280          * @param signatory the signatory to set
281          */
282         public void setSignatory(User signatory) {
283                 this.signatory = signatory;
284         }
285 }