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;
55 * Value of the tool bar property.
56 * It can be: none, standard, study, back.
58 private String _toolProperty;
60 // ==============================================================================================================================
62 // ==============================================================================================================================
65 * Fill the values of the drop-down list, and initialize a menu.
69 public String doInitialize() {
71 // get the list of the simulation contexts of the study
72 contelm = getSimulationContextService().getSimulationContextList();
74 // set the default name of the new study
75 ResourceBundle locale = ResourceBundle.getBundle("labels",
76 getApplicationSettings().getCurrentLocale());
77 title = locale.getString("label.study") + " "
78 + String.valueOf(number + 1);
80 setMenuProperty("create");
81 setToolProperty("none");
82 initializationScreenContext(_menuProperty, _toolProperty);
90 * @return SUCCESS if the new study is created, INPUT if project context is not defined, ERROR if failed
92 * if properties of the new study are invalid
94 public String doCreate() throws Exception {
95 String[] input = context.split(",");
96 int valid = Integer.valueOf(input[0]);
97 String value = ""; // input[1] if exists
99 Study.Properties sprop = new Study.Properties();
101 // Check arguments and creation of the study
103 SimulationContext.Properties cprop = new SimulationContext.Properties();
104 SimulationContextType product = getSimulationContextService()
105 .selectType("product");
106 contelm = getSimulationContextService()
107 .selectSimulationContextsWhere(cprop.setType(product));
108 return INPUT; // Title empty, simply wait for input without error message
111 value = input[1].trim();
112 if (value.length() == 0) {
113 setMenuProperty("create");
114 initializationScreenContext(_menuProperty);
115 return INPUT; // No need to reinitialize the list of existing products
118 sprop.setTitle(title).setManager(getConnectedUser());
119 sprop.checkValidity();
120 sprop.disableCheck();
122 // Addition of a default scenario
123 ResourceBundle locale = ResourceBundle.getBundle("labels",
124 getApplicationSettings().getCurrentLocale());
125 Scenario.Properties oprop = new Scenario.Properties();
126 oprop.setTitle(locale.getString("label.scenario") + " 1");
128 // Addition of the entered project context
129 SimulationContext.Properties cprop = new SimulationContext.Properties();
130 if (valid == 0) { // Input of new project context
132 getSimulationContextService().selectType("product"))
134 } else { // Selection of existing project context
135 cprop.setIndex(valid);
137 Study study = getScenarioService().createStudy(sprop, oprop, cprop);
138 // Update of the session
140 open(study); // Opens the study,
142 setMenuProperty("study");
143 setToolProperty("none");
144 initializationScreenContext(_menuProperty, _toolProperty);
147 } catch (Exception error) {
148 logger.error("Unable to save the study, reason:", error);
149 setMenuProperty("none");
150 initializationScreenContext(_menuProperty);
155 // ==============================================================================================================================
156 // Getters and setters
157 // ==============================================================================================================================
160 * Get the selected project context for the new study.
161 * @return the selected project context
163 public String getProjectContext() {
168 * Get the list of available project contexts.
169 * @return the list of context values
171 public List<SimulationContext> getProjectContextValues() {
176 * Get the title of the new study.
179 public String getTitle() {
184 * Set the project context for the new study.
185 * @param value the project context value.
187 public void setProjectContext(String value) {
188 this.context = value;
192 * Set the title of the new study.
193 * @param value the title to set
195 public void setTitle(String value) {
200 * Get the simulationContextService.
202 * @return the simulationContextService
204 public SimulationContextService getSimulationContextService() {
205 return _simulationContextService;
209 * Set the simulationContextService.
211 * @param simulationContextService
212 * the simulationContextService to set
214 public void setSimulationContextService(
215 SimulationContextService simulationContextService) {
216 _simulationContextService = simulationContextService;
220 * Get the scenarioService.
222 * @return the scenarioService
224 public ScenarioService getScenarioService() {
225 return _scenarioService;
229 * Set the scenarioService.
231 * @param scenarioService
232 * the scenarioService to set
234 public void setScenarioService(ScenarioService scenarioService) {
235 _scenarioService = scenarioService;
239 * Get the menuProperty.
241 * @return the menuProperty
243 public String getMenuProperty() {
244 return _menuProperty;
248 * Set the menuProperty.
250 * @param menuProperty
251 * the menuProperty to set
253 public void setMenuProperty(String menuProperty) {
254 this._menuProperty = menuProperty;
258 * Get the toolProperty.
259 * @return the toolProperty
261 public String getToolProperty() {
262 return _toolProperty;
266 * Set the toolProperty.
267 * @param toolProperty the toolProperty to set
269 public void setToolProperty(final String toolProperty) {
270 _toolProperty = toolProperty;