1 package org.splat.dal.bo.som;
5 * @author Daniel Brunier-Coulin
6 * @copyright OPEN CASCADE 2012
9 import java.util.Collections;
10 import java.util.Date;
11 import java.util.HashSet;
12 import java.util.Iterator;
13 import java.util.LinkedHashSet;
14 import java.util.List;
16 import java.util.Vector;
18 import org.splat.dal.bo.kernel.Entity;
19 import org.splat.dal.bo.kernel.User;
20 import org.splat.kernel.InvalidPropertyException;
21 import org.splat.kernel.MissedPropertyException;
22 import org.splat.kernel.MultiplyDefinedException;
23 import org.splat.kernel.ObjectProperties;
24 import org.splat.som.Step;
27 * Persistent project element class. It can be study or scenario.
29 public abstract class ProjectElement extends Entity {
33 * Persistent field: project element title.
35 protected String title;
37 * Persistent field: project element author/manager.
39 protected User manager;
41 * Persistent field: object creation date.
43 protected Date credate;
45 * Persistent field: object last modification date.
47 protected Date lasdate;
49 * Persistent field: simulation contexts structured by the Step transient class.
51 private final List<SimulationContext> contex = new Vector<SimulationContext>();
53 * Persistent field: documents publications structured by the Step transient class.
55 private final Set<Publication> docums = new LinkedHashSet<Publication>();
58 * Transient array of steps (folders).
60 private Step[] folders;
63 * Set the transient array of steps (folders).
68 public void setFolders(final Step[] folders) {
69 this.folders = folders;
73 * Get the transient array of steps (folders).
75 * @return the array of steps
77 public Step[] getFolders() {
81 // ==============================================================================================================================
83 // ==============================================================================================================================
86 * Database fetch constructor.
88 protected ProjectElement() {
94 * Initialization constructor.
97 * @throws MissedPropertyException
98 * @throws InvalidPropertyException
99 * @throws MultiplyDefinedException
101 protected ProjectElement(final ObjectProperties oprop)
102 throws MissedPropertyException, InvalidPropertyException,
103 MultiplyDefinedException {
104 super(oprop); // Throws one of the above exception if not valid
105 title = null; // Initialized by subclasses
106 credate = null; // Initialized by subclasses
107 lasdate = null; // Initialized by subclasses
108 // RKV docums = new LinkedHashSet<Publication>();
109 // RKV contex = new Vector<SimulationContext>();
114 // ==============================================================================================================================
115 // Public member functions
116 // ==============================================================================================================================
118 public User getAuthor() {
123 * Returns the creation date of this Project Element.
125 public Date getDate() {
129 public String getDescription() {
130 String summary = null;
131 DescriptionAttribute field = (DescriptionAttribute) this
132 .getAttribute(DescriptionAttribute.class);
134 summary = field.getValue();
136 return summary; // May be null
139 public Date getLastModificationDate() {
143 public void setLastModificationDate(final Date aDate) {
148 * Returns the publication into this Project Element of the given document version, if exists. If exists, a document publication id
149 * unique in a given ProjectElement.
152 * a document version published into this Project Element
153 * @return the publication of the document version, or null if the given document version is not published into this Project Element
155 public Publication getPublication(final Document doc) {
156 long index = doc.getIndex();
157 for (Iterator<Publication> i = docums.iterator(); i.hasNext();) {
158 Publication found = i.next();
159 if (found.value().getIndex() == index) {
160 return found; // A document publication is unique in a given ProjectElement
166 public String getTitle() {
170 public void setTitle(final String aTitle) {
175 * Check if the given document is published in the scenario.
179 * @return true if the document is published in the scenario
181 public boolean publishes(final Document doc) {
183 long index = doc.getIndex();
184 for (Publication pub : docums) {
185 Document found = pub.value();
186 res = (found.getIndex() == index);
194 public Iterator<Publication> PublicationIterator() {
195 return Collections.unmodifiableSet(docums).iterator();
198 public Iterator<SimulationContext> SimulationContextIterator() {
199 return Collections.unmodifiableList(contex).iterator();
202 // ==============================================================================================================================
203 // Protected member functions
204 // ==============================================================================================================================
207 * Add a document publication to the project element.
210 * the publication to add
211 * @return true if added successfully, otherwise false
213 public boolean add(final Publication newdoc) {
214 return docums.add(newdoc);
218 * Add a simulation context to the project element.
221 * the simulation context to add
222 * @return true if added successfully, otherwise false
224 public boolean add(final SimulationContext newdoc) {
225 return contex.add(newdoc);
229 * Remove the document publication from the project element.
232 * the publication to remove
233 * @return true if removed successfully, otherwise false
235 public boolean remove(final Publication oldoc) {
236 return docums.remove(oldoc); // The removed tag becoming orphan, it is supposed automatically deleted from the data store
240 * Remove the simulation context from the project element.
243 * the simulation context to remove
244 * @return true if removed successfully, otherwise false
246 public boolean remove(final SimulationContext oldoc) {
247 return contex.remove(oldoc);
255 public Set<Publication> getDocums() {
260 * Return the study of the project element.
262 * @return the project element study
264 public abstract Study getOwnerStudy();
269 * @see org.splat.dal.bo.kernel.Entity#evict()
272 public void evict() {
274 // Evict all attributes of the persistent object
275 Set<Publication> tmpSet = new HashSet<Publication>();
276 tmpSet.addAll(docums);
278 // Evict publications
279 for (Publication rel : tmpSet) {
280 if (rel.isSaved()) { // to avoid recursive evict