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.LinkedList;
14 import java.util.List;
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.InvalidPropertyException;
22 import org.splat.kernel.MissedPropertyException;
23 import org.splat.kernel.MultiplyDefinedException;
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 scenarios.
55 private final List<Scenario> scenarii = new LinkedList<Scenario>();
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 final List<User> contributor = new Vector<User>();
68 * Transient map of document types to validation cycles.
70 private transient final Map<String, ValidationCycle> validactor = new HashMap<String, ValidationCycle>();
72 * Transient set of all actors of the study, i.d. contributors and validation cycles participants.
74 private transient final Set<User> actor = new HashSet<User>();
76 // ==============================================================================================================================
78 // ==============================================================================================================================
81 * Fields initialization class.
83 public static class Properties extends Persistent.Properties {
84 private String sid = null; // Search criterion only
85 private String title = null;
86 private String summary = null;
87 private User manager = null;
88 private User actor = null; // Search criterion only
89 private Visibility visibility = null; // Search criterion only
90 private ProgressState state = null; // Search criterion only
91 private Date date = null;
92 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(final User actor) {
166 public Properties setDate(final Date date) {
171 public Properties setDescription(final String summary) {
172 if (summary.length() > 0) {
173 this.summary = summary;
178 public Properties setManager(final User user) {
183 // For building a search query
184 public Properties setReference(final String sid)
185 throws InvalidPropertyException {
186 if (sid.length() == 0) {
187 throw new InvalidPropertyException("reference");
193 // For building a search query
194 public Properties setSimulationContexts(
195 final List<SimulationContext> context) {
196 this.context = context;
200 // For building a search query
201 public Properties setState(final ProgressState state) {
206 public Properties setTitle(final String title)
207 throws InvalidPropertyException {
208 if (title.length() == 0) {
209 throw new InvalidPropertyException("title");
215 // For building a search query
216 public Properties setVisibility(final Visibility area) {
217 this.visibility = area;
221 // - Global validity check
223 public void checkValidity() throws MissedPropertyException,
224 InvalidPropertyException, MultiplyDefinedException {
226 throw new MissedPropertyException("title");
228 if (manager == null) {
229 throw new MissedPropertyException("manager");
235 * Database fetch constructor.
245 * Constructor from properties.
249 * @throws MissedPropertyException
250 * if some mandatory property is missed
251 * @throws InvalidPropertyException
252 * if some property has invalid value
253 * @throws MultiplyDefinedException
254 * if some property is defined several times
256 public Study(final Properties sprop) throws MissedPropertyException,
257 InvalidPropertyException, MultiplyDefinedException {
258 super(sprop); // Throws one of the above exception if not valid
259 sid = sprop.sid; // Reset after save
260 title = sprop.title; // Inherited attribute
261 manager = sprop.manager;
264 // RKV scenarii = new LinkedList<Scenario>();
265 visibility = Visibility.PRIVATE;
266 state = ProgressState.inWORK;
268 credate = sprop.date; // Inherited attribute
269 if (credate == null) {
270 Calendar current = Calendar.getInstance();
271 credate = current.getTime(); // Today
273 lasdate = credate; // Inherited attribute
274 version = new Revision().incrementAs(state).toString();
276 if (sprop.summary != null) {
277 this.setAttribute(new DescriptionAttribute(this, sprop.summary));
285 public ProgressState getProgressState() {
290 * Returns the global unique reference of this study. The study reference is common to all versions of the study (versioning a study
291 * does not change its reference). The form of this study reference is defined in the configuration of the application server - see the
292 * SOM XML customization file.
294 public String getReference() {
298 public void setReference(final String aReference) {
303 * Get persistent list of study scenarios as an array.
305 * @return array of scenarios
307 public Scenario[] getScenarii() {
308 return scenarii.toArray(new Scenario[scenarii.size()]);
312 * Get persistent list of study scenarios.
314 * @return the list of scenarios
316 public List<Scenario> getScenariiList() {
320 public String getVersion() {
324 public Visibility getVisibility() {
329 * Checks whether this study is in the Public or the Reference area of the repository.
331 * @return true if the study is public.
332 * @see #moveToPublic()
333 * @see #moveToReference()
335 public boolean isPublic() {
336 return (visibility != Visibility.PRIVATE);
339 public boolean isVersioned() {
340 return (history > 0);
344 * Check if the document is shared by scenarios of the study.
347 * the document to check
348 * @return true if the document is published in more then one scenario of the study
350 public boolean shares(final Document doc) {
351 Scenario[] scene = this.getScenarii(); // If shared from within the study, the document is shared by the scenarios
355 for (int i = 0; i < scene.length; i++) {
356 if (scene[i].publishes(doc)) {
368 * Get the last numerical index of study documents.
370 * @return the last value of the index part of study documents reference
372 public int getLastLocalIndex() {
377 * Set visibility of the study.
380 * a study visibility to set
382 public void setVisibility(final Visibility aVisibility) {
383 visibility = aVisibility;
387 * Set the progress state for the study.
390 * a study progress state to set
392 public void setProgressState(final ProgressState aState) {
397 * Set the study version.
402 public void setVersion(final String aVersion) {
407 * Set total number of documents of this study, including versions. It is stored in the persistent property docount.
410 * a number of study documents
412 public void setLastLocalIndex(final int anIndex) {
417 * Get the transient map of document types to validation cycles.
419 * @return map of validation cycles
421 public Map<String, ValidationCycle> getValidationCycles() {
426 * Get the transient list of study contributors.
428 * @return the List of User objects
430 public List<User> getContributor() {
435 * Get the transient set of all study actors (contributors and validation cycles participants).
437 * @return the set of User objects
439 public Set<User> getActor() {
446 * @see org.splat.dal.bo.som.ProjectElement#getOwnerStudy()
449 public Study getOwnerStudy() {