1 package org.splat.dal.bo.som;
4 * @author Daniel Brunier-Coulin
5 * @copyright OPEN CASCADE 2012
8 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 final Set<DocumentType> uses = new HashSet<DocumentType>();
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;
42 public void clear () {
49 // - Setters of DocumentType properties
51 public Properties setName (final String name) throws InvalidPropertyException
53 if (name.length() == 0) {
54 throw new InvalidPropertyException("name");
59 public Properties setResult (final ProjectSettingsService.Step step)
61 this.result = String.valueOf(step.getNumber());
64 public Properties setStep (final ProjectSettingsService.Step... step)
67 for (int i=0; i<step.length; i++) {
68 this.step = this.step + String.valueOf(step[i].getNumber()) + "-";
72 public Properties setUses (final DocumentType... type)
77 // - Global validity check
79 public void checkValidity() throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException
82 throw new MissedPropertyException("name");
85 throw new MissedPropertyException("path");
89 // Database fetch constructor
90 protected DocumentType () {
91 // -------------------------
93 // Initialization constructor
94 public DocumentType (final Properties dprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException {
95 // -----------------------------------------
96 super(dprop); // Throws one of the above exception if not valid
98 state = ProgressState.inCHECK;
100 result = dprop.result; // May be null
101 if (dprop.uses != null) {
102 for (int i=0; i<dprop.uses.length; i++) {
103 getUses().add(dprop.uses[i]);
108 // ==============================================================================================================================
109 // Public member functions
110 // ==============================================================================================================================
113 public boolean equals(final Object entity) {
114 // ------------------------------------
115 if (entity == null) {
118 if (entity instanceof String) {
119 return this.name.equals(entity); // Names are unique
120 } else if (entity instanceof DocumentType) {
121 DocumentType object = (DocumentType)entity;
122 long he = object.getIndex();
123 long me = this.getIndex();
127 return this.getName().equals(object.getName());
134 public String getName () {
135 // ------------------------
139 public Set<DocumentType> getDefaultUses () {
140 // -------------------------------------------
144 public boolean isApproved () {
145 // ----------------------------
146 return (state == ProgressState.APPROVED);
150 * Checks if documents of this type are attached to the given study step, either as result or content.
152 * @param step the involved study step
153 * @return true if documents of this type are attached to the given step.
154 * @see #isResultOf(org.splat.service.technical.ProjectSettingsServiceImpl.Step)
156 public boolean isContentInto (final ProjectSettingsService.Step step) {
157 // --------------------------------------------------------
158 String[] path = this.step.split("-");
159 for (int i=0; i<path.length; i++) {
160 String value = path[i];
161 if (value.length() == 0) {
164 if (Integer.valueOf(value) == step.getNumber()) {
172 * Checks if documents of this type are result of any study step.
174 * @return true if documents of this type are result of a step.
175 * @see #isStudyResult()
176 * @see #isResultOf(org.splat.service.technical.ProjectSettingsServiceImpl.Step)
178 public boolean isStepResult () {
179 // ------------------------------
180 return (result != null);
184 * Checks if documents of this type are result of the given study step.
186 * @param step the involved study step
187 * @return true if documents of this type are result of the given step.
188 * @see #isContentInto(org.splat.service.technical.ProjectSettingsServiceImpl.Step)
189 * @see #isStepResult()
190 * @see #isStudyResult()
192 public boolean isResultOf (final ProjectSettingsService.Step step) {
193 // -----------------------------------------------------
194 if (result == null) {
197 return (Integer.valueOf(result) == step.getNumber());
204 public ProgressState getState() {
209 * @param state the state to set
211 public void setState(final ProgressState state) {
218 protected Set<DocumentType> getUses() {