5 * @author Daniel Brunier-Coulin
6 * @copyright OPEN CASCADE 2012
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;
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
35 // ==============================================================================================================================
37 // ==============================================================================================================================
39 public Step(final ProjectSettingsService.Step step,
40 final ProjectElement owner) {
43 this._contex = new ArrayList<SimulationContext>();
44 this._docums = new ArrayList<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)) {
54 this._contex.add(adoc);
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)) {
62 mydoc.setStep(this); //RKV
63 this._docums.add(mydoc);
67 // ==============================================================================================================================
68 // Public member functions
69 // ==============================================================================================================================
71 public User getActor() {
75 public List<Publication> getAllDocuments() {
76 return Collections.unmodifiableList(_docums);
80 * Get the persistent collection of step documents.
82 * @return the list of documents
84 public List<Publication> getDocuments() {
88 public List<SimulationContext> getAllSimulationContexts() {
89 return Collections.unmodifiableList(_contex);
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
102 public int getNumber() {
103 return _step.getNumber();
106 public ProjectElement getOwner() {
107 return _owner; // May be a Study or a Scenario
110 public Study getOwnerStudy() {
111 if (_owner instanceof Study) {
112 return (Study) _owner;
114 return ((Scenario) _owner).getOwnerStudy();
118 public String getPath() {
119 return _step.getPath();
122 public List<Publication> getResultDocuments() {
123 List<Publication> result = new ArrayList<Publication>();
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())) {
138 public ProjectSettingsService.Step getStep() {
142 public SimulationContext getSimulationContext(final long l) {
143 for (Iterator<SimulationContext> i = _owner.SimulationContextIterator(); i
145 SimulationContext myctex = i.next();
146 if (myctex.getIndex() == l) {
153 public List<SimulationContext> getSimulationContext(
154 final SimulationContextType type) {
155 List<SimulationContext> result = new ArrayList<SimulationContext>();
157 for (Iterator<SimulationContext> i = _owner.SimulationContextIterator(); i
159 SimulationContext myctex = i.next();
160 if (myctex.getType().equals(type)) {
167 public boolean isStarted() {
168 boolean res = _step.mayContain(KnowledgeElement.class);
170 List<KnowledgeElement> kelm = ((Scenario) _owner)
171 .getAllKnowledgeElements();
172 res = (!kelm.isEmpty() || !_docums.isEmpty());
174 res = (!_docums.isEmpty());
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()) {
186 for (Iterator<KnowledgeElement> i = kelm.iterator(); i.hasNext();) {
187 KnowledgeElement content = i.next();
188 if (content.getProgressState() != ProgressState.APPROVED) {
193 } else { // Check if all existing knowledges are approved
194 if (_docums.isEmpty()) {
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())) {
204 if (content.getProgressState() == ProgressState.EXTERN) {
207 result = true; // There is at least 1 non external result document
208 if (content.getProgressState() != ProgressState.APPROVED) {
216 @SuppressWarnings("unchecked")
217 public boolean mayContain(final Class type) {
218 return _step.mayContain(type);
221 public void setActor(final User user) {
225 public List<SimulationContext> getContex() {