]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman-Common/src/org/splat/som/Step.java
Salome HOME
Modifications done to respect PMD rules. Versioning a document is fixed. Validation...
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / som / Step.java
1 package org.splat.som;
2
3 /**
4  * 
5  * @author    Daniel Brunier-Coulin
6  * @copyright OPEN CASCADE 2012
7  */
8
9 import java.util.ArrayList;
10 import java.util.Collections;
11 import java.util.Iterator;
12 import java.util.List;
13
14 import org.splat.dal.bo.kernel.User;
15 import org.splat.dal.bo.som.Document;
16 import org.splat.dal.bo.som.DocumentType;
17 import org.splat.dal.bo.som.KnowledgeElement;
18 import org.splat.dal.bo.som.ProgressState;
19 import org.splat.dal.bo.som.ProjectElement;
20 import org.splat.dal.bo.som.Publication;
21 import org.splat.dal.bo.som.Scenario;
22 import org.splat.dal.bo.som.SimulationContext;
23 import org.splat.dal.bo.som.SimulationContextType;
24 import org.splat.dal.bo.som.Study;
25 import org.splat.service.technical.ProjectSettingsService;
26
27 public class Step {
28
29         private transient final ProjectSettingsService.Step _step;
30         private transient final ProjectElement _owner;
31         private transient final List<SimulationContext> _contex;
32         private transient final List<Publication> _docums;
33         private User _actor; // Actor involved in operations on published documents and requiring a time-stamp
34
35         // ==============================================================================================================================
36         // Constructor
37         // ==============================================================================================================================
38
39         public Step(final ProjectSettingsService.Step step,
40                         final ProjectElement owner) {
41                 this._step = step;
42                 this._owner = owner;
43                 this._contex = new ArrayList<SimulationContext>();
44                 this._docums = new ArrayList<Publication>();
45                 this._actor = null;
46
47                 // Filtering of Simulation contexts, if exist
48                 for (Iterator<SimulationContext> i = owner.SimulationContextIterator(); i
49                                 .hasNext();) {
50                         SimulationContext adoc = i.next();
51                         if (!adoc.isInto(this)) {
52                                 continue;
53                         }
54                         this._contex.add(adoc);
55                 }
56                 // Filtering of Documents, if exist
57                 for (Iterator<Publication> i = owner.PublicationIterator(); i.hasNext();) {
58                         Publication mydoc = i.next();
59                         if (!mydoc.value().isInto(this)) {
60                                 continue;
61                         }
62                         mydoc.setStep(this); //RKV
63                         this._docums.add(mydoc);
64                 }
65         }
66
67         // ==============================================================================================================================
68         // Public member functions
69         // ==============================================================================================================================
70
71         public User getActor() {
72                 return _actor;
73         }
74
75         public List<Publication> getAllDocuments() {
76                 return Collections.unmodifiableList(_docums);
77         }
78
79         /**
80          * Get the persistent collection of step documents.
81          * 
82          * @return the list of documents
83          */
84         public List<Publication> getDocuments() {
85                 return _docums;
86         }
87
88         public List<SimulationContext> getAllSimulationContexts() {
89                 return Collections.unmodifiableList(_contex);
90         }
91
92         public Publication getDocument(final long docId) {
93                 for (Iterator<Publication> i = _docums.iterator(); i.hasNext();) {
94                         Publication found = i.next(); // In a given study step,
95                         if (found.value().getIndex() == docId) {
96                                 return found; // there is only one publication of a given document
97                         }
98                 }
99                 return null;
100         }
101
102         public int getNumber() {
103                 return _step.getNumber();
104         }
105
106         public ProjectElement getOwner() {
107                 return _owner; // May be a Study or a Scenario
108         }
109
110         public Study getOwnerStudy() {
111                 if (_owner instanceof Study) {
112                         return (Study) _owner;
113                 } else {
114                         return ((Scenario) _owner).getOwnerStudy();
115                 }
116         }
117
118         public String getPath() {
119                 return _step.getPath();
120         }
121
122         public List<Publication> getResultDocuments() {
123                 List<Publication> result = new ArrayList<Publication>();
124
125                 if (!_docums.isEmpty()) {
126                         for (Iterator<Publication> i = _docums.iterator(); i.hasNext();) {
127                                 Publication content = i.next();
128                                 DocumentType type = content.value().getType();
129                                 if (!type.isResultOf(this.getStep())) {
130                                         continue;
131                                 }
132                                 result.add(content);
133                         }
134                 }
135                 return result;
136         }
137
138         public ProjectSettingsService.Step getStep() {
139                 return _step;
140         }
141
142         public SimulationContext getSimulationContext(final long l) {
143                 for (Iterator<SimulationContext> i = _owner.SimulationContextIterator(); i
144                                 .hasNext();) {
145                         SimulationContext myctex = i.next();
146                         if (myctex.getIndex() == l) {
147                                 return myctex;
148                         }
149                 }
150                 return null;
151         }
152
153         public List<SimulationContext> getSimulationContext(
154                         final SimulationContextType type) {
155                 List<SimulationContext> result = new ArrayList<SimulationContext>();
156
157                 for (Iterator<SimulationContext> i = _owner.SimulationContextIterator(); i
158                                 .hasNext();) {
159                         SimulationContext myctex = i.next();
160                         if (myctex.getType().equals(type)) {
161                                 result.add(myctex);
162                         }
163                 }
164                 return result;
165         }
166
167         public boolean isStarted() {
168                 boolean res = _step.mayContain(KnowledgeElement.class);
169                 if (res) {
170                         List<KnowledgeElement> kelm = ((Scenario) _owner)
171                                         .getAllKnowledgeElements();
172                         res = (!kelm.isEmpty() || !_docums.isEmpty());
173                 } else {
174                         res = (!_docums.isEmpty());
175                 }
176                 return res;
177         }
178
179         public boolean isFinished() {
180                 if (_step.mayContain(KnowledgeElement.class)) { // Check if all result documents are approved
181                         List<KnowledgeElement> kelm = ((Scenario) _owner)
182                                         .getAllKnowledgeElements();
183                         if (kelm.isEmpty()) {
184                                 return false;
185                         }
186                         for (Iterator<KnowledgeElement> i = kelm.iterator(); i.hasNext();) {
187                                 KnowledgeElement content = i.next();
188                                 if (content.getProgressState() != ProgressState.APPROVED) {
189                                         return false;
190                                 }
191                         }
192                         return true;
193                 } else { // Check if all existing knowledges are approved
194                         if (_docums.isEmpty()) {
195                                 return false;
196                         }
197                         boolean result = false;
198                         for (Iterator<Publication> i = _docums.iterator(); i.hasNext();) {
199                                 Document content = i.next().value();
200                                 DocumentType type = content.getType();
201                                 if (!type.isResultOf(this.getStep())) {
202                                         continue;
203                                 }
204                                 if (content.getProgressState() == ProgressState.EXTERN) {
205                                         continue;
206                                 }
207                                 result = true; // There is at least 1 non external result document
208                                 if (content.getProgressState() != ProgressState.APPROVED) {
209                                         return false;
210                                 }
211                         }
212                         return result;
213                 }
214         }
215
216         @SuppressWarnings("unchecked")
217         public boolean mayContain(final Class type) {
218                 return _step.mayContain(type);
219         }
220
221         public void setActor(final User user) {
222                 _actor = user;
223         }
224
225         public List<SimulationContext> getContex() {
226                 return _contex;
227         }
228
229 }