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>();
57 * Persistent study version property.
59 private String version;
61 * Persistent history property. It is a number of studies versioning this one, if any.
66 * Persistent property. Flag: marked the given study as reference or not.
68 private int markreference;
72 * Transient list of contributors.
74 private transient final List<User> contributor = new Vector<User>();
76 * Transient map of document types to validation cycles.
78 private transient final Map<String, ValidationCycle> validactor = new HashMap<String, ValidationCycle>();
80 * Transient set of all actors of the study, i.d. contributors and validation cycles participants.
82 private transient final Set<User> actor = new HashSet<User>();
84 // ==============================================================================================================================
86 // ==============================================================================================================================
89 * Fields initialization class.
91 public static class Properties extends Persistent.Properties {
92 private String sid = null; // Search criterion only
93 private String title = null;
94 private String summary = null;
95 private User manager = null;
96 private User actor = null; // Search criterion only
97 private Visibility visibility = null; // Search criterion only
98 private ProgressState state = null; // Search criterion only
99 private Date date = null;
100 private List<SimulationContext> context = new Vector<SimulationContext>(); // Search criterion only
105 public void clear() {
115 context = new Vector<SimulationContext>(); // as clear() may generate side effects
118 public Properties copy() {
119 Properties copy = new Properties();
121 copy.title = this.title;
122 copy.summary = this.summary;
123 copy.manager = this.manager;
124 copy.actor = this.actor;
125 copy.visibility = this.visibility;
126 copy.state = this.state;
127 copy.date = this.date;
128 copy.context = this.context;
132 // - Protected services
134 public User getActor() {
138 public User getManager() {
142 public ProgressState getProgressState() {
146 public String getReference() {
150 public List<SimulationContext> getSimulationContexts() {
154 public String getTitle() {
158 public String getSummary() {
162 public Visibility getVisibility() {
166 // - Property setters
168 // For building a search query
169 public Properties setActor(final User actor) {
174 public Properties setDate(final Date date) {
179 public Properties setDescription(final String summary) {
180 if (summary.length() > 0) {
181 this.summary = summary;
186 public Properties setManager(final User user) {
191 // For building a search query
192 public Properties setReference(final String sid)
193 throws InvalidPropertyException {
194 if (sid.length() == 0) {
195 throw new InvalidPropertyException("reference");
201 // For building a search query
202 public Properties setSimulationContexts(
203 final List<SimulationContext> context) {
204 this.context = context;
208 // For building a search query
209 public Properties setState(final ProgressState state) {
214 public Properties setTitle(final String title)
215 throws InvalidPropertyException {
216 if (title.length() == 0) {
217 throw new InvalidPropertyException("title");
223 // For building a search query
224 public Properties setVisibility(final Visibility area) {
225 this.visibility = area;
229 // - Global validity check
232 public void checkValidity() throws MissedPropertyException,
233 InvalidPropertyException, MultiplyDefinedException {
235 throw new MissedPropertyException("title");
237 if (manager == null) {
238 throw new MissedPropertyException("manager");
244 * Database fetch constructor.
254 * Constructor from properties.
258 * @throws MissedPropertyException
259 * if some mandatory property is missed
260 * @throws InvalidPropertyException
261 * if some property has invalid value
262 * @throws MultiplyDefinedException
263 * if some property is defined several times
265 public Study(final Properties sprop) throws MissedPropertyException,
266 InvalidPropertyException, MultiplyDefinedException {
267 super(sprop); // Throws one of the above exception if not valid
268 sid = sprop.sid; // Reset after save
269 title = sprop.title; // Inherited attribute
270 manager = sprop.manager;
273 // RKV scenarii = new LinkedList<Scenario>();
274 visibility = Visibility.PRIVATE;
275 state = ProgressState.inWORK;
278 credate = sprop.date; // Inherited attribute
279 if (credate == null) {
280 Calendar current = Calendar.getInstance();
281 credate = current.getTime(); // Today
283 lasdate = credate; // Inherited attribute
284 version = new Revision().incrementAs(state).toString();
286 if (sprop.summary != null) {
287 this.setAttribute(new DescriptionAttribute(this, sprop.summary));
295 public ProgressState getProgressState() {
300 * Returns the global unique reference of this study. The study reference is common to all versions of the study (versioning a study
301 * does not change its reference). The form of this study reference is defined in the configuration of the application server - see the
302 * SOM XML customization file.
304 public String getReference() {
308 public void setReference(final String aReference) {
313 * Get persistent list of study scenarios as an array.
315 * @return array of scenarios
317 public Scenario[] getScenarii() {
318 return scenarii.toArray(new Scenario[scenarii.size()]);
322 * Get persistent list of study scenarios.
324 * @return the list of scenarios
326 public List<Scenario> getScenariiList() {
330 public String getVersion() {
334 public Visibility getVisibility() {
339 * Checks whether this study is in the Public or the Reference area of the repository.
341 * @return true if the study is public.
342 * @see #moveToPublic()
343 * @see #moveToReference()
345 public boolean isPublic() {
346 return (visibility != Visibility.PRIVATE);
349 public boolean isVersioned() {
350 return (history > 0);
354 * Check if the document is shared by scenarios of the study.
357 * the document to check
358 * @return true if the document is published in more then one scenario of the study
360 public boolean shares(final Document doc) {
361 Scenario[] scene = this.getScenarii(); // If shared from within the study, the document is shared by the scenarios
365 for (int i = 0; i < scene.length; i++) {
366 if (scene[i].publishes(doc)) {
378 * Get the last numerical index of study documents.
380 * @return the last value of the index part of study documents reference
382 public int getLastLocalIndex() {
387 * Set visibility of the study.
390 * a study visibility to set
392 public void setVisibility(final Visibility aVisibility) {
393 visibility = aVisibility;
397 * Set the progress state for the study.
400 * a study progress state to set
402 public void setProgressState(final ProgressState aState) {
407 * Set the study version.
412 public void setVersion(final String aVersion) {
417 * Set total number of documents of this study, including versions. It is stored in the persistent property docount.
420 * a number of study documents
422 public void setLastLocalIndex(final int anIndex) {
427 * Get the transient map of document types to validation cycles.
429 * @return map of validation cycles
431 public Map<String, ValidationCycle> getValidationCycles() {
436 * Get the transient list of study contributors.
438 * @return the List of User objects
440 public List<User> getContributor() {
445 * Get the transient set of all study actors (contributors and validation cycles participants).
447 * @return the set of User objects
449 public Set<User> getActor() {
456 * @see org.splat.dal.bo.som.ProjectElement#getOwnerStudy()
459 public Study getOwnerStudy() {
464 * Get the markreference.
465 * @return the markreference
467 public int getMarkreference() {
468 return markreference;
472 * Set the markreference.
473 * @param markreference the markreference to set
475 public void setMarkreference(final int markreference) {
476 this.markreference = markreference;