]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman-Common/src/org/splat/dal/bo/som/DocumentType.java
Salome HOME
More business logic has been moved from BO to services. ServiceLocator is created...
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / dal / bo / som / DocumentType.java
1 package org.splat.dal.bo.som;
2 /**
3  * 
4  * @author    Daniel Brunier-Coulin
5  * @copyright OPEN CASCADE 2012
6  */
7
8 import java.util.Set;
9 import java.util.HashSet;
10
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;
17
18
19 public class DocumentType extends Persistent {
20         
21 //  Persistent fields
22     private String            name;
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;
27
28 //  ==============================================================================================================================
29 //  Construction
30 //  ==============================================================================================================================
31
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;
39
40 //  - Public services
41
42       public void clear () {
43         super.clear();
44         name    = null;
45         step    = null;
46         result  = null;
47         uses    = null;
48       }
49 //  - Setters of DocumentType properties
50       
51       public Properties setName (String name) throws InvalidPropertyException
52       {
53         if (name.length() == 0) throw new InvalidPropertyException("name");
54         this.name = name;
55         return this;
56       }
57       public Properties setResult (ProjectSettingsService.Step step)
58       {
59         this.result = String.valueOf(step.getNumber());
60         return this;
61       }
62       public Properties setStep (ProjectSettingsService.Step... step)
63       {
64         this.step = "-";
65         for (int i=0; i<step.length; i++) this.step = this.step + String.valueOf(step[i].getNumber()) + "-";
66         return this;
67       }
68       public Properties setUses (DocumentType... type)
69       {
70         this.uses = type;
71         return this;
72       }
73 //  - Global validity check
74         
75       public void checkValidity() throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException
76       {
77         if (name == null)  throw new MissedPropertyException("name");
78         if (step == null)  throw new MissedPropertyException("path");
79       }
80     }
81 //  Database fetch constructor
82     protected DocumentType () {
83 //  -------------------------
84     }
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
89       name   = dprop.name;
90       state  = ProgressState.inCHECK;
91       step   = dprop.step;
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]);
95     }
96
97 //  ==============================================================================================================================
98 //  Public member functions
99 //  ==============================================================================================================================
100
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);
106           return true;
107     }
108
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
114       } else
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());
121       } else {
122         return false;
123       }
124     }
125
126     public String getName () {
127 //  ------------------------
128       return name;
129     }
130
131     public Set<DocumentType> getDefaultUses () {
132 //  -------------------------------------------
133       return uses;
134     }
135
136     public boolean isApproved () {
137 //  ----------------------------
138       return (state == ProgressState.APPROVED);
139     }
140
141 /**
142  * Checks if documents of this type are attached to the given study step, either as result or content.
143  * 
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)
147  */
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;
155       }
156       return false;
157     }
158
159 /**
160  * Checks if documents of this type are result of any study step.
161  * 
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)
165  */
166     public boolean isStepResult () {
167 //  ------------------------------
168       return (result != null);
169     }
170
171 /**
172  * Checks if documents of this type are result of the given study step.
173  * 
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()
179  */
180     public boolean isResultOf (ProjectSettingsService.Step step) {
181 //  -----------------------------------------------------
182       if (result == null) return false;
183       return (Integer.valueOf(result) == step.getNumber());
184     }
185 }