1 package org.splat.dal.bo.som;
5 * @author Daniel Brunier-Coulin
6 * @copyright OPEN CASCADE 2012
9 import java.util.Calendar;
10 import java.util.Date;
11 import java.util.HashMap;
12 import java.util.HashSet;
13 import java.util.List;
14 import java.util.LinkedList;
17 import java.util.Vector;
19 import org.splat.dal.bo.kernel.Persistent;
20 import org.splat.dal.bo.kernel.User;
21 import org.splat.kernel.MultiplyDefinedException;
22 import org.splat.kernel.InvalidPropertyException;
23 import org.splat.kernel.MissedPropertyException;
24 import org.splat.som.Revision;
27 * Siman Study persistent object.
29 public class Study extends ProjectElement {
33 * Persistent sid property. It is an external unique reference in a format conform to the configuration pattern.
37 * Persistent docount property. It is a total number of documents of this study, including versions.
41 * Persistent state property. It is a study progress state.
43 * @see org.splat.dal.bo.som.ProgressState enumeration
45 private ProgressState state;
47 * Persistent visibility property.
49 * @see org.splat.dal.bo.som.Visibility enumeration
51 private Visibility visibility;
53 * Persistent list of study scenarii.
55 private List<Scenario> scenarii;
56 private String version;
58 * Persistent history property. It is a number of studies versioning this one, if any.
64 * Transient list of contributors.
66 private transient List<User> contributor = new Vector<User>(); // Shortcut to contributors
68 * Transient map of document types to validation cycles.
70 private transient Map<String, ValidationCycle> validactor = new HashMap<String, ValidationCycle>(); // Shortcut to validation cycles
72 * Transient set of all actors of the study, i.d. contributors and validation cycles participants.
74 private transient Set<User> actor = new HashSet<User>(); // Summary of above actors
76 // ==============================================================================================================================
78 // ==============================================================================================================================
81 * Fields initialization class.
83 public static class Properties extends Persistent.Properties {
84 // ------------------------------------------------------------
85 private String sid = null; // Search criterion only
86 private String title = null;
87 private String summary = null;
88 private User manager = null;
89 private User actor = null; // Search criterion only
90 private Visibility visibility = null; // Search criterion only
91 private ProgressState state = null; // Search criterion only
92 private Date date = null;
93 private List<SimulationContext> context = new Vector<SimulationContext>(); // Search criterion only
107 context = new Vector<SimulationContext>(); // as clear() may generate side effects
110 public Properties copy() {
111 Properties copy = new Properties();
113 copy.title = this.title;
114 copy.summary = this.summary;
115 copy.manager = this.manager;
116 copy.actor = this.actor;
117 copy.visibility = this.visibility;
118 copy.state = this.state;
119 copy.date = this.date;
120 copy.context = this.context;
124 // - Protected services
126 public User getActor() {
130 public User getManager() {
134 public ProgressState getProgressState() {
138 public String getReference() {
142 public List<SimulationContext> getSimulationContexts() {
146 public String getTitle() {
150 public String getSummary() {
154 public Visibility getVisibility() {
158 // - Property setters
160 // For building a search query
161 public Properties setActor(User actor) {
166 public Properties setDate(Date date) {
171 public Properties setDescription(String summary) {
172 if (summary.length() > 0)
173 this.summary = summary;
177 public Properties setManager(User user) {
182 // For building a search query
183 public Properties setReference(String sid)
184 throws InvalidPropertyException {
185 if (sid.length() == 0)
186 throw new InvalidPropertyException("reference");
191 // For building a search query
192 public Properties setSimulationContexts(List<SimulationContext> context) {
193 this.context = context;
197 // For building a search query
198 public Properties setState(ProgressState state) {
203 public Properties setTitle(String title)
204 throws InvalidPropertyException {
205 if (title.length() == 0)
206 throw new InvalidPropertyException("title");
211 // For building a search query
212 public Properties setVisibility(Visibility area) {
213 this.visibility = area;
217 // - Global validity check
219 public void checkValidity() throws MissedPropertyException,
220 InvalidPropertyException, MultiplyDefinedException {
222 throw new MissedPropertyException("title");
224 throw new MissedPropertyException("manager");
228 // Database fetch constructor
235 // Internal constructor
236 public Study(Properties sprop) throws MissedPropertyException,
237 InvalidPropertyException, MultiplyDefinedException {
238 // ----------------------------------
239 super(sprop); // Throws one of the above exception if not valid
240 sid = sprop.sid; // Reset after save
241 title = sprop.title; // Inherited attribute
242 manager = sprop.manager;
245 scenarii = new LinkedList<Scenario>();
246 visibility = Visibility.PRIVATE;
247 state = ProgressState.inWORK;
249 credate = sprop.date; // Inherited attribute
250 if (credate == null) {
251 Calendar current = Calendar.getInstance();
252 credate = current.getTime(); // Today
254 lasdate = credate; // Inherited attribute
255 version = new Revision().incrementAs(state).toString();
257 if (sprop.summary != null)
258 this.setAttribute(new DescriptionAttribute(this, sprop.summary));
265 public ProgressState getProgressState() {
270 * Returns the global unique reference of this study. The study reference is common to all versions of the study (versioning a study
271 * does not change its reference). The form of this study reference is defined in the configuration of the application server - see the
272 * SOM XML customization file.
274 public String getReference() {
278 public void setReference(String aReference) {
282 public Scenario[] getScenarii() {
283 // --------------------------------
284 return scenarii.toArray(new Scenario[scenarii.size()]);
287 public List<Scenario> getScenariiList() {
288 // --------------------------------
292 public String getVersion() {
293 // ---------------------------
297 public Visibility getVisibility() {
298 // ----------------------------------
303 * Checks whether this study is in the Public or the Reference area of the repository.
305 * @return true if the study is public.
306 * @see #moveToPublic()
307 * @see #moveToReference()
309 public boolean isPublic() {
310 // --------------------------
311 return (visibility != Visibility.PRIVATE);
314 public boolean isVersioned() {
315 // -----------------------------
316 return (history > 0);
319 public boolean shares(Document doc) {
320 // ------------------------------------
321 Scenario[] scene = this.getScenarii(); // If shared from within the study, the document is shared by the scenarios
324 for (int i = 0; i < scene.length; i++) {
325 if (!scene[i].publishes(doc))
334 public int getLastLocalIndex() {
335 // ----------------------------------
341 * a study visibility to set
343 public void setVisibility(Visibility aVisibility) {
344 visibility = aVisibility;
349 * a study progress state to set
351 public void setProgressState(ProgressState aState) {
358 public void setVersion(String aVersion) {
363 * Set total number of documents of this study, including versions. It is stored in the persistent property docount.
366 * a number of study documents
368 public void setLastLocalIndex(int anIndex) {
373 * Get the transient map of document types to validation cycles.
375 * @return map of validation cycles
377 public Map<String, ValidationCycle> getValidationCycles() {
382 * Get the transient list of study contributors.
384 * @return the List of User objects
386 public List<User> getContributor() {
391 * Get the transient set of all study actors (contributors and validation cycles participants).
393 * @return the set of User objects
395 public Set<User> getActor() {