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