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;
61 * Value of the left menu property.
62 * It can be: open, study, knowledge, scenario.
64 private String _leftMenuProperty;
66 // ==============================================================================================================================
68 // ==============================================================================================================================
71 * Fill the values of the drop-down list, and initialize a menu.
75 public String doInitialize() {
77 // get the list of the simulation contexts of the study
78 contelm = getSimulationContextService().getSimulationContextList();
80 // set the default name of the new study
81 ResourceBundle locale = ResourceBundle.getBundle("labels",
82 getApplicationSettings().getCurrentLocale());
83 title = locale.getString("label.study") + " "
84 + String.valueOf(number + 1);
86 setMenuProperty("create");
87 setToolProperty("none");
88 setLeftMenuProperty("open");
89 initializationFullScreenContext(_menuProperty, _toolProperty, _leftMenuProperty);
97 * @return SUCCESS if the new study is created, INPUT if project context is not defined, ERROR if failed
99 * if properties of the new study are invalid
101 public String doCreate() throws Exception {
102 String[] input = context.split(",");
103 int valid = Integer.valueOf(input[0]);
104 String value = ""; // input[1] if exists
106 Study.Properties sprop = new Study.Properties();
108 // Check arguments and creation of the study
110 SimulationContext.Properties cprop = new SimulationContext.Properties();
111 SimulationContextType product = getSimulationContextService()
112 .selectType("product");
113 contelm = getSimulationContextService()
114 .selectSimulationContextsWhere(cprop.setType(product));
115 return INPUT; // Title empty, simply wait for input without error message
118 value = input[1].trim();
119 if (value.length() == 0) {
120 setMenuProperty("create");
121 initializationScreenContext(_menuProperty);
122 return INPUT; // No need to reinitialize the list of existing products
125 sprop.setTitle(title).setManager(getConnectedUser());
126 sprop.checkValidity();
127 sprop.disableCheck();
129 // Addition of a default scenario
130 ResourceBundle locale = ResourceBundle.getBundle("labels",
131 getApplicationSettings().getCurrentLocale());
132 Scenario.Properties oprop = new Scenario.Properties();
133 oprop.setTitle(locale.getString("label.scenario") + " 1");
135 // Addition of the entered project context
136 SimulationContext.Properties cprop = new SimulationContext.Properties();
137 if (valid == 0) { // Input of new project context
139 getSimulationContextService().selectType("product"))
141 } else { // Selection of existing project context
142 cprop.setIndex(valid);
144 Study study = getScenarioService().createStudy(sprop, oprop, cprop);
145 // Update of the session
147 open(study); // Opens the study,
149 setMenuProperty("study");
150 setToolProperty("none");
151 setLeftMenuProperty("open");
152 initializationFullScreenContext(_menuProperty, _toolProperty, _leftMenuProperty);
155 } catch (Exception error) {
156 logger.error("Unable to save the study, reason:", error);
157 setMenuProperty("none");
158 initializationScreenContext(_menuProperty);
163 // ==============================================================================================================================
164 // Getters and setters
165 // ==============================================================================================================================
168 * Get the selected project context for the new study.
169 * @return the selected project context
171 public String getProjectContext() {
176 * Get the list of available project contexts.
177 * @return the list of context values
179 public List<SimulationContext> getProjectContextValues() {
184 * Get the title of the new study.
187 public String getTitle() {
192 * Set the project context for the new study.
193 * @param value the project context value.
195 public void setProjectContext(String value) {
196 this.context = value;
200 * Set the title of the new study.
201 * @param value the title to set
203 public void setTitle(String value) {
208 * Get the simulationContextService.
210 * @return the simulationContextService
212 public SimulationContextService getSimulationContextService() {
213 return _simulationContextService;
217 * Set the simulationContextService.
219 * @param simulationContextService
220 * the simulationContextService to set
222 public void setSimulationContextService(
223 SimulationContextService simulationContextService) {
224 _simulationContextService = simulationContextService;
228 * Get the scenarioService.
230 * @return the scenarioService
232 public ScenarioService getScenarioService() {
233 return _scenarioService;
237 * Set the scenarioService.
239 * @param scenarioService
240 * the scenarioService to set
242 public void setScenarioService(ScenarioService scenarioService) {
243 _scenarioService = scenarioService;
247 * Get the menuProperty.
249 * @return the menuProperty
251 public String getMenuProperty() {
252 return _menuProperty;
256 * Set the menuProperty.
258 * @param menuProperty
259 * the menuProperty to set
261 public void setMenuProperty(String menuProperty) {
262 this._menuProperty = menuProperty;
266 * Get the toolProperty.
267 * @return the toolProperty
269 public String getToolProperty() {
270 return _toolProperty;
274 * Set the toolProperty.
275 * @param toolProperty the toolProperty to set
277 public void setToolProperty(final String toolProperty) {
278 _toolProperty = toolProperty;
282 * Get the leftMenuProperty.
283 * @return the leftMenuProperty
285 public String getLeftMenuProperty() {
286 return _leftMenuProperty;
290 * Set the leftMenuProperty.
291 * @param leftMenuProperty the leftMenuProperty to set
293 public void setLeftMenuProperty(final String leftMenuProperty) {
294 _leftMenuProperty = leftMenuProperty;