1 package org.splat.dal.bo.som;
4 * @author Daniel Brunier-Coulin
5 * @copyright OPEN CASCADE 2012
9 import java.util.HashSet;
11 import org.splat.dal.bo.kernel.Persistent;
12 import org.splat.dal.dao.som.Database;
13 import org.splat.kernel.InvalidPropertyException;
14 import org.splat.kernel.MissedPropertyException;
15 import org.splat.kernel.MultiplyDefinedException;
16 import org.splat.service.technical.ProjectSettingsService;
19 public class DocumentType extends Persistent {
23 private ProgressState state;
24 private String step; // List of (dash separated) steps (numbers) containing this type
25 private String result; // Step (number ) having this type as result
26 private Set<DocumentType> uses;
28 // ==============================================================================================================================
30 // ==============================================================================================================================
32 // Fields initialization class
33 public static class Properties extends Persistent.Properties {
34 // ------------------------------------------------------------
35 private String name = null;
36 private String step = null;
37 private String result = null;
38 private DocumentType[] uses = null;
42 public void clear () {
49 // - Setters of DocumentType properties
51 public Properties setName (String name) throws InvalidPropertyException
53 if (name.length() == 0) throw new InvalidPropertyException("name");
57 public Properties setResult (ProjectSettingsService.Step step)
59 this.result = String.valueOf(step.getNumber());
62 public Properties setStep (ProjectSettingsService.Step... step)
65 for (int i=0; i<step.length; i++) this.step = this.step + String.valueOf(step[i].getNumber()) + "-";
68 public Properties setUses (DocumentType... type)
73 // - Global validity check
75 public void checkValidity() throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException
77 if (name == null) throw new MissedPropertyException("name");
78 if (step == null) throw new MissedPropertyException("path");
81 // Database fetch constructor
82 protected DocumentType () {
83 // -------------------------
85 // Initialization constructor
86 public DocumentType (Properties dprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException {
87 // -----------------------------------------
88 super(dprop); // Throws one of the above exception if not valid
90 state = ProgressState.inCHECK;
92 result = dprop.result; // May be null
93 uses = new HashSet<DocumentType>();
94 if (dprop.uses != null) for (int i=0; i<dprop.uses.length; i++) uses.add(dprop.uses[i]);
97 // ==============================================================================================================================
98 // Public member functions
99 // ==============================================================================================================================
101 public boolean approve () {
102 // -------------------------
103 if (state != ProgressState.inCHECK) return false;
104 this.state = ProgressState.APPROVED; // The type name is supposed being localized
105 Database.getSession().update(this);
109 public boolean equals(Object entity) {
110 // ------------------------------------
111 if (entity == null) return false;
112 if (entity instanceof String) {
113 return this.name.equals((String)entity); // Names are unique
115 if (entity instanceof DocumentType) {
116 DocumentType object = (DocumentType)entity;
117 long he = object.getIndex();
118 long me = this.getIndex();
119 if (me*he != 0) return (he == me);
120 else return this.getName().equals(object.getName());
126 public String getName () {
127 // ------------------------
131 public Set<DocumentType> getDefaultUses () {
132 // -------------------------------------------
136 public boolean isApproved () {
137 // ----------------------------
138 return (state == ProgressState.APPROVED);
142 * Checks if documents of this type are attached to the given study step, either as result or content.
144 * @param step the involved study step
145 * @return true if documents of this type are attached to the given step.
146 * @see #isResultOf(org.splat.service.technical.ProjectSettingsServiceImpl.Step)
148 public boolean isContentInto (ProjectSettingsService.Step step) {
149 // --------------------------------------------------------
150 String[] path = this.step.split("-");
151 for (int i=0; i<path.length; i++) {
152 String value = path[i];
153 if (value.length() == 0) continue;
154 if (Integer.valueOf(value) == step.getNumber()) return true;
160 * Checks if documents of this type are result of any study step.
162 * @return true if documents of this type are result of a step.
163 * @see #isStudyResult()
164 * @see #isResultOf(org.splat.service.technical.ProjectSettingsServiceImpl.Step)
166 public boolean isStepResult () {
167 // ------------------------------
168 return (result != null);
172 * Checks if documents of this type are result of the given study step.
174 * @param step the involved study step
175 * @return true if documents of this type are result of the given step.
176 * @see #isContentInto(org.splat.service.technical.ProjectSettingsServiceImpl.Step)
177 * @see #isStepResult()
178 * @see #isStudyResult()
180 public boolean isResultOf (ProjectSettingsService.Step step) {
181 // -----------------------------------------------------
182 if (result == null) return false;
183 return (Integer.valueOf(result) == step.getNumber());