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;
37 * Value of the menu property.
38 * It can be: none, create, open, study, knowledge, sysadmin, help.
40 private String _menuProperty;
42 // ==============================================================================================================================
44 // ==============================================================================================================================
46 // Fill the values of the drop-down list.
47 public String doInitialize() {
49 // get the list of the simulation contexts of the study
50 contelm = getSimulationContextService().getSimulationContextList();
52 // set the default name of the new study
53 ResourceBundle locale = ResourceBundle.getBundle("labels",
54 ApplicationSettings.getCurrentLocale());
55 title = locale.getString("label.study") + " "
56 + String.valueOf(number + 1);
58 setMenuProperty("create");
59 initializationScreenContext(_menuProperty);
64 public String doCreate() throws Exception {
65 String[] input = context.split(",");
66 int valid = Integer.valueOf(input[0]);
67 String value = ""; // input[1] if exists
69 Study.Properties sprop = new Study.Properties();
71 // Check arguments and creation of the study
74 throw new Exception();
76 value = input[1].trim();
77 if (value.length() == 0) {
79 setMenuProperty("create");
80 initializationScreenContext(_menuProperty);
82 return INPUT; // No need to reinitialize the list of existing products
85 sprop.setTitle(title).setManager(getConnectedUser());
86 sprop.checkValidity();
88 } catch (Exception error) {
89 SimulationContext.Properties cprop = new SimulationContext.Properties();
90 SimulationContextType product = getSimulationContextService()
91 .selectType("product");
92 contelm = getSimulationContextService()
93 .selectSimulationContextsWhere(cprop.setType(product));
95 setMenuProperty("create");
96 initializationScreenContext(_menuProperty);
98 return INPUT; // Title empty, simply wait for input without error message
101 Study study = getStudyService().createStudy(sprop);
103 // Addition of a default scenario
104 ResourceBundle locale = ResourceBundle.getBundle("labels",
105 ApplicationSettings.getCurrentLocale());
106 Scenario.Properties oprop = new Scenario.Properties();
107 oprop.setTitle(locale.getString("label.scenario") + " 1");
108 getScenarioService().addScenario(study, oprop);
110 // Addition of the entered project context
111 if (valid == 0) { // Input of new project context
112 SimulationContext.Properties cprop = new SimulationContext.Properties();
114 getSimulationContextService().selectType("product"))
116 getStudyService().addProjectContext(study, cprop);
117 } else { // Selection of existing project context
118 SimulationContext context = getSimulationContextService()
119 .selectSimulationContext(valid);
120 getStudyService().addProjectContext(study, context);
122 // Update of the session
124 open(study); // Opens the study,
126 setMenuProperty("study");
127 initializationScreenContext(_menuProperty);
130 } catch (Exception error) {
131 logger.error("Unable to save the study, reason:", error);
132 setMenuProperty("none");
133 initializationScreenContext(_menuProperty);
138 // ==============================================================================================================================
139 // Getters and setters
140 // ==============================================================================================================================
142 public String getProjectContext() {
143 // ----------------------------------
147 public List<SimulationContext> getProjectContextValues() {
148 // ---------------------------------------------------------
152 public String getTitle() {
153 // ----------------------------
157 public void setProjectContext(String value) {
158 // --------------------------------------------
159 this.context = value;
162 public void setTitle(String value) {
163 // -----------------------------------
168 * Get the studyService.
170 * @return the studyService
172 public StudyService getStudyService() {
173 return _studyService;
177 * Set the studyService.
179 * @param studyService
180 * the studyService to set
182 public void setStudyService(StudyService studyService) {
183 _studyService = studyService;
187 * Get the simulationContextService.
189 * @return the simulationContextService
191 public SimulationContextService getSimulationContextService() {
192 return _simulationContextService;
196 * Set the simulationContextService.
198 * @param simulationContextService
199 * the simulationContextService to set
201 public void setSimulationContextService(
202 SimulationContextService simulationContextService) {
203 _simulationContextService = simulationContextService;
207 * Get the scenarioService.
208 * @return the scenarioService
210 public ScenarioService getScenarioService() {
211 return _scenarioService;
215 * Set the scenarioService.
216 * @param scenarioService the scenarioService to set
218 public void setScenarioService(ScenarioService scenarioService) {
219 _scenarioService = scenarioService;
223 * Get the menuProperty.
224 * @return the menuProperty
226 public String getMenuProperty() {
227 return _menuProperty;
231 * Set the menuProperty.
232 * @param menuProperty the menuProperty to set
234 public void setMenuProperty(String menuProperty) {
235 this._menuProperty = menuProperty;