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.kernel.InvalidPropertyException;
13 import org.splat.kernel.MissedPropertyException;
14 import org.splat.kernel.MultiplyDefinedException;
15 import org.splat.service.technical.ProjectSettingsService;
18 public class DocumentType extends Persistent {
22 private ProgressState state;
23 private String step; // List of (dash separated) steps (numbers) containing this type
24 private String result; // Step (number ) having this type as result
25 private Set<DocumentType> uses;
27 // ==============================================================================================================================
29 // ==============================================================================================================================
31 // Fields initialization class
32 public static class Properties extends Persistent.Properties {
33 // ------------------------------------------------------------
34 private String name = null;
35 private String step = null;
36 private String result = null;
37 private DocumentType[] uses = null;
41 public void clear () {
48 // - Setters of DocumentType properties
50 public Properties setName (String name) throws InvalidPropertyException
52 if (name.length() == 0) throw new InvalidPropertyException("name");
56 public Properties setResult (ProjectSettingsService.Step step)
58 this.result = String.valueOf(step.getNumber());
61 public Properties setStep (ProjectSettingsService.Step... step)
64 for (int i=0; i<step.length; i++) this.step = this.step + String.valueOf(step[i].getNumber()) + "-";
67 public Properties setUses (DocumentType... type)
72 // - Global validity check
74 public void checkValidity() throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException
76 if (name == null) throw new MissedPropertyException("name");
77 if (step == null) throw new MissedPropertyException("path");
80 // Database fetch constructor
81 protected DocumentType () {
82 // -------------------------
84 // Initialization constructor
85 public DocumentType (Properties dprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException {
86 // -----------------------------------------
87 super(dprop); // Throws one of the above exception if not valid
89 state = ProgressState.inCHECK;
91 result = dprop.result; // May be null
92 uses = new HashSet<DocumentType>();
93 if (dprop.uses != null) for (int i=0; i<dprop.uses.length; i++) uses.add(dprop.uses[i]);
96 // ==============================================================================================================================
97 // Public member functions
98 // ==============================================================================================================================
100 public boolean equals(Object entity) {
101 // ------------------------------------
102 if (entity == null) return false;
103 if (entity instanceof String) {
104 return this.name.equals((String)entity); // Names are unique
106 if (entity instanceof DocumentType) {
107 DocumentType object = (DocumentType)entity;
108 long he = object.getIndex();
109 long me = this.getIndex();
110 if (me*he != 0) return (he == me);
111 else return this.getName().equals(object.getName());
117 public String getName () {
118 // ------------------------
122 public Set<DocumentType> getDefaultUses () {
123 // -------------------------------------------
127 public boolean isApproved () {
128 // ----------------------------
129 return (state == ProgressState.APPROVED);
133 * Checks if documents of this type are attached to the given study step, either as result or content.
135 * @param step the involved study step
136 * @return true if documents of this type are attached to the given step.
137 * @see #isResultOf(org.splat.service.technical.ProjectSettingsServiceImpl.Step)
139 public boolean isContentInto (ProjectSettingsService.Step step) {
140 // --------------------------------------------------------
141 String[] path = this.step.split("-");
142 for (int i=0; i<path.length; i++) {
143 String value = path[i];
144 if (value.length() == 0) continue;
145 if (Integer.valueOf(value) == step.getNumber()) return true;
151 * Checks if documents of this type are result of any study step.
153 * @return true if documents of this type are result of a step.
154 * @see #isStudyResult()
155 * @see #isResultOf(org.splat.service.technical.ProjectSettingsServiceImpl.Step)
157 public boolean isStepResult () {
158 // ------------------------------
159 return (result != null);
163 * Checks if documents of this type are result of the given study step.
165 * @param step the involved study step
166 * @return true if documents of this type are result of the given step.
167 * @see #isContentInto(org.splat.service.technical.ProjectSettingsServiceImpl.Step)
168 * @see #isStepResult()
169 * @see #isStudyResult()
171 public boolean isResultOf (ProjectSettingsService.Step step) {
172 // -----------------------------------------------------
173 if (result == null) return false;
174 return (Integer.valueOf(result) == step.getNumber());
181 public ProgressState getState() {
186 * @param state the state to set
188 public void setState(ProgressState state) {