1 package org.splat.dal.bo.som;
4 * @author Daniel Brunier-Coulin
5 * @copyright OPEN CASCADE 2012
8 import java.util.Collections;
10 import java.util.Iterator;
11 import java.util.LinkedHashSet;
12 import java.util.List;
14 import java.util.Vector;
16 import org.apache.log4j.Logger;
18 import org.splat.dal.bo.kernel.User;
19 import org.splat.dal.dao.som.Database;
20 import org.splat.kernel.ObjectProperties;
21 import org.splat.kernel.InvalidPropertyException;
22 import org.splat.kernel.MissedPropertyException;
23 import org.splat.kernel.MultiplyDefinedException;
24 import org.splat.som.Step;
27 public abstract class ProjectElement extends Entity {
30 protected String title;
31 protected User manager;
32 protected Date credate; // Object creation date
33 protected Date lasdate; // Object Last modification date
34 private List<SimulationContext> contex; // Structured by the Step transient class
35 private Set<Publication> docums; // Structured by the Step transient class
38 private Step[] folders;
42 * @param folders the folders to set
44 public void setFolders(Step[] folders) {
45 this.folders = folders;
51 public Step[] getFolders() {
55 protected final static Logger logger = Logger.getLogger(ProjectElement.class);
57 // ==============================================================================================================================
59 // ==============================================================================================================================
61 // Database fetch constructor
62 protected ProjectElement () {
63 // ---------------------------
66 // Initialization constructor
67 protected ProjectElement (ObjectProperties oprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException {
68 // -------------------------------------------------
69 super(oprop); // Throws one of the above exception if not valid
70 title = null; // Initialized by subclasses
71 credate = null; // Initialized by subclasses
72 lasdate = null; // Initialized by subclasses
73 docums = new LinkedHashSet<Publication>();
74 contex = new Vector<SimulationContext>();
79 // ==============================================================================================================================
80 // Public member functions
81 // ==============================================================================================================================
83 public User getAuthor () {
84 // ------------------------
89 * Returns the creation date of this Project Element.
91 public Date getDate () {
92 // ----------------------
96 public String getDescription () {
97 // -------------------------------
98 String summary = null;
99 DescriptionAttribute field = (DescriptionAttribute)this.getAttribute(DescriptionAttribute.class);
100 if (field != null) summary = field.getValue();
101 return summary; // May be null
104 public Date getLastModificationDate () {
108 public void setLastModificationDate (Date aDate) {
113 * Returns the publication into this Project Element of the given document version, if exists.
114 * If exists, a document publication id unique in a given ProjectElement.
116 * @param doc a document version published into this Project Element
117 * @return the publication of the document version, or null if the given document version is not published into this Project Element
119 public Publication getPublication (Document doc) {
120 // ------------------------------------------------
121 int index = doc.getIndex();
122 for (Iterator<Publication> i=docums.iterator(); i.hasNext(); ) {
123 Publication found = i.next();
124 if (found.value().getIndex() == index) return found; // A document publication is unique in a given ProjectElement
129 public String getTitle () {
130 // -------------------------
134 public void setTitle (String aTitle) {
138 public boolean publishes (Document doc) {
139 // ---------------------------------------
140 int index = doc.getIndex();
141 for (Iterator<Publication> i=docums.iterator(); i.hasNext(); ) {
142 Document found = i.next().value();
143 if (found.getIndex() == index) return true;
148 public Iterator<Publication> PublicationIterator () {
149 // ---------------------------------------------------
150 return Collections.unmodifiableSet(docums).iterator();
153 public Iterator<SimulationContext> SimulationContextIterator () {
154 // ---------------------------------------------------------------
155 return Collections.unmodifiableList(contex).iterator();
158 // ==============================================================================================================================
159 // Protected member functions
160 // ==============================================================================================================================
162 public boolean add (Publication newdoc) {
163 // ------------------------------------------
164 return docums.add(newdoc);
167 public boolean add (SimulationContext newdoc) {
168 // ------------------------------------------------
169 return contex.add(newdoc);
172 public boolean remove (Publication oldoc) {
173 // --------------------------------------------
174 return docums.remove(oldoc); // The removed tag becoming orphan, it is supposed automatically deleted from the data store
177 public boolean remove (SimulationContext oldoc) {
178 // --------------------------------------------------
179 return contex.remove(oldoc);
183 * Refreshes the internal data potentially out-of-date.
184 * This function needs to be called when Publication objects are added to this Project Element before being saved. The reason is,
185 * as saving a persistent object changes its hashcode, hashed data need to be rebuilt after saving for making functions based
186 * on this hashcode such as remove(), working.
188 public void refresh () {
189 // -------------------------
190 Publication[] curdoc = docums.toArray(new Publication[docums.size()]);
192 folders = null; // Just in case
194 for (int i=0; i<curdoc.length; i++) docums.add(curdoc[i]);
195 // No need to rebuild the list of SimulationContext as it does not use hashcodes
196 Database.getSession().update(this);