1 package org.splat.dal.bo.som;
5 * @author Daniel Brunier-Coulin
6 * @copyright OPEN CASCADE 2012-2015
9 import java.util.Calendar;
10 import java.util.Collections;
11 import java.util.Date;
12 import java.util.HashMap;
13 import java.util.HashSet;
14 import java.util.Iterator;
15 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.Step;
27 * Scenario persistent object.
29 public class Scenario extends ProjectElement {
33 * Persistent property owner. It is a parent study of the scenario.
37 * Persistent property sid. It is an unique identifier in the scope of owner study.
41 * Persistent property cuser. It is a user having checked-out the scenario, if done.
45 * The persistent set of scenario knowledge elements.
47 private final Set<KnowledgeElement> kelms = new HashSet<KnowledgeElement>();
51 * The transient map of knowledge elements grouped by types.
53 transient private final HashMap<Long, List<KnowledgeElement>> known;
55 * The scenario transient list of knowledge elements.
57 transient private List<KnowledgeElement> knowl; // Copy of kelms excluding the internal Knowledge Element (ucase below)
59 * The scenario transient "use case" knowledge element.
61 transient private KnowledgeElement ucase; // Internal Knowledge Element for accessing to all used simulation contexts
63 // ==============================================================================================================================
65 // ==============================================================================================================================
68 * Fields initialization class.
70 public static class Properties extends Persistent.Properties {
71 private Study owner = null;
72 private Scenario previous = null;
73 private Step base = null;
74 private String title = null;
75 private String summary = null;
76 private User manager = null;
77 private Date date = null;
93 // - Protected services
95 public Step getBaseStep() {
96 return base; // May be null
99 public Scenario getInsertAfter() {
100 return previous; // May be null
103 public User getManager() {
107 public Properties setOwnerStudy(final Study owner) {
112 // - Setters of Scenario properties
114 public Properties setBaseStep(final Step base)
115 throws InvalidPropertyException {
116 if (!(base.getOwner() instanceof Scenario)) {
117 throw new InvalidPropertyException("step");
123 public Properties setDate(final Date date) {
128 public Properties setDescription(final String summary) {
129 if (summary.length() > 0) {
130 this.summary = summary;
135 public Properties setInsertAfter(final Scenario previous) {
136 this.previous = previous;
140 public Properties setManager(final User user) {
145 public Properties setTitle(final String title)
146 throws InvalidPropertyException {
147 if (title.length() == 0) {
148 throw new InvalidPropertyException("title");
154 // - Global validity check
156 public void checkValidity() throws MissedPropertyException,
157 InvalidPropertyException, MultiplyDefinedException {
159 throw new MissedPropertyException("owner");
162 throw new MissedPropertyException("title");
164 if (manager == null) {
165 throw new MissedPropertyException("manager");
170 // Database fetch constructor
171 protected Scenario() {
177 // Internal constructor
178 public Scenario(final Properties sprop) throws MissedPropertyException,
179 InvalidPropertyException, MultiplyDefinedException {
180 super(sprop); // Throws one of the above exception if not valid
184 title = sprop.title; // Inherited attribute
186 knowl = null; // Initialized when getting all Knowledge Elements
189 manager = sprop.manager;
190 // RKV: The business logic is moved to business services: if (!owner.isStaffedBy(manager)) throw new
191 // InvalidPropertyException("manager");
193 credate = sprop.date; // Inherited attribute
194 if (credate == null) {
195 Calendar current = Calendar.getInstance();
196 credate = current.getTime(); // Today
198 lasdate = credate; // Inherited attribute
200 if (sprop.summary != null) {
201 this.setAttribute(new DescriptionAttribute(this, sprop.summary));
204 Scenario[] scene = owner.getScenarii();
205 for (int i = 0; i < scene.length; i++) {
206 if (scene[i].sid > this.sid) {
207 this.sid = scene[i].sid;
213 // ==============================================================================================================================
214 // Public member functions
215 // ==============================================================================================================================
217 public List<KnowledgeElement> getAllKnowledgeElements() {
219 knowl = new Vector<KnowledgeElement>(kelms.size());
220 for (Iterator<KnowledgeElement> i = kelms.iterator(); i.hasNext();) {
221 KnowledgeElement kelm = i.next();
222 if (kelm.getType().equals("usecase")) {
229 return Collections.unmodifiableList(knowl);
232 public KnowledgeElement getKnowledgeElement(final long l) {
233 for (Iterator<KnowledgeElement> i = kelms.iterator(); i.hasNext();) {
234 KnowledgeElement mykelm = i.next();
235 if (l == mykelm.getIndex()) {
245 * @see org.splat.dal.bo.som.ProjectElement#getOwnerStudy()
248 public Study getOwnerStudy() {
253 * Returns the local reference of this scenario. This reference is unique in the scope of the owner study.
255 public String getReference() {
256 return String.valueOf(sid);
259 public User getUser() {
260 return cuser; // Null if the scenario has not been checked-out
263 public void setUser(final User aUser) {
264 cuser = aUser; // Null if the scenario has not been checked-out
267 public boolean isCheckedout() {
268 return (cuser != null);
271 // ==============================================================================================================================
273 // ==============================================================================================================================
275 * Get the persistent set of knowledge elements.
277 * @return the persistent set of scenario knowledge elements
279 public Set<KnowledgeElement> getKnowledgeElements() {
284 * Get the transient list of knowledge elements.
286 * @return the transient list of knowledge elements
288 public List<KnowledgeElement> getKnowledgeElementsList() {
293 * Set the scenario transient "use case" knowledge element.
296 * the scenario transient "use case" knowledge element
298 public void setUcase(final KnowledgeElement kelm) {
303 * Get the scenario transient "use case" knowledge element.
305 * @return the scenario transient "use case" knowledge element
307 public KnowledgeElement getUcase() {