1 package org.splat.dal.bo.som;
5 * @author Daniel Brunier-Coulin
6 * @copyright OPEN CASCADE 2012
9 import java.util.Arrays;
10 import java.util.HashSet;
13 import org.splat.dal.bo.kernel.Persistent;
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;
20 * Persistent document type.
22 public class DocumentType extends Persistent {
30 * Type progress state.
32 private ProgressState state;
34 * List of (dash separated) steps (numbers) containing this type.
38 * Step (number) having this type as result.
40 private String result;
42 * Set of "parent" document types, which are used by this type.
44 private final Set<DocumentType> uses = new HashSet<DocumentType>();
46 // ==============================================================================================================================
48 // ==============================================================================================================================
51 * Fields initialization class.
53 public static class Properties extends Persistent.Properties {
57 * @see DocumentType#name
59 private String name = null;
63 * @see DocumentType#step
65 private String step = null;
69 * @see DocumentType#result
71 private String result = null;
75 * @see DocumentType#uses
77 private DocumentType[] uses = null;
84 * @see org.splat.dal.bo.kernel.Persistent.Properties#clear()
95 // - Setters of DocumentType properties
97 public Properties setName(final String name)
98 throws InvalidPropertyException {
99 if (name.length() == 0) {
100 throw new InvalidPropertyException("name");
106 public Properties setResult(final ProjectSettingsService.Step step) {
107 this.result = String.valueOf(step.getNumber());
111 public Properties setStep(final ProjectSettingsService.Step... step) {
113 for (int i = 0; i < step.length; i++) {
114 this.step = this.step + String.valueOf(step[i].getNumber())
120 public Properties setUses(final DocumentType... type) {
125 // - Global validity check
127 public void checkValidity() throws MissedPropertyException,
128 InvalidPropertyException, MultiplyDefinedException {
130 throw new MissedPropertyException("name");
133 throw new MissedPropertyException("path");
142 public String getName() {
148 * Database fetch constructor.
150 protected DocumentType() {
155 * Initialization constructor.
159 * @throws MissedPropertyException
160 * if some mandatory property is missed
161 * @throws InvalidPropertyException
162 * if some property has invalid value
163 * @throws MultiplyDefinedException
164 * if some property is defined several times
166 public DocumentType(final Properties dprop) throws MissedPropertyException,
167 InvalidPropertyException, MultiplyDefinedException {
168 super(dprop); // Throws one of the above exception if not valid
170 state = ProgressState.inCHECK;
172 result = dprop.result; // May be null
173 if (dprop.uses != null) {
174 for (int i = 0; i < dprop.uses.length; i++) {
175 getUses().add(dprop.uses[i]);
180 // ==============================================================================================================================
181 // Public member functions
182 // ==============================================================================================================================
185 public boolean equals(final Object entity) {
186 if (entity == null) {
189 if (entity instanceof String) {
190 return this.name.equals(entity); // Names are unique
191 } else if (entity instanceof DocumentType) {
192 DocumentType object = (DocumentType) entity;
193 long he = object.getIndex();
194 long me = this.getIndex();
196 return this.getName().equals(object.getName());
205 public String getName() {
209 public Set<DocumentType> getDefaultUses() {
213 public boolean isApproved() {
214 return (state == ProgressState.APPROVED);
218 * Checks if documents of this type are attached to the given study step, either as result or content.
221 * the involved study step
222 * @return true if documents of this type are attached to the given step.
223 * @see #isResultOf(org.splat.service.technical.ProjectSettingsServiceImpl.Step)
225 public boolean isContentInto(final ProjectSettingsService.Step step) {
226 String[] path = this.step.split("-");
227 for (int i = 0; i < path.length; i++) {
228 String value = path[i];
229 if (value.length() == 0) {
232 if (Integer.valueOf(value) == step.getNumber()) {
240 * Checks if documents of this type are result of any study step.
242 * @return true if documents of this type are result of a step.
243 * @see #isStudyResult()
244 * @see #isResultOf(org.splat.service.technical.ProjectSettingsServiceImpl.Step)
246 public boolean isStepResult() {
247 return (result != null);
251 * Checks if documents of this type are result of the given study step.
254 * the involved study step
255 * @return true if documents of this type are result of the given step.
256 * @see #isContentInto(org.splat.service.technical.ProjectSettingsServiceImpl.Step)
257 * @see #isStepResult()
258 * @see #isStudyResult()
260 public boolean isResultOf(final ProjectSettingsService.Step step) {
261 if (result == null) {
264 return (Integer.valueOf(result) == step.getNumber());
272 public ProgressState getState() {
282 public void setState(final ProgressState state) {
291 protected Set<DocumentType> getUses() {
296 * Set properties of document type except persistent id and name.
301 public void setProperties(final Properties tprop) {
302 this.step = tprop.step;
303 this.result = tprop.result;
305 this.uses.addAll(Arrays.asList(tprop.uses));