1 package org.splat.dal.bo.som;
4 * Class defining the validation cycle applicable to documents of a given type.<br/>
5 * A validation cycle specifies the validation steps of documents complying with by this cycle, as well as the actors
6 * involved in such validations. Once past, each validation step is written down by a time-stamp attached to the validated
9 * The possible validation steps are Promotion, Review, Approval and Acceptance (or Refusal), all being optional,
10 * except Promotion.<br/>
11 * When enabled, Review and Approval involve one given user while Promotion and Acceptance have default actors defined by
12 * the application. The default actors are:
14 * <li>Promotion by either the author of the document or the responsible of study</li>
15 * <li>Acceptance by the customer, possibly represented by an internal user</li>
17 * Explicit Promotion and Acceptance actors can be defined, for example to force some documents to be published by the
18 * responsible of study only.<br/>
20 * Default validation cycles are defined in the configuration workflow, the responsible of studies overriding them when necessary.
21 * They are attached to studies at a given document type.<br/>
23 * @see Study#addValidationCycle(DocumentType,Properties)
24 * @see Study#getValidationCycleOf(DocumentType)
26 * @author Daniel Brunier-Coulin
27 * @copyright OPEN CASCADE 2012-2015
30 import java.util.ArrayList;
31 import java.util.List;
33 import org.splat.dal.bo.kernel.Persistent;
34 import org.splat.dal.bo.kernel.User;
35 import org.splat.kernel.InvalidPropertyException;
36 import org.splat.kernel.MissedPropertyException;
37 import org.splat.kernel.MultiplyDefinedException;
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
56 // ==============================================================================================================================
58 // ==============================================================================================================================
60 // Fields initialization class
61 public static class Properties extends Persistent.Properties {
62 DocumentType doctype = null;
63 User publisher = null;
66 User signatory = null;
80 // - Protected services
82 public Properties setDocumentType(final DocumentType type) {
87 // - Properties setter
89 public Properties setActor(final ValidationStep step, final User actor) {
90 if (step == ValidationStep.PROMOTION) {
92 } else if (step == ValidationStep.REVIEW) {
94 } else if (step == ValidationStep.APPROVAL) {
96 } else if (step == ValidationStep.ACCEPTANCE
97 || step == ValidationStep.REFUSAL) {
103 // - Global validity check
105 public void checkValidity() throws MissedPropertyException {
106 if (doctype == null) {
107 throw new MissedPropertyException("type");
114 * @return the publisher
116 public User getPublisher() {
123 * @return the reviewer
125 public User getReviewer() {
132 * @return the approver
134 public User getApprover() {
141 * @return the signatory
143 public User getSignatory() {
148 // Database fetch constructor
149 public ValidationCycle() {
153 public ValidationCycle(final Study from, final Properties vprop)
154 throws MissedPropertyException, InvalidPropertyException,
155 MultiplyDefinedException {
156 super(vprop); // Throws one of the above exception if not valid
157 mytype = vprop.doctype;
158 publisher = vprop.publisher; // May be null
159 reviewer = vprop.reviewer; // May be null
160 approver = vprop.approver; // May be null
161 signatory = vprop.signatory; // May be null
162 context = new ValidationCycleRelation(from, this);
166 * Create a copy of the given cycle for the given study.
170 * @return the cloned validation cycle
172 public ValidationCycle clone(final Study study) {
173 ValidationCycle res = new ValidationCycle();
174 res.mytype = this.mytype;
175 res.publisher = this.publisher; // May be null
176 res.reviewer = this.reviewer; // May be null
177 res.approver = this.approver; // May be null
178 res.signatory = this.signatory; // May be null
179 res.context = new ValidationCycleRelation(study, res);
183 // ==============================================================================================================================
184 // Public member functions
185 // ==============================================================================================================================
187 * Checks if a given validation step is enabled in this validation cycle.
190 * the validation step checked.
191 * @return true if the given validation step is enabled.
193 public boolean enables(final ValidationStep step) {
195 if (step == ValidationStep.PROMOTION) {
197 } else if (step == ValidationStep.REVIEW) {
198 res = (reviewer != null);
199 } else if (step == ValidationStep.APPROVAL) {
200 res = (approver != null);
201 } else if (step == ValidationStep.ACCEPTANCE
202 || step == ValidationStep.REFUSAL) {
203 res = (signatory != null);
209 * Returns the user involved in a given step of this document validation cycle. When enabled, the Review and Approval steps have one
210 * explicit actor returned by this function. On the other hand, Promotion and Acceptance have default actors - they respectively are the
211 * author of the document or the responsible of study, and the customer or its representative internal user. In this context, a null
215 * the validation step
216 * @return the user involved by the given step or null if the step is disabled or the actors are the default ones
217 * @see #getAllActors()
220 public User getActor(final ValidationStep step) {
222 if (step == ValidationStep.PROMOTION) {
224 } else if (step == ValidationStep.REVIEW) {
226 } else if (step == ValidationStep.APPROVAL) {
228 } else if (step == ValidationStep.ACCEPTANCE
229 || step == ValidationStep.REFUSAL) {
236 * Returns all explicit actors of this document validation cycle, that is, actors of enabled validation cycles, excluding the default
239 * @return the users explicitly involved by the steps of this validation cycle
240 * @see #getActor(ValidationStep)
241 * @see #enables(ValidationStep)
243 public User[] getAllActors() {
244 List<User> result = new ArrayList<User>();
245 if (publisher != null) {
246 result.add(publisher);
248 if (reviewer != null) {
249 result.add(reviewer);
251 if (approver != null) {
252 result.add(approver);
254 if (signatory != null) {
255 result.add(signatory);
257 return result.toArray(new User[result.size()]);
261 * Return the document type to which this validation cycle applies. If this validation cycle is a default one, the document type is not
264 * @return the document type involved by this validation cycle, or null if this validation cycle is a default one.
267 public DocumentType getDocumentType() {
268 return mytype; // May be null
272 * Set a document type for the validation cycle.
277 public void setDocumentType(final DocumentType aType) {
278 mytype = aType; // May be null
282 * 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 been
285 * @return true if this validation cycle is assigned to a study.
287 public boolean isAssigned() {
288 return (context != null);
292 * Checks if this validation cycle is a default one, either specific to a Study or defined in the configuration workflow or built-in.<br/>
293 * Default validation cycle are not attached to any document type. As for built-in ones, they doesn't include any validation step other
296 * @return true if this validation cycle is a default one.
297 * @see #getDocumentType()
299 public boolean isDefault() {
300 return (mytype == null);
303 public ValidationCycleRelation getContext() {
311 * the publisher to set
313 public void setPublisher(final User publisher) {
314 this.publisher = publisher;
321 * the reviewer to set
323 public void setReviewer(final User reviewer) {
324 this.reviewer = reviewer;
331 * the approver to set
333 public void setApprover(final User approver) {
334 this.approver = approver;
341 * the signatory to set
343 public void setSignatory(final User signatory) {
344 this.signatory = signatory;