Salome HOME
Unused imports are removed.
[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.Collections;
10 import java.util.List;
11 import java.util.Vector;
12 import java.util.Iterator;
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 ProjectSettingsService.Step step;
30         private ProjectElement owner;
31         private List<SimulationContext> contex;
32         private 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(ProjectSettingsService.Step step, ProjectElement owner) {
40                 // ----------------------------------------------------------------
41                 this.step = step;
42                 this.owner = owner;
43                 this.contex = new Vector<SimulationContext>();
44                 this.docums = new Vector<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                         this.contex.add(adoc);
54                 }
55                 // Filtering of Documents, if exist
56                 for (Iterator<Publication> i = owner.PublicationIterator(); i.hasNext();) {
57                         Publication mydoc = i.next();
58                         if (!mydoc.value().isInto(this))
59                                 continue;
60                         this.docums.add(mydoc);
61                 }
62         }
63
64         // ==============================================================================================================================
65         // Public member functions
66         // ==============================================================================================================================
67
68         public User getActor() {
69                 // -----------------------
70                 return actor;
71         }
72
73         public List<Publication> getAllDocuments() {
74                 // -------------------------------------------
75                 return Collections.unmodifiableList(docums);
76         }
77
78         /**
79          * Get the persistent collection of step documents.
80          * @return the list of documents
81          */
82         public List<Publication> getDocuments() {
83                 return docums;
84         }
85
86         public List<SimulationContext> getAllSimulationContexts() {
87                 // ----------------------------------------------------------
88                 return Collections.unmodifiableList(contex);
89         }
90
91         public Publication getDocument(long l) {
92                 // ------------------------------------------
93                 for (Iterator<Publication> i = docums.iterator(); i.hasNext();) {
94                         Publication found = i.next(); // In a given study step,
95                         if (found.value().getIndex() == l)
96                                 return found; // there is only one publication of a given document
97                 }
98                 return null;
99         }
100
101         public int getNumber() {
102                 // -----------------------
103                 return step.getNumber();
104         }
105
106         public ProjectElement getOwner() {
107                 // ---------------------------------
108                 return owner; // May be a Study or a Scenario
109         }
110
111         public Study getOwnerStudy() {
112                 // -----------------------------
113                 if (owner instanceof Study)
114                         return (Study) owner;
115                 else
116                         return ((Scenario) owner).getOwnerStudy();
117         }
118
119         public String getPath() {
120                 // ------------------------
121                 return step.getPath();
122         }
123
124         public List<Publication> getResultDocuments() {
125                 // ----------------------------------------------
126                 List<Publication> result = new Vector<Publication>();
127
128                 if (!docums.isEmpty())
129                         for (Iterator<Publication> i = docums.iterator(); i.hasNext();) {
130                                 Publication content = i.next();
131                                 DocumentType type = content.value().getType();
132                                 if (!type.isResultOf(this.getStep()))
133                                         continue;
134                                 result.add(content);
135                         }
136                 return result;
137         }
138
139         public ProjectSettingsService.Step getStep() {
140                 // --------------------------------------
141                 return step;
142         }
143
144         public SimulationContext getSimulationContext(long l) {
145                 // ---------------------------------------------------------
146                 for (Iterator<SimulationContext> i = owner.SimulationContextIterator(); i
147                                 .hasNext();) {
148                         SimulationContext myctex = i.next();
149                         if (myctex.getIndex() == l)
150                                 return myctex;
151                 }
152                 return null;
153         }
154
155         public List<SimulationContext> getSimulationContext(
156                         SimulationContextType type) {
157                 // --------------------------------------------------------------------------------
158                 Vector<SimulationContext> result = new Vector<SimulationContext>();
159
160                 for (Iterator<SimulationContext> i = owner.SimulationContextIterator(); i
161                                 .hasNext();) {
162                         SimulationContext myctex = i.next();
163                         if (myctex.getType().equals(type))
164                                 result.add(myctex);
165                 }
166                 return result;
167         }
168
169         public boolean isStarted() {
170                 // ---------------------------
171                 if (!step.mayContain(KnowledgeElement.class))
172                         return !docums.isEmpty();
173
174                 List<KnowledgeElement> kelm = ((Scenario) owner)
175                                 .getAllKnowledgeElements();
176                 if (kelm.isEmpty() && docums.isEmpty())
177                         return false;
178                 return true;
179         }
180
181         public boolean isFinished() {
182                 // ----------------------------
183                 if (!step.mayContain(KnowledgeElement.class)) { // Check if all result documents are approved
184                         if (docums.isEmpty())
185                                 return false;
186                         boolean result = false;
187                         for (Iterator<Publication> i = docums.iterator(); i.hasNext();) {
188                                 Document content = i.next().value();
189                                 DocumentType type = content.getType();
190                                 if (!type.isResultOf(this.getStep()))
191                                         continue;
192                                 if (content.getProgressState() == ProgressState.EXTERN)
193                                         continue;
194                                 result = true; // There is at least 1 non external result document
195                                 if (content.getProgressState() != ProgressState.APPROVED)
196                                         return false;
197                         }
198                         return result;
199                 } else { // Check if all existing knowledges are approved
200                         List<KnowledgeElement> kelm = ((Scenario) owner)
201                                         .getAllKnowledgeElements();
202                         if (kelm.isEmpty())
203                                 return false;
204                         for (Iterator<KnowledgeElement> i = kelm.iterator(); i.hasNext();) {
205                                 KnowledgeElement content = i.next();
206                                 if (content.getProgressState() != ProgressState.APPROVED)
207                                         return false;
208                         }
209                         return true;
210                 }
211         }
212
213         public boolean mayContain(@SuppressWarnings("rawtypes")
214         Class type) {
215                 return step.mayContain(type);
216         }
217
218         public void setActor(User user) {
219                 actor = user;
220         }
221
222         public List<SimulationContext> getContex() {
223                 return contex;
224         }
225
226 }