Salome HOME
bf08b16ff78e281bd56f71348b1935ef35289f69
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / dal / bo / som / ProjectElement.java
1 package org.splat.dal.bo.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.Date;
11 import java.util.Iterator;
12 import java.util.LinkedHashSet;
13 import java.util.List;
14 import java.util.Set;
15 import java.util.Vector;
16
17 import org.splat.dal.bo.kernel.Entity;
18 import org.splat.dal.bo.kernel.User;
19 import org.splat.kernel.InvalidPropertyException;
20 import org.splat.kernel.MissedPropertyException;
21 import org.splat.kernel.MultiplyDefinedException;
22 import org.splat.kernel.ObjectProperties;
23 import org.splat.som.Step;
24
25 public abstract class ProjectElement extends Entity {
26
27         // Persistent fields
28         protected String title;
29         protected User manager;
30         protected Date credate; // Object creation date
31         protected Date lasdate; // Object Last modification date
32         private final List<SimulationContext> contex = new Vector<SimulationContext>(); // Structured by the Step transient class
33         private final Set<Publication> docums = new LinkedHashSet<Publication>(); // Structured by the Step transient class
34
35         /**
36          * Transient array of steps (folders).
37          */
38         private Step[] folders;
39
40         /**
41          * Set the transient array of steps (folders).
42          * 
43          * @param folders
44          *            the steps to set
45          */
46         public void setFolders(final Step[] folders) {
47                 this.folders = folders;
48         }
49
50         /**
51          * Get the transient array of steps (folders).
52          * 
53          * @return the array of steps
54          */
55         public Step[] getFolders() {
56                 return folders;
57         }
58
59         // ==============================================================================================================================
60         // Constructors
61         // ==============================================================================================================================
62
63         /**
64          * Database fetch constructor.
65          */
66         protected ProjectElement() {
67                 super();
68                 folders = null;
69         }
70
71         /**
72          * Initialization constructor.
73          * 
74          * @param oprop
75          * @throws MissedPropertyException
76          * @throws InvalidPropertyException
77          * @throws MultiplyDefinedException
78          */
79         protected ProjectElement(final ObjectProperties oprop)
80                         throws MissedPropertyException, InvalidPropertyException,
81                         MultiplyDefinedException {
82                 super(oprop); // Throws one of the above exception if not valid
83                 title = null; // Initialized by subclasses
84                 credate = null; // Initialized by subclasses
85                 lasdate = null; // Initialized by subclasses
86                 // RKV docums = new LinkedHashSet<Publication>();
87                 // RKV contex = new Vector<SimulationContext>();
88
89                 folders = null;
90         }
91
92         // ==============================================================================================================================
93         // Public member functions
94         // ==============================================================================================================================
95
96         public User getAuthor() {
97                 return manager;
98         }
99
100         /**
101          * Returns the creation date of this Project Element.
102          */
103         public Date getDate() {
104                 return credate;
105         }
106
107         public String getDescription() {
108                 String summary = null;
109                 DescriptionAttribute field = (DescriptionAttribute) this
110                                 .getAttribute(DescriptionAttribute.class);
111                 if (field != null) {
112                         summary = field.getValue();
113                 }
114                 return summary; // May be null
115         }
116
117         public Date getLastModificationDate() {
118                 return lasdate;
119         }
120
121         public void setLastModificationDate(final Date aDate) {
122                 lasdate = aDate;
123         }
124
125         /**
126          * Returns the publication into this Project Element of the given document version, if exists. If exists, a document publication id
127          * unique in a given ProjectElement.
128          * 
129          * @param doc
130          *            a document version published into this Project Element
131          * @return the publication of the document version, or null if the given document version is not published into this Project Element
132          */
133         public Publication getPublication(final Document doc) {
134                 long index = doc.getIndex();
135                 for (Iterator<Publication> i = docums.iterator(); i.hasNext();) {
136                         Publication found = i.next();
137                         if (found.value().getIndex() == index) {
138                                 return found; // A document publication is unique in a given ProjectElement
139                         }
140                 }
141                 return null;
142         }
143
144         public String getTitle() {
145                 return title;
146         }
147
148         public void setTitle(final String aTitle) {
149                 title = aTitle;
150         }
151
152         /**
153          * Check if the given document is published in the scenario.
154          * 
155          * @param doc
156          *            the document
157          * @return true if the document is published in the scenario
158          */
159         public boolean publishes(final Document doc) {
160                 boolean res = false;
161                 long index = doc.getIndex();
162                 for (Iterator<Publication> i = docums.iterator(); i.hasNext();) {
163                         Document found = i.next().value();
164                         res = (found.getIndex() == index);
165                         if (res) {
166                                 break;
167                         }
168                 }
169                 return res;
170         }
171
172         public Iterator<Publication> PublicationIterator() {
173                 return Collections.unmodifiableSet(docums).iterator();
174         }
175
176         public Iterator<SimulationContext> SimulationContextIterator() {
177                 return Collections.unmodifiableList(contex).iterator();
178         }
179
180         // ==============================================================================================================================
181         // Protected member functions
182         // ==============================================================================================================================
183
184         public boolean add(final Publication newdoc) {
185                 return docums.add(newdoc);
186         }
187
188         public boolean add(final SimulationContext newdoc) {
189                 return contex.add(newdoc);
190         }
191
192         public boolean remove(final Publication oldoc) {
193                 return docums.remove(oldoc); // The removed tag becoming orphan, it is supposed automatically deleted from the data store
194         }
195
196         public boolean remove(final SimulationContext oldoc) {
197                 return contex.remove(oldoc);
198         }
199
200         /**
201          * Get the docums.
202          * 
203          * @return the docums
204          */
205         public Set<Publication> getDocums() {
206                 return docums;
207         }
208
209         /**
210          * Return the study of the project element.
211          * 
212          * @return the project element study
213          */
214         public abstract Study getOwnerStudy();
215 }