1 package org.splat.dal.bo.som;
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.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;
41 public class ValidationCycle extends Persistent {
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
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
57 // ==============================================================================================================================
59 // ==============================================================================================================================
61 // Fields initialization class
62 public static class Properties extends Persistent.Properties {
63 // ------------------------------------------------------------
64 DocumentType doctype = null;
65 User publisher = null;
68 User signatory = null;
72 public void clear () {
80 // - Protected services
82 public Properties setDocumentType (DocumentType type)
87 // - Properties setter
89 public Properties setActor (ValidationStep step, User actor)
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;
97 // - Global validity check
99 public void checkValidity() throws MissedPropertyException
101 if (doctype == null) throw new MissedPropertyException("type");
104 // Database fetch constructor
105 protected ValidationCycle () {
107 // Internal constructors
108 protected ValidationCycle (Study from, ProjectSettingsServiceImpl.ProjectSettingsValidationCycle cycle) {
109 // -----------------------------------------------------------------------------
110 Actor[] actype = cycle.getActorTypes();
111 User.Properties uprop = new User.Properties();
113 mytype = Document.selectType(cycle.getName()); // Null in case of default validation cycle
114 // context = new ValidationCycleRelation(from, this);
115 context = null; // Validation cycle defined in the workflow
116 for (int i=0; i<actype.length; i++) {
118 if (actype[i] != null)
120 if (actype[i] == Actor.manager) {
121 actor = from.getAuthor();
123 if (actype[i] == Actor.Nx1) {
124 List<User> manager = UserDirectory.selectUsersWhere(uprop.setOrganizationName("Nx1"));
125 if (manager.size() == 1) actor = manager.get(0);
127 if (actype[i] == Actor.Nx2) {
128 List<User> manager = UserDirectory.selectUsersWhere(uprop.setOrganizationName("Nx2"));
129 if (manager.size() == 1) actor = manager.get(0);
130 } else { /* Actor.customer */
131 actor = from.getAuthor();
132 //TODO: Get the customer of the study, if exists
134 } catch (Exception e) { // Should not happen
137 if (i == 0) reviewer = actor;
138 else if (i == 1) approver = actor;
139 else if (i == 2) signatory = actor;
142 public ValidationCycle (Study from, Properties vprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException {
143 // --------------------------------------------------------
144 super(vprop); // Throws one of the above exception if not valid
145 mytype = vprop.doctype;
146 publisher = vprop.publisher; // May be null
147 reviewer = vprop.reviewer; // May be null
148 approver = vprop.approver; // May be null
149 signatory = vprop.signatory; // May be null
150 context = new ValidationCycleRelation(from, this);
153 // ==============================================================================================================================
154 // Public member functions
155 // ==============================================================================================================================
157 * Checks if a given validation step is enabled in this validation cycle.
159 * @param step the validation step checked.
160 * @return true if the given validation step is enabled.
162 public boolean enables (ValidationStep step) {
163 // -------------------------------------------
164 if (step == ValidationStep.PROMOTION) return true;
165 else if (step == ValidationStep.REVIEW) return (reviewer != null);
166 else if (step == ValidationStep.APPROVAL) return (approver != null);
167 else if (step == ValidationStep.ACCEPTANCE || step == ValidationStep.REFUSAL) return (signatory != null);
172 * Returns the user involved in a given step of this document validation cycle.
173 * When enabled, the Review and Approval steps have one explicit actor returned by this function. On the other hand,
174 * Promotion and Acceptance have default actors - they respectively are the author of the document or the responsible of study,
175 * and the customer or its representative internal user. In this context, a null user is returned.
177 * @param step the validation step
178 * @return the user involved by the given step or null if the step is disabled or the actors are the default ones
179 * @see #getAllActors()
182 public User getActor (ValidationStep step) {
183 // -----------------------------------------
184 if (step == ValidationStep.PROMOTION) return publisher;
185 else if (step == ValidationStep.REVIEW) return reviewer;
186 else if (step == ValidationStep.APPROVAL) return approver;
187 else if (step == ValidationStep.ACCEPTANCE || step == ValidationStep.REFUSAL) return signatory;
192 * Returns all explicit actors of this document validation cycle, that is, actors of enabled validation cycles, excluding
193 * the default actors.
195 * @return the users explicitly involved by the steps of this validation cycle
196 * @see #getActor(ValidationStep)
197 * @see #enables(ValidationStep)
199 public User[] getAllActors () {
200 // -----------------------------
201 Vector<User> result = new Vector<User>();
202 if (publisher != null) result.add(publisher);
203 if (reviewer != null) result.add(reviewer);
204 if (approver != null) result.add(approver);
205 if (signatory != null) result.add(signatory);
206 return result.toArray(new User[result.size()]);
210 * Return the document type to which this validation cycle applies. If this validation cycle is a default one, the document
211 * type is not defined.
213 * @return the document type involved by this validation cycle, or null if this validation cycle is a default one.
216 public DocumentType getDocumentType () {
217 // --------------------------------------
218 return mytype; // May be null
222 * 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 * @return true if this validation cycle is assigned to a study.
227 public boolean isAssigned () {
228 // ----------------------------
229 return (context != null);
233 * Checks if this validation cycle is a default one, either specific to a Study or defined in the configuration workflow or
235 * Default validation cycle are not attached to any document type. As for built-in ones, they doesn't include any validation step
236 * other than Promotion.
238 * @return true if this validation cycle is a default one.
239 * @see #getDocumentType()
240 * @see ProjectSettingsServiceImpl#getNewValidationCycle()
242 public boolean isDefault () {
243 // ---------------------------
244 return (mytype == null);
247 // ==============================================================================================================================
248 // Protected services
249 // ==============================================================================================================================
251 public ValidationCycleRelation getContext () {
252 // -----------------------------------------------
256 protected void remove (ValidationStep step) {
257 // ------------------------------------------
258 if (step == ValidationStep.REVIEW) reviewer = null;
259 else if (step == ValidationStep.APPROVAL) approver = null;
260 else if (step == ValidationStep.ACCEPTANCE || step == ValidationStep.REFUSAL) signatory = null;
261 if (this.isSaved()) Database.getSession().update(this);
264 public void resetActors (Properties vprop) {
265 // ---------------------------------------------
266 publisher = vprop.publisher; // May be null
267 reviewer = vprop.reviewer; // May be null
268 approver = vprop.approver; // May be null
269 signatory = vprop.signatory; // May be null
270 if (this.isSaved()) Database.getSession().update(this);
273 protected void setActor (ValidationStep step, User actor) {
274 // --------------------------------------------------------
275 if (step == ValidationStep.PROMOTION) publisher = actor;
276 else if (step == ValidationStep.REVIEW) reviewer = actor;
277 else if (step == ValidationStep.APPROVAL) approver = actor;
278 else if (step == ValidationStep.ACCEPTANCE || step == ValidationStep.REFUSAL) signatory = actor;
279 if (this.isSaved()) Database.getSession().update(this);