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;
14 * Action for creation of a new study.
16 public class NewStudyAction extends Action {
21 private static final long serialVersionUID = 693943641800113782L;
23 * Sequential number of the new study for appending to its default title.
25 private static int number = 0;
28 * Title of the new study.
30 private String title = null;
32 * List of available project contexts for selection for the new study.
34 private List<SimulationContext> contelm = null;
38 private String context = null;
41 * Injected simulation context service.
43 private SimulationContextService _simulationContextService;
45 * Injected scenario service.
47 private ScenarioService _scenarioService;
50 * Value of the menu property. It can be: none, create, open, study, knowledge, sysadmin, help.
52 private String _menuProperty;
54 // ==============================================================================================================================
56 // ==============================================================================================================================
59 * Fill the values of the drop-down list, and initialize a menu.
63 public String doInitialize() {
65 // get the list of the simulation contexts of the study
66 contelm = getSimulationContextService().getSimulationContextList();
68 // set the default name of the new study
69 ResourceBundle locale = ResourceBundle.getBundle("labels",
70 getApplicationSettings().getCurrentLocale());
71 title = locale.getString("label.study") + " "
72 + String.valueOf(number + 1);
74 setMenuProperty("create");
75 initializationScreenContext(_menuProperty);
83 * @return SUCCESS if the new study is created, INPUT if project context is not defined, ERROR if failed
85 * if properties of the new study are invalid
87 public String doCreate() throws Exception {
88 String[] input = context.split(",");
89 int valid = Integer.valueOf(input[0]);
90 String value = ""; // input[1] if exists
92 Study.Properties sprop = new Study.Properties();
94 // Check arguments and creation of the study
96 SimulationContext.Properties cprop = new SimulationContext.Properties();
97 SimulationContextType product = getSimulationContextService()
98 .selectType("product");
99 contelm = getSimulationContextService()
100 .selectSimulationContextsWhere(cprop.setType(product));
101 return INPUT; // Title empty, simply wait for input without error message
104 value = input[1].trim();
105 if (value.length() == 0) {
106 setMenuProperty("create");
107 initializationScreenContext(_menuProperty);
108 return INPUT; // No need to reinitialize the list of existing products
111 sprop.setTitle(title).setManager(getConnectedUser());
112 sprop.checkValidity();
113 sprop.disableCheck();
115 // Addition of a default scenario
116 ResourceBundle locale = ResourceBundle.getBundle("labels",
117 getApplicationSettings().getCurrentLocale());
118 Scenario.Properties oprop = new Scenario.Properties();
119 oprop.setTitle(locale.getString("label.scenario") + " 1");
121 // Addition of the entered project context
122 SimulationContext.Properties cprop = new SimulationContext.Properties();
123 if (valid == 0) { // Input of new project context
125 getSimulationContextService().selectType("product"))
127 } else { // Selection of existing project context
128 cprop.setIndex(valid);
130 Study study = getScenarioService().createStudy(sprop, oprop, cprop);
131 // Update of the session
133 open(study); // Opens the study,
135 setMenuProperty("study");
136 initializationScreenContext(_menuProperty);
139 } catch (Exception error) {
140 logger.error("Unable to save the study, reason:", error);
141 setMenuProperty("none");
142 initializationScreenContext(_menuProperty);
147 // ==============================================================================================================================
148 // Getters and setters
149 // ==============================================================================================================================
152 * Get the selected project context for the new study.
153 * @return the selected project context
155 public String getProjectContext() {
160 * Get the list of available project contexts.
161 * @return the list of context values
163 public List<SimulationContext> getProjectContextValues() {
168 * Get the title of the new study.
171 public String getTitle() {
176 * Set the project context for the new study.
177 * @param value the project context value.
179 public void setProjectContext(String value) {
180 this.context = value;
184 * Set the title of the new study.
185 * @param value the title to set
187 public void setTitle(String value) {
192 * Get the simulationContextService.
194 * @return the simulationContextService
196 public SimulationContextService getSimulationContextService() {
197 return _simulationContextService;
201 * Set the simulationContextService.
203 * @param simulationContextService
204 * the simulationContextService to set
206 public void setSimulationContextService(
207 SimulationContextService simulationContextService) {
208 _simulationContextService = simulationContextService;
212 * Get the scenarioService.
214 * @return the scenarioService
216 public ScenarioService getScenarioService() {
217 return _scenarioService;
221 * Set the scenarioService.
223 * @param scenarioService
224 * the scenarioService to set
226 public void setScenarioService(ScenarioService scenarioService) {
227 _scenarioService = scenarioService;
231 * Get the menuProperty.
233 * @return the menuProperty
235 public String getMenuProperty() {
236 return _menuProperty;
240 * Set the menuProperty.
242 * @param menuProperty
243 * the menuProperty to set
245 public void setMenuProperty(String menuProperty) {
246 this._menuProperty = menuProperty;