5 * @author Daniel Brunier-Coulin
6 * @copyright OPEN CASCADE 2012
9 import java.util.Collections;
10 import java.util.List;
11 import java.util.Vector;
12 import java.util.Iterator;
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;
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
35 // ==============================================================================================================================
37 // ==============================================================================================================================
39 public Step(ProjectSettingsService.Step step, ProjectElement owner) {
40 // ----------------------------------------------------------------
43 this.contex = new Vector<SimulationContext>();
44 this.docums = new Vector<Publication>();
47 // Filtering of Simulation contexts, if exist
48 for (Iterator<SimulationContext> i = owner.SimulationContextIterator(); i
50 SimulationContext adoc = i.next();
51 if (!adoc.isInto(this))
53 this.contex.add(adoc);
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))
60 this.docums.add(mydoc);
64 // ==============================================================================================================================
65 // Public member functions
66 // ==============================================================================================================================
68 public User getActor() {
69 // -----------------------
73 public List<Publication> getAllDocuments() {
74 // -------------------------------------------
75 return Collections.unmodifiableList(docums);
79 * Get the persistent collection of step documents.
80 * @return the list of documents
82 public List<Publication> getDocuments() {
86 public List<SimulationContext> getAllSimulationContexts() {
87 // ----------------------------------------------------------
88 return Collections.unmodifiableList(contex);
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
101 public int getNumber() {
102 // -----------------------
103 return step.getNumber();
106 public ProjectElement getOwner() {
107 // ---------------------------------
108 return owner; // May be a Study or a Scenario
111 public Study getOwnerStudy() {
112 // -----------------------------
113 if (owner instanceof Study)
114 return (Study) owner;
116 return ((Scenario) owner).getOwnerStudy();
119 public String getPath() {
120 // ------------------------
121 return step.getPath();
124 public List<Publication> getResultDocuments() {
125 // ----------------------------------------------
126 List<Publication> result = new Vector<Publication>();
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()))
139 public ProjectSettingsService.Step getStep() {
140 // --------------------------------------
144 public SimulationContext getSimulationContext(long l) {
145 // ---------------------------------------------------------
146 for (Iterator<SimulationContext> i = owner.SimulationContextIterator(); i
148 SimulationContext myctex = i.next();
149 if (myctex.getIndex() == l)
155 public List<SimulationContext> getSimulationContext(
156 SimulationContextType type) {
157 // --------------------------------------------------------------------------------
158 Vector<SimulationContext> result = new Vector<SimulationContext>();
160 for (Iterator<SimulationContext> i = owner.SimulationContextIterator(); i
162 SimulationContext myctex = i.next();
163 if (myctex.getType().equals(type))
169 public boolean isStarted() {
170 // ---------------------------
171 if (!step.mayContain(KnowledgeElement.class))
172 return !docums.isEmpty();
174 List<KnowledgeElement> kelm = ((Scenario) owner)
175 .getAllKnowledgeElements();
176 if (kelm.isEmpty() && docums.isEmpty())
181 public boolean isFinished() {
182 // ----------------------------
183 if (!step.mayContain(KnowledgeElement.class)) { // Check if all result documents are approved
184 if (docums.isEmpty())
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()))
192 if (content.getProgressState() == ProgressState.EXTERN)
194 result = true; // There is at least 1 non external result document
195 if (content.getProgressState() != ProgressState.APPROVED)
199 } else { // Check if all existing knowledges are approved
200 List<KnowledgeElement> kelm = ((Scenario) owner)
201 .getAllKnowledgeElements();
204 for (Iterator<KnowledgeElement> i = kelm.iterator(); i.hasNext();) {
205 KnowledgeElement content = i.next();
206 if (content.getProgressState() != ProgressState.APPROVED)
213 public boolean mayContain(@SuppressWarnings("rawtypes")
215 return step.mayContain(type);
218 public void setActor(User user) {
222 public List<SimulationContext> getContex() {