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");
106 * @return the publisher
108 public User getPublisher() {
114 * @return the reviewer
116 public User getReviewer() {
122 * @return the approver
124 public User getApprover() {
130 * @return the signatory
132 public User getSignatory() {
136 // Database fetch constructor
137 public ValidationCycle () {
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);
150 // ==============================================================================================================================
151 // Public member functions
152 // ==============================================================================================================================
154 * Checks if a given validation step is enabled in this validation cycle.
156 * @param step the validation step checked.
157 * @return true if the given validation step is enabled.
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);
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.
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()
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;
189 * Returns all explicit actors of this document validation cycle, that is, actors of enabled validation cycles, excluding
190 * the default actors.
192 * @return the users explicitly involved by the steps of this validation cycle
193 * @see #getActor(ValidationStep)
194 * @see #enables(ValidationStep)
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()]);
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.
210 * @return the document type involved by this validation cycle, or null if this validation cycle is a default one.
213 public DocumentType getDocumentType () {
214 // --------------------------------------
215 return mytype; // May be null
219 * Set a document type for the validation cycle.
220 * @param aType the document type
222 public void setDocumentType (DocumentType aType) {
223 mytype = aType; // May be null
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
230 * @return true if this validation cycle is assigned to a study.
232 public boolean isAssigned () {
233 // ----------------------------
234 return (context != null);
238 * Checks if this validation cycle is a default one, either specific to a Study or defined in the configuration workflow or
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.
243 * @return true if this validation cycle is a default one.
244 * @see #getDocumentType()
245 * @see ProjectSettingsServiceImpl#getNewValidationCycle()
247 public boolean isDefault () {
248 // ---------------------------
249 return (mytype == null);
252 // ==============================================================================================================================
253 // Protected services
254 // ==============================================================================================================================
256 public ValidationCycleRelation getContext () {
257 // -----------------------------------------------
262 * @param publisher the publisher to set
264 public void setPublisher(User publisher) {
265 this.publisher = publisher;
269 * @param reviewer the reviewer to set
271 public void setReviewer(User reviewer) {
272 this.reviewer = reviewer;
276 * @param approver the approver to set
278 public void setApprover(User approver) {
279 this.approver = approver;
283 * @param signatory the signatory to set
285 public void setSignatory(User signatory) {
286 this.signatory = signatory;