1 package org.splat.simer;
4 import java.util.ResourceBundle;
6 import org.splat.dal.bo.som.Scenario;
7 import org.splat.dal.bo.som.SimulationContext;
8 import org.splat.dal.bo.som.SimulationContextType;
9 import org.splat.dal.bo.som.Study;
10 import org.splat.service.ScenarioService;
11 import org.splat.service.SimulationContextService;
12 import org.splat.service.StudyService;
14 public class NewStudyAction extends Action {
16 private String title = null;
17 private List<SimulationContext> contelm = null;
18 private String context = null;
20 private static int number = 0;
24 private static final long serialVersionUID = 693943641800113782L;
27 * The injected Study service.
29 private StudyService _studyService;
30 private SimulationContextService _simulationContextService;
32 * Injected scenario service.
34 private ScenarioService _scenarioService;
36 // ==============================================================================================================================
38 // ==============================================================================================================================
40 // Fill the values of the drop-down list.
41 public String doInitialize() {
43 // get the list of the simulation contexts of the study
44 contelm = getSimulationContextService().getSimulationContextList();
46 // set the default name of the new study
47 ResourceBundle locale = ResourceBundle.getBundle("labels",
48 ApplicationSettings.getCurrentLocale());
49 title = locale.getString("label.study") + " "
50 + String.valueOf(number + 1);
55 public String doCreate() throws Exception {
56 String[] input = context.split(",");
57 int valid = Integer.valueOf(input[0]);
58 String value = ""; // input[1] if exists
60 Study.Properties sprop = new Study.Properties();
62 // Check arguments and creation of the study
65 throw new Exception();
67 value = input[1].trim();
68 if (value.length() == 0)
69 return INPUT; // No need to reinitialize the list of existing products
71 sprop.setTitle(title).setManager(getConnectedUser());
72 sprop.checkValidity();
74 } catch (Exception error) {
75 SimulationContext.Properties cprop = new SimulationContext.Properties();
76 SimulationContextType product = getSimulationContextService()
77 .selectType("product");
78 contelm = getSimulationContextService()
79 .selectSimulationContextsWhere(cprop.setType(product));
80 return INPUT; // Title empty, simply wait for input without error message
83 Study study = getStudyService().createStudy(sprop);
85 // Addition of a default scenario
86 ResourceBundle locale = ResourceBundle.getBundle("labels",
87 ApplicationSettings.getCurrentLocale());
88 Scenario.Properties oprop = new Scenario.Properties();
89 oprop.setTitle(locale.getString("label.scenario") + " 1");
90 getScenarioService().addScenario(study, oprop);
92 // Addition of the entered project context
93 if (valid == 0) { // Input of new project context
94 SimulationContext.Properties cprop = new SimulationContext.Properties();
96 getSimulationContextService().selectType("product"))
98 getStudyService().addProjectContext(study, cprop);
99 } else { // Selection of existing project context
100 SimulationContext context = getSimulationContextService()
101 .selectSimulationContext(valid);
102 getStudyService().addProjectContext(study, context);
104 // Update of the session
106 open(study); // Opens the study,
108 } catch (Exception error) {
109 logger.error("Unable to save the study, reason:", error);
114 // ==============================================================================================================================
115 // Getters and setters
116 // ==============================================================================================================================
118 public String getProjectContext() {
119 // ----------------------------------
123 public List<SimulationContext> getProjectContextValues() {
124 // ---------------------------------------------------------
128 public String getTitle() {
129 // ----------------------------
133 public void setProjectContext(String value) {
134 // --------------------------------------------
135 this.context = value;
138 public void setTitle(String value) {
139 // -----------------------------------
144 * Get the studyService.
146 * @return the studyService
148 public StudyService getStudyService() {
149 return _studyService;
153 * Set the studyService.
155 * @param studyService
156 * the studyService to set
158 public void setStudyService(StudyService studyService) {
159 _studyService = studyService;
163 * Get the simulationContextService.
165 * @return the simulationContextService
167 public SimulationContextService getSimulationContextService() {
168 return _simulationContextService;
172 * Set the simulationContextService.
174 * @param simulationContextService
175 * the simulationContextService to set
177 public void setSimulationContextService(
178 SimulationContextService simulationContextService) {
179 _simulationContextService = simulationContextService;
183 * Get the scenarioService.
184 * @return the scenarioService
186 public ScenarioService getScenarioService() {
187 return _scenarioService;
191 * Set the scenarioService.
192 * @param scenarioService the scenarioService to set
194 public void setScenarioService(ScenarioService scenarioService) {
195 _scenarioService = scenarioService;