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