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);
154 * Create a copy of the given cycle for the given study.
155 * @param study the owner study
156 * @param src the original validation cycle
158 public ValidationCycle (final Study study, final ValidationCycle src) {
159 super(); // Throws one of the above exception if not valid
160 mytype = src.getDocumentType();
161 publisher = src.publisher; // May be null
162 reviewer = src.reviewer; // May be null
163 approver = src.approver; // May be null
164 signatory = src.signatory; // May be null
165 context = new ValidationCycleRelation(study, this);
168 // ==============================================================================================================================
169 // Public member functions
170 // ==============================================================================================================================
172 * Checks if a given validation step is enabled in this validation cycle.
174 * @param step the validation step checked.
175 * @return true if the given validation step is enabled.
177 public boolean enables (final ValidationStep step) {
178 if (step == ValidationStep.PROMOTION) {
180 } else if (step == ValidationStep.REVIEW) {
181 return (reviewer != null);
182 } else if (step == ValidationStep.APPROVAL) {
183 return (approver != null);
184 } else if (step == ValidationStep.ACCEPTANCE || step == ValidationStep.REFUSAL) {
185 return (signatory != null);
191 * Returns the user involved in a given step of this document validation cycle.
192 * When enabled, the Review and Approval steps have one explicit actor returned by this function. On the other hand,
193 * Promotion and Acceptance have default actors - they respectively are the author of the document or the responsible of study,
194 * and the customer or its representative internal user. In this context, a null user is returned.
196 * @param step the validation step
197 * @return the user involved by the given step or null if the step is disabled or the actors are the default ones
198 * @see #getAllActors()
201 public User getActor (final ValidationStep step) {
202 if (step == ValidationStep.PROMOTION) {
204 } else if (step == ValidationStep.REVIEW) {
206 } else if (step == ValidationStep.APPROVAL) {
208 } else if (step == ValidationStep.ACCEPTANCE || step == ValidationStep.REFUSAL) {
215 * Returns all explicit actors of this document validation cycle, that is, actors of enabled validation cycles, excluding
216 * the default actors.
218 * @return the users explicitly involved by the steps of this validation cycle
219 * @see #getActor(ValidationStep)
220 * @see #enables(ValidationStep)
222 public User[] getAllActors () {
223 // -----------------------------
224 Vector<User> result = new Vector<User>();
225 if (publisher != null) {
226 result.add(publisher);
228 if (reviewer != null) {
229 result.add(reviewer);
231 if (approver != null) {
232 result.add(approver);
234 if (signatory != null) {
235 result.add(signatory);
237 return result.toArray(new User[result.size()]);
241 * Return the document type to which this validation cycle applies. If this validation cycle is a default one, the document
242 * type is not defined.
244 * @return the document type involved by this validation cycle, or null if this validation cycle is a default one.
247 public DocumentType getDocumentType () {
248 return mytype; // May be null
252 * Set a document type for the validation cycle.
253 * @param aType the document type
255 public void setDocumentType (final DocumentType aType) {
256 mytype = aType; // May be null
260 * 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
263 * @return true if this validation cycle is assigned to a study.
265 public boolean isAssigned () {
266 return (context != null);
270 * Checks if this validation cycle is a default one, either specific to a Study or defined in the configuration workflow or
272 * Default validation cycle are not attached to any document type. As for built-in ones, they doesn't include any validation step
273 * other than Promotion.
275 * @return true if this validation cycle is a default one.
276 * @see #getDocumentType()
278 public boolean isDefault () {
279 return (mytype == null);
282 public ValidationCycleRelation getContext () {
283 // -----------------------------------------------
288 * @param publisher the publisher to set
290 public void setPublisher(final User publisher) {
291 this.publisher = publisher;
295 * @param reviewer the reviewer to set
297 public void setReviewer(final User reviewer) {
298 this.reviewer = reviewer;
302 * @param approver the approver to set
304 public void setApprover(final User approver) {
305 this.approver = approver;
309 * @param signatory the signatory to set
311 public void setSignatory(final User signatory) {
312 this.signatory = signatory;