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.Vector;
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;
37 public class ValidationCycle extends Persistent {
39 private ValidationCycleRelation context;
40 private DocumentType mytype; // Null if the referenced validation cycle is a default one
41 private User publisher;
42 private User reviewer; // Null if no REVIEW validation step
43 private User approver; // Null if no APPROVAL validation step
44 private User signatory; // Null if no ACCEPTANCE validation step
47 manager, // Responsible of study
48 Nx1, // N+1 manager of the responsible of study
49 Nx2, // N+2 manager of the responsible of study
53 // ==============================================================================================================================
55 // ==============================================================================================================================
57 // Fields initialization class
58 public static class Properties extends Persistent.Properties {
59 // ------------------------------------------------------------
60 DocumentType doctype = null;
61 User publisher = null;
64 User signatory = null;
69 public void clear () {
77 // - Protected services
79 public Properties setDocumentType (final DocumentType type)
84 // - Properties setter
86 public Properties setActor (final ValidationStep step, final User actor)
88 if (step == ValidationStep.PROMOTION) {
90 } else if (step == ValidationStep.REVIEW) {
92 } else if (step == ValidationStep.APPROVAL) {
94 } else if (step == ValidationStep.ACCEPTANCE || step == ValidationStep.REFUSAL) {
99 // - Global validity check
101 public void checkValidity() throws MissedPropertyException
103 if (doctype == null) {
104 throw new MissedPropertyException("type");
110 * @return the publisher
112 public User getPublisher() {
118 * @return the reviewer
120 public User getReviewer() {
126 * @return the approver
128 public User getApprover() {
134 * @return the signatory
136 public User getSignatory() {
140 // Database fetch constructor
141 public ValidationCycle () {
143 public ValidationCycle (final Study from, final Properties vprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException {
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 (final ValidationStep step) {
163 if (step == ValidationStep.PROMOTION) {
165 } else if (step == ValidationStep.REVIEW) {
166 return (reviewer != null);
167 } else if (step == ValidationStep.APPROVAL) {
168 return (approver != null);
169 } else if (step == ValidationStep.ACCEPTANCE || step == ValidationStep.REFUSAL) {
170 return (signatory != null);
176 * Returns the user involved in a given step of this document validation cycle.
177 * When enabled, the Review and Approval steps have one explicit actor returned by this function. On the other hand,
178 * Promotion and Acceptance have default actors - they respectively are the author of the document or the responsible of study,
179 * and the customer or its representative internal user. In this context, a null user is returned.
181 * @param step the validation step
182 * @return the user involved by the given step or null if the step is disabled or the actors are the default ones
183 * @see #getAllActors()
186 public User getActor (final ValidationStep step) {
187 if (step == ValidationStep.PROMOTION) {
189 } else if (step == ValidationStep.REVIEW) {
191 } else if (step == ValidationStep.APPROVAL) {
193 } else if (step == ValidationStep.ACCEPTANCE || step == ValidationStep.REFUSAL) {
200 * Returns all explicit actors of this document validation cycle, that is, actors of enabled validation cycles, excluding
201 * the default actors.
203 * @return the users explicitly involved by the steps of this validation cycle
204 * @see #getActor(ValidationStep)
205 * @see #enables(ValidationStep)
207 public User[] getAllActors () {
208 // -----------------------------
209 Vector<User> result = new Vector<User>();
210 if (publisher != null) {
211 result.add(publisher);
213 if (reviewer != null) {
214 result.add(reviewer);
216 if (approver != null) {
217 result.add(approver);
219 if (signatory != null) {
220 result.add(signatory);
222 return result.toArray(new User[result.size()]);
226 * Return the document type to which this validation cycle applies. If this validation cycle is a default one, the document
227 * type is not defined.
229 * @return the document type involved by this validation cycle, or null if this validation cycle is a default one.
232 public DocumentType getDocumentType () {
233 return mytype; // May be null
237 * Set a document type for the validation cycle.
238 * @param aType the document type
240 public void setDocumentType (final DocumentType aType) {
241 mytype = aType; // May be null
245 * 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
248 * @return true if this validation cycle is assigned to a study.
250 public boolean isAssigned () {
251 return (context != null);
255 * Checks if this validation cycle is a default one, either specific to a Study or defined in the configuration workflow or
257 * Default validation cycle are not attached to any document type. As for built-in ones, they doesn't include any validation step
258 * other than Promotion.
260 * @return true if this validation cycle is a default one.
261 * @see #getDocumentType()
263 public boolean isDefault () {
264 return (mytype == null);
267 public ValidationCycleRelation getContext () {
268 // -----------------------------------------------
273 * @param publisher the publisher to set
275 public void setPublisher(final User publisher) {
276 this.publisher = publisher;
280 * @param reviewer the reviewer to set
282 public void setReviewer(final User reviewer) {
283 this.reviewer = reviewer;
287 * @param approver the approver to set
289 public void setApprover(final User approver) {
290 this.approver = approver;
294 * @param signatory the signatory to set
296 public void setSignatory(final User signatory) {
297 this.signatory = signatory;