1 package org.splat.simer;
3 import java.util.Arrays;
6 import org.splat.dal.bo.som.ProjectElement;
7 import org.splat.dal.bo.som.SimulationContext;
8 import org.splat.dal.bo.som.SimulationContextType;
9 import org.splat.service.SimulationContextService;
10 import org.splat.service.SimulationContextTypeService;
11 import org.splat.service.StepService;
12 import org.splat.service.StudyService;
13 import org.splat.som.Step;
14 import org.splat.dal.bo.som.Study;
16 public class EditSimulationContextAction extends DisplayStudyStepAction {
18 private List<SimulationContextType> contype = null;
19 private List<SimulationContext> contelm = null;
20 private String selectype = null; // Context type, if selected
21 private String newtype = null; // Context type, if newed
22 private SimulationContextType type = null; // Corresponding context type object
23 private String value = null; // Context value
25 * Injected study service.
27 private StudyService _studyService;
29 * Injected step service.
31 private StepService _stepService;
33 * Injected simulation context service.
35 private SimulationContextService _simulationContextService;
37 * Injected simulation context type service.
39 private SimulationContextTypeService _simulationContextTypeService;
42 * Value of the menu property.
43 * It can be: none, create, open, study, knowledge, sysadmin, help.
45 private String _menuProperty;
48 * Get the stepService.
50 * @return the stepService
52 public StepService getStepService() {
57 * Set the stepService.
60 * the stepService to set
62 public void setStepService(StepService stepService) {
63 _stepService = stepService;
66 private static final long serialVersionUID = -641719644024601042L;
68 // ==============================================================================================================================
70 // ==============================================================================================================================
72 public String doInitialize() {
74 mystudy = getOpenStudy();
75 contype = getInvolvedContexts();
77 setMenuProperty("study");
78 initializationScreenContext(_menuProperty);
80 if (contype.isEmpty())
86 public String doSelectContext() {
87 mystudy = getOpenStudy();
89 setMenuProperty("study");
90 initializationScreenContext(_menuProperty);
92 int typid = Integer.valueOf(selectype);
96 SimulationContext.Properties cprop = new SimulationContext.Properties();
97 type = getSimulationContextService().selectType(typid);
98 newtype = type.getName();
99 contype = getInvolvedContexts();
100 contelm = getSimulationContextService()
101 .selectSimulationContextsWhere(cprop.setType(type));
106 public String doCreateContext() {
107 // --------------------------------
109 mystudy = getOpenStudy();
111 setMenuProperty("study");
112 initializationScreenContext(_menuProperty);
114 if (newtype.length() == 0 || value.length() == 0)
117 Step step = mystudy.getSelectedStep();
118 ProjectElement owner = step.getOwner();
120 SimulationContext.Properties cprop = new SimulationContext.Properties();
121 SimulationContext contex = null;
122 type = getSimulationContextTypeService().createType(newtype,
124 cprop.setType(type).setValue(value);
125 if (owner instanceof Study)
126 contex = getStudyService().addProjectContext(((Study) owner),
127 cprop); // Re-indexes knowledges and the study
129 contex = getStepService().addSimulationContext(step, cprop); // Re-indexes knowledges only
133 } catch (RuntimeException saverror) {
134 logger.error("Reason:", saverror);
136 } catch (Exception error) {
141 public String doDeleteContext() {
143 setMenuProperty("study");
144 initializationScreenContext(_menuProperty);
147 mystudy = getOpenStudy();
149 Step step = mystudy.getSelectedStep();
150 ProjectElement owner = step.getOwner();
151 SimulationContext context = step.getSimulationContext(Integer
153 if (owner instanceof Study)
155 .removeProjectContext(((Study) owner), context); // Re-indexes knowledges and the study
157 getStepService().removeSimulationContext(step, context); // Re-indexes knowledges only
159 mystudy.remove(context);
161 } catch (RuntimeException saverror) {
162 logger.error("Reason:", saverror);
167 public String doSetContext() {
168 // -----------------------------
169 String[] input = value.split(",");
170 // Session connex = Database.getCurSession();
171 // Transaction transax = connex.beginTransaction();
173 setMenuProperty("study");
174 initializationScreenContext(_menuProperty);
177 mystudy = getOpenStudy();
179 Step step = mystudy.getSelectedStep();
180 ProjectElement owner = step.getOwner();
181 SimulationContext contex = null;
183 if (input.length == 1
184 || (input.length == 2 && input[1].equals(" "))) {
185 // Setting an existing simulation context identified by value (input = rid," ")
186 int valid = Integer.valueOf(input[0]);
187 contex = getSimulationContextService().selectSimulationContext(
189 if (owner instanceof Study)
191 .addProjectContext(((Study) owner), contex);
193 getStepService().addSimulationContext(step, contex);
195 // Setting a new simulation context value (input = 0,"new context value")
196 int typid = Integer.valueOf(selectype);
197 SimulationContext.Properties cprop = new SimulationContext.Properties();
198 cprop.setType(getSimulationContextService().selectType(typid))
199 .setValue(input[1].trim());
200 if (owner instanceof Study)
201 contex = getStudyService().addProjectContext(
202 ((Study) owner), cprop); // Re-indexes knowledges and the study
204 contex = getStepService().addSimulationContext(step, cprop); // Re-indexes knowledges only
207 contype = getInvolvedContexts();
211 } catch (RuntimeException saverror) {
212 logger.error("Reason:", saverror);
214 } catch (Exception error) {
220 // ==============================================================================================================================
221 // Getters and setters
222 // ==============================================================================================================================
224 public SimulationContextType getContextType() {
225 // ----------------------------------------------
229 public String getContextName() {
230 // -------------------------------
234 // public List<SimulationContextFacade> getSimulationContexts () {
235 // -------------------------------------------------------
236 // return mystudy.getSelectedStep().getAllSimulationContexts();
238 public List<SimulationContextType> getSimulationContextTypes() {
239 // ---------------------------------------------------------------
243 public List<SimulationContext> getSimulationContextValues() {
244 // ------------------------------------------------------------
248 public void setContextType(String type) {
249 // ----------------------------------------
250 this.selectype = type;
253 public void setContextValue(String value) {
254 // -----------------------------------------
258 public void setNewType(String name) {
259 // ------------------------------------
263 // ==============================================================================================================================
265 // ==============================================================================================================================
267 private List<SimulationContextType> getInvolvedContexts() {
268 // ----------------------------------------------------------
269 SimulationContextType.Properties sprop = new SimulationContextType.Properties()
270 .setStep(mystudy.getSelectedStep().getStep());
271 List<SimulationContextType> contype = getSimulationContextService()
272 .selectTypesWhere(sprop);
274 if (!contype.isEmpty()) {
275 // Ordering by alphabetical order of localized context types
276 SimulationContextType[] types = contype
277 .toArray(new SimulationContextType[contype.size()]);
278 ContextTypeComparator compare = new ContextTypeComparator();
279 boolean state = types[0].isApproved();
282 while (to < types.length - 1) {
284 if (types[to].isApproved() == state)
288 Arrays.sort(types, from, to, compare);
293 Arrays.sort(types, from, to + 1, compare);
294 contype = Arrays.asList(types);
300 * Get the studyService.
302 * @return the studyService
304 public StudyService getStudyService() {
305 return _studyService;
309 * Set the studyService.
311 * @param studyService
312 * the studyService to set
314 public void setStudyService(StudyService studyService) {
315 _studyService = studyService;
319 * Get the simulationContextService.
321 * @return the simulationContextService
323 public SimulationContextService getSimulationContextService() {
324 return _simulationContextService;
328 * Set the simulationContextService.
330 * @param simulationContextService
331 * the simulationContextService to set
333 public void setSimulationContextService(
334 SimulationContextService simulationContextService) {
335 _simulationContextService = simulationContextService;
339 * Get the simulationContextTypeService.
340 * @return the simulationContextTypeService
342 public SimulationContextTypeService getSimulationContextTypeService() {
343 return _simulationContextTypeService;
347 * Set the simulationContextTypeService.
348 * @param simulationContextTypeService the simulationContextTypeService to set
350 public void setSimulationContextTypeService(
351 SimulationContextTypeService simulationContextTypeService) {
352 _simulationContextTypeService = simulationContextTypeService;
356 * Get the menuProperty.
357 * @return the menuProperty
359 public String getMenuProperty() {
360 return _menuProperty;
364 * Set the menuProperty.
365 * @param menuProperty the menuProperty to set
367 public void setMenuProperty(String menuProperty) {
368 this._menuProperty = menuProperty;