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
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:
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>
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/>
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/>
22 * @see Study#addValidationCycle(DocumentType,Properties)
23 * @see Study#getValidationCycleOf(DocumentType)
25 * @author Daniel Brunier-Coulin
26 * @copyright OPEN CASCADE 2012
29 import java.util.List;
30 import java.util.Vector;
32 import org.splat.kernel.InvalidPropertyException;
33 import org.splat.kernel.MissedPropertyException;
34 import org.splat.kernel.MultiplyDefinedException;
35 import org.splat.kernel.Persistent;
36 import org.splat.kernel.User;
37 import org.splat.kernel.UserDirectory;
39 public class ValidationCycle extends Persistent {
41 private ValidationCycleRelation context;
42 private DocumentType mytype; // Null if the referenced validation cycle is a default one
43 private User publisher;
44 private User reviewer; // Null if no REVIEW validation step
45 private User approver; // Null if no APPROVAL validation step
46 private User signatory; // Null if no ACCEPTANCE validation step
49 manager, // Responsible of study
50 Nx1, // N+1 manager of the responsible of study
51 Nx2, // N+2 manager of the responsible of study
55 // ==============================================================================================================================
57 // ==============================================================================================================================
59 // Fields initialization class
60 public static class Properties extends Persistent.Properties {
61 // ------------------------------------------------------------
62 DocumentType doctype = null;
63 User publisher = null;
66 User signatory = null;
70 public void clear () {
78 // - Protected services
80 protected Properties setDocumentType (DocumentType type)
85 // - Properties setter
87 public Properties setActor (ValidationStep step, User actor)
89 if (step == ValidationStep.PROMOTION) publisher = actor;
90 else if (step == ValidationStep.REVIEW) reviewer = actor;
91 else if (step == ValidationStep.APPROVAL) approver = actor;
92 else if (step == ValidationStep.ACCEPTANCE || step == ValidationStep.REFUSAL) signatory = actor;
95 // - Global validity check
97 public void checkValidity() throws MissedPropertyException
99 if (doctype == null) throw new MissedPropertyException("type");
102 // Database fetch constructor
103 protected ValidationCycle () {
105 // Internal constructors
106 protected ValidationCycle (Study from, ProjectSettings.ValidationCycle cycle) {
107 // -----------------------------------------------------------------------------
108 Actor[] actype = cycle.getActorTypes();
109 User.Properties uprop = new User.Properties();
111 mytype = Document.selectType(cycle.getName()); // Null in case of default validation cycle
112 // context = new ValidationCycleRelation(from, this);
113 context = null; // Validation cycle defined in the workflow
114 for (int i=0; i<actype.length; i++) {
116 if (actype[i] != null)
118 if (actype[i] == Actor.manager) {
119 actor = from.getAuthor();
121 if (actype[i] == Actor.Nx1) {
122 List<User> manager = UserDirectory.selectUsersWhere(uprop.setOrganizationName("Nx1"));
123 if (manager.size() == 1) actor = manager.get(0);
125 if (actype[i] == Actor.Nx2) {
126 List<User> manager = UserDirectory.selectUsersWhere(uprop.setOrganizationName("Nx2"));
127 if (manager.size() == 1) actor = manager.get(0);
128 } else { /* Actor.customer */
129 actor = from.getAuthor();
130 //TODO: Get the customer of the study, if exists
132 } catch (Exception e) { // Should not happen
135 if (i == 0) reviewer = actor;
136 else if (i == 1) approver = actor;
137 else if (i == 2) signatory = actor;
140 protected ValidationCycle (Study from, Properties vprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException {
141 // --------------------------------------------------------
142 super(vprop); // Throws one of the above exception if not valid
143 mytype = vprop.doctype;
144 publisher = vprop.publisher; // May be null
145 reviewer = vprop.reviewer; // May be null
146 approver = vprop.approver; // May be null
147 signatory = vprop.signatory; // May be null
148 context = new ValidationCycleRelation(from, this);
151 // ==============================================================================================================================
152 // Public member functions
153 // ==============================================================================================================================
155 * Checks if a given validation step is enabled in this validation cycle.
157 * @param step the validation step checked.
158 * @return true if the given validation step is enabled.
160 public boolean enables (ValidationStep step) {
161 // -------------------------------------------
162 if (step == ValidationStep.PROMOTION) return true;
163 else if (step == ValidationStep.REVIEW) return (reviewer != null);
164 else if (step == ValidationStep.APPROVAL) return (approver != null);
165 else if (step == ValidationStep.ACCEPTANCE || step == ValidationStep.REFUSAL) return (signatory != null);
170 * Returns the user involved in a given step of this document validation cycle.
171 * When enabled, the Review and Approval steps have one explicit actor returned by this function. On the other hand,
172 * Promotion and Acceptance have default actors - they respectively are the author of the document or the responsible of study,
173 * and the customer or its representative internal user. In this context, a null user is returned.
175 * @param step the validation step
176 * @return the user involved by the given step or null if the step is disabled or the actors are the default ones
177 * @see #getAllActors()
180 public User getActor (ValidationStep step) {
181 // -----------------------------------------
182 if (step == ValidationStep.PROMOTION) return publisher;
183 else if (step == ValidationStep.REVIEW) return reviewer;
184 else if (step == ValidationStep.APPROVAL) return approver;
185 else if (step == ValidationStep.ACCEPTANCE || step == ValidationStep.REFUSAL) return signatory;
190 * Returns all explicit actors of this document validation cycle, that is, actors of enabled validation cycles, excluding
191 * the default actors.
193 * @return the users explicitly involved by the steps of this validation cycle
194 * @see #getActor(ValidationStep)
195 * @see #enables(ValidationStep)
197 public User[] getAllActors () {
198 // -----------------------------
199 Vector<User> result = new Vector<User>();
200 if (publisher != null) result.add(publisher);
201 if (reviewer != null) result.add(reviewer);
202 if (approver != null) result.add(approver);
203 if (signatory != null) result.add(signatory);
204 return result.toArray(new User[result.size()]);
208 * Return the document type to which this validation cycle applies. If this validation cycle is a default one, the document
209 * type is not defined.
211 * @return the document type involved by this validation cycle, or null if this validation cycle is a default one.
214 public DocumentType getDocumentType () {
215 // --------------------------------------
216 return mytype; // May be null
220 * 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
223 * @return true if this validation cycle is assigned to a study.
225 public boolean isAssigned () {
226 // ----------------------------
227 return (context != null);
231 * Checks if this validation cycle is a default one, either specific to a Study or defined in the configuration workflow or
233 * Default validation cycle are not attached to any document type. As for built-in ones, they doesn't include any validation step
234 * other than Promotion.
236 * @return true if this validation cycle is a default one.
237 * @see #getDocumentType()
238 * @see ProjectSettings#getNewValidationCycle()
240 public boolean isDefault () {
241 // ---------------------------
242 return (mytype == null);
245 // ==============================================================================================================================
246 // Protected services
247 // ==============================================================================================================================
249 protected ValidationCycleRelation getContext () {
250 // -----------------------------------------------
254 protected void remove (ValidationStep step) {
255 // ------------------------------------------
256 if (step == ValidationStep.REVIEW) reviewer = null;
257 else if (step == ValidationStep.APPROVAL) approver = null;
258 else if (step == ValidationStep.ACCEPTANCE || step == ValidationStep.REFUSAL) signatory = null;
259 if (this.isSaved()) Database.getSession().update(this);
262 protected void resetActors (Properties vprop) {
263 // ---------------------------------------------
264 publisher = vprop.publisher; // May be null
265 reviewer = vprop.reviewer; // May be null
266 approver = vprop.approver; // May be null
267 signatory = vprop.signatory; // May be null
268 if (this.isSaved()) Database.getSession().update(this);
271 protected void setActor (ValidationStep step, User actor) {
272 // --------------------------------------------------------
273 if (step == ValidationStep.PROMOTION) publisher = actor;
274 else if (step == ValidationStep.REVIEW) reviewer = actor;
275 else if (step == ValidationStep.APPROVAL) approver = actor;
276 else if (step == ValidationStep.ACCEPTANCE || step == ValidationStep.REFUSAL) signatory = actor;
277 if (this.isSaved()) Database.getSession().update(this);