5 * @author Daniel Brunier-Coulin
6 * @copyright OPEN CASCADE 2012-2015
9 import java.util.ArrayList;
10 import java.util.Collections;
11 import java.util.Iterator;
12 import java.util.List;
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;
28 * The activity (step) instance of a project element.
33 * The study workflow step presented by this step instance.
35 private transient final ProjectSettingsService.Step _step;
37 * The parent project element containing this step.
39 private transient final ProjectElement _owner;
41 * The list of applied simulation contexts.
43 private transient final List<SimulationContext> _contex;
45 * The list of documents publications of this step instance.
47 private transient final List<Publication> _docums;
49 * Actor involved in operations on published documents and requiring a time-stamp.
53 // =========================================================================
55 // =========================================================================
58 * The constructor of the study step instance.
61 * the study workflow step to instantiate
63 * the parent project element
65 public Step(final ProjectSettingsService.Step step,
66 final ProjectElement owner) {
69 this._contex = new ArrayList<SimulationContext>();
70 this._docums = new ArrayList<Publication>();
72 // Filtering of Simulation contexts, if exist
73 for (Iterator<SimulationContext> i = owner.SimulationContextIterator(); i
75 SimulationContext adoc = i.next();
76 if (adoc.isInto(this)) {
77 this._contex.add(adoc);
80 // Filtering of Documents, if exist
81 for (Iterator<Publication> i = owner.PublicationIterator(); i.hasNext();) {
82 Publication mydoc = i.next();
83 if (mydoc.value().isInto(this)) {
84 mydoc.setStep(this); // RKV
85 this._docums.add(mydoc);
90 // =========================================================================
91 // Public member functions
92 // =========================================================================
94 public User getActor() {
98 public List<Publication> getAllDocuments() {
99 return Collections.unmodifiableList(_docums);
103 * Get the persistent collection of step documents.
105 * @return the list of documents
107 public List<Publication> getDocuments() {
111 public List<SimulationContext> getAllSimulationContexts() {
112 return Collections.unmodifiableList(_contex);
116 * Get document publication or null if it is not published in this step.
120 * @return document publication or null if not published in this step
122 public Publication getDocument(final long docId) {
123 Publication found = null;
124 for (Publication pub : _docums) {
125 // In a given study step,
126 if (pub.value().getIndex() == docId) {
127 found = pub; // there is only one publication of a given document
137 * @return step number
139 public int getNumber() {
140 return _step.getNumber();
144 * Get step's parent project element.
146 * @return parent project element
148 public ProjectElement getOwner() {
149 return _owner; // May be a Study or a Scenario
155 * @return the parent study
157 public Study getOwnerStudy() {
158 return _owner.getOwnerStudy();
162 * Get data path for this step.
164 * @return the data path
166 public String getPath() {
167 return _step.getPath();
171 * Get all documents publications which are results of this step according to documents types.
173 * @return list of the step result documents publications
175 public List<Publication> getResultDocuments() {
176 List<Publication> result = new ArrayList<Publication>();
178 if (!_docums.isEmpty()) {
179 for (Publication content : _docums) {
180 DocumentType type = content.value().getType();
181 if (type.isResultOf(this.getStep())) {
190 * Get the abstract workflow step of this step instance.
192 * @return the abstract workflow step
194 public ProjectSettingsService.Step getStep() {
199 * Get an applied simulation context by its id or null.
202 * the simulation context id
203 * @return simulation context or null if it is not applied to this step
205 public SimulationContext getSimulationContext(final long contextId) {
206 SimulationContext found = null;
207 for (Iterator<SimulationContext> i = _owner.SimulationContextIterator(); i
209 SimulationContext myctex = i.next();
210 if (myctex.getIndex() == contextId) {
219 * Get applied simulation contexts of the given type.
222 * the simulation context type
223 * @return the list of applied simulation contexts
225 public List<SimulationContext> getSimulationContext(
226 final SimulationContextType type) {
227 List<SimulationContext> result = new ArrayList<SimulationContext>();
229 for (Iterator<SimulationContext> i = _owner.SimulationContextIterator(); i
231 SimulationContext myctex = i.next();
232 if (myctex.getType().equals(type)) {
240 * Check if the step is started, i.e. it contains a knowledge if applicable or at least one document.
242 * @return true if the step is started, otherwise false
244 public boolean isStarted() {
245 boolean res = _step.mayContain(KnowledgeElement.class);
247 List<KnowledgeElement> kelm = ((Scenario) _owner)
248 .getAllKnowledgeElements();
249 res = (!kelm.isEmpty() || !_docums.isEmpty());
251 res = (!_docums.isEmpty());
257 * Check if the step is finished, i.e. all knowledges are approved if any,<BR>
258 * there is at least one non external result document and all non external <BR>
259 * result documents are approved.
261 * @return true if the step is finished, otherwise false
263 public boolean isFinished() {
264 boolean result = false;
265 if (_step.mayContain(KnowledgeElement.class)) {
266 // Check if all existing knowledges are approved
267 List<KnowledgeElement> kelm = ((Scenario) _owner)
268 .getAllKnowledgeElements();
269 if (!kelm.isEmpty()) {
271 for (KnowledgeElement content : kelm) {
272 if (content.getProgressState() != ProgressState.APPROVED) {
279 // Check if all result documents are approved
280 for (Publication pub : _docums) {
281 Document content = pub.value();
282 DocumentType type = content.getType();
283 if (type.isResultOf(this.getStep())
284 && (content.getProgressState() != ProgressState.EXTERN)) {
285 // There is at least 1 non external result document
286 result = (content.getProgressState() == ProgressState.APPROVED);
288 break; // not approved result is found
297 * Check if data of the given type are applicable to this step.
300 * the data type to check
301 * @return true if the type is applicable to the step, otherwise false
303 @SuppressWarnings("unchecked")
304 public boolean mayContain(final Class type) {
305 return _step.mayContain(type);
309 * Set an actor involved in operations on published documents and requiring a time-stamp.
314 public void setActor(final User user) {
319 * Get the list of simulation contexts applied to this step instance.
321 * @return the list of applied simulation contexts
323 public List<SimulationContext> getContex() {