1 package org.splat.dal.bo.som;
4 * @author Daniel Brunier-Coulin
5 * @copyright OPEN CASCADE 2012
10 import java.util.HashSet;
12 import org.splat.dal.bo.kernel.Persistent;
13 import org.splat.dal.dao.som.Database;
14 import org.splat.kernel.InvalidPropertyException;
15 import org.splat.kernel.MissedPropertyException;
16 import org.splat.kernel.MultiplyDefinedException;
17 import org.splat.service.technical.ProjectSettingsService;
18 import org.splat.service.technical.ProjectSettingsService.Step;
21 public class DocumentType extends Persistent {
25 private ProgressState state;
26 private String step; // List of (dash separated) steps (numbers) containing this type
27 private String result; // Step (number ) having this type as result
28 private Set<DocumentType> uses;
30 // ==============================================================================================================================
32 // ==============================================================================================================================
34 // Fields initialization class
35 public static class Properties extends Persistent.Properties {
36 // ------------------------------------------------------------
37 private String name = null;
38 private String step = null;
39 private String result = null;
40 private DocumentType[] uses = null;
44 public void clear () {
51 // - Setters of DocumentType properties
53 public Properties setName (String name) throws InvalidPropertyException
55 if (name.length() == 0) throw new InvalidPropertyException("name");
59 public Properties setResult (ProjectSettingsService.Step step)
61 this.result = String.valueOf(step.getNumber());
64 public Properties setStep (ProjectSettingsService.Step... step)
67 for (int i=0; i<step.length; i++) this.step = this.step + String.valueOf(step[i].getNumber()) + "-";
70 public Properties setUses (DocumentType... type)
75 // - Global validity check
77 public void checkValidity() throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException
79 if (name == null) throw new MissedPropertyException("name");
80 if (step == null) throw new MissedPropertyException("path");
83 // Database fetch constructor
84 protected DocumentType () {
85 // -------------------------
87 // Initialization constructor
88 protected DocumentType (Properties dprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException {
89 // -----------------------------------------
90 super(dprop); // Throws one of the above exception if not valid
92 state = ProgressState.inCHECK;
94 result = dprop.result; // May be null
95 uses = new HashSet<DocumentType>();
96 if (dprop.uses != null) for (int i=0; i<dprop.uses.length; i++) uses.add(dprop.uses[i]);
99 // ==============================================================================================================================
100 // Public member functions
101 // ==============================================================================================================================
103 public boolean approve () {
104 // -------------------------
105 if (state != ProgressState.inCHECK) return false;
106 this.state = ProgressState.APPROVED; // The type name is supposed being localized
107 Database.getSession().update(this);
111 public boolean equals(Object entity) {
112 // ------------------------------------
113 if (entity == null) return false;
114 if (entity instanceof String) {
115 return this.name.equals((String)entity); // Names are unique
117 if (entity instanceof DocumentType) {
118 DocumentType object = (DocumentType)entity;
119 int he = object.getIndex();
120 int me = this.getIndex();
121 if (me*he != 0) return (he == me);
122 else return this.getName().equals(object.getName());
128 public String getName () {
129 // ------------------------
133 public Set<DocumentType> getDefaultUses () {
134 // -------------------------------------------
138 public boolean isApproved () {
139 // ----------------------------
140 return (state == ProgressState.APPROVED);
144 * Checks if documents of this type are attached to the given study step, either as result or content.
146 * @param step the involved study step
147 * @return true if documents of this type are attached to the given step.
148 * @see #isResultOf(org.splat.service.technical.ProjectSettingsServiceImpl.Step)
150 public boolean isContentInto (ProjectSettingsService.Step step) {
151 // --------------------------------------------------------
152 String[] path = this.step.split("-");
153 for (int i=0; i<path.length; i++) {
154 String value = path[i];
155 if (value.length() == 0) continue;
156 if (Integer.valueOf(value) == step.getNumber()) return true;
162 * Checks if documents of this type are result of any study step.
164 * @return true if documents of this type are result of a step.
165 * @see #isStudyResult()
166 * @see #isResultOf(org.splat.service.technical.ProjectSettingsServiceImpl.Step)
168 public boolean isStepResult () {
169 // ------------------------------
170 return (result != null);
174 * Checks if documents of this type are result of the given study step.
176 * @param step the involved study step
177 * @return true if documents of this type are result of the given step.
178 * @see #isContentInto(org.splat.service.technical.ProjectSettingsServiceImpl.Step)
179 * @see #isStepResult()
180 * @see #isStudyResult()
182 public boolean isResultOf (ProjectSettingsService.Step step) {
183 // -----------------------------------------------------
184 if (result == null) return false;
185 return (Integer.valueOf(result) == step.getNumber());