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.kernel.InvalidPropertyException;
11 import org.splat.kernel.MissedPropertyException;
12 import org.splat.kernel.MultiplyDefinedException;
13 import org.splat.service.ScenarioService;
14 import org.splat.service.SimulationContextService;
17 * Action for creation of a new study.
19 public class NewStudyAction extends Action {
24 private static final long serialVersionUID = 693943641800113782L;
26 * Sequential number of the new study for appending to its default title.
28 private static int number = 0;
31 * Title of the new study.
33 private String _title = null;
35 * List of available project contexts for selection for the new study.
37 private transient List<SimulationContext> _contelm = null;
41 private String _projectContext = null;
44 * Injected simulation context service.
46 private SimulationContextService _simulationContextService;
48 * Injected scenario service.
50 private ScenarioService _scenarioService;
53 * Value of the menu property. It can be: none, create, open, study, knowledge, sysadmin, help.
55 private String _menuProperty;
58 * Value of the tool bar property. It can be: none, standard, study, back.
60 private String _toolProperty;
63 * Value of the left menu property. It can be: open, study, knowledge, scenario.
65 private String _leftMenuProperty;
67 // ==============================================================================================================================
69 // ==============================================================================================================================
72 * Fill the values of the drop-down list, and initialize a menu.
76 public String doInitialize() {
78 // get the list of the simulation contexts of the study
79 _contelm = getSimulationContextService().getSimulationContextList();
81 // set the default name of the new study
82 ResourceBundle locale = ResourceBundle.getBundle("labels",
83 getApplicationSettings().getCurrentLocale());
84 _title = locale.getString("label.study") + " "
85 + String.valueOf(number + 1);
87 setMenuProperty("create");
88 setToolProperty("none");
89 setLeftMenuProperty("open");
90 initializationFullScreenContext(_menuProperty, _toolProperty,
99 * @return SUCCESS if the new study is created, INPUT if project context is not defined, ERROR if failed
100 * @throws InvalidPropertyException
101 * if some property has invalid value
102 * @throws MultiplyDefinedException
103 * if some property is defined several times
104 * @throws MissedPropertyException
105 * if properties of the new study are invalid
107 public String doCreate() throws InvalidPropertyException,
108 MissedPropertyException, MultiplyDefinedException {
109 String[] input = _projectContext.split(",");
110 int valid = Integer.valueOf(input[0]);
111 String value = ""; // input[1] if exists
113 Study.Properties sprop = new Study.Properties();
115 // Check arguments and creation of the study
117 SimulationContext.Properties cprop = new SimulationContext.Properties();
118 SimulationContextType product = getSimulationContextService()
119 .selectType("product");
120 _contelm = getSimulationContextService()
121 .selectSimulationContextsWhere(cprop.setType(product));
122 return INPUT; // Title empty, simply wait for input without error message
125 value = input[1].trim();
126 if (value.length() == 0) {
127 setMenuProperty("create");
128 initializationScreenContext(_menuProperty);
129 return INPUT; // No need to reinitialize the list of existing products
132 sprop.setTitle(_title).setManager(getConnectedUser());
133 sprop.checkValidity();
134 sprop.disableCheck();
136 // Addition of a default scenario
137 ResourceBundle locale = ResourceBundle.getBundle("labels",
138 getApplicationSettings().getCurrentLocale());
139 Scenario.Properties oprop = new Scenario.Properties();
140 oprop.setTitle(locale.getString("label.scenario") + " 1");
142 // Addition of the entered project context
143 SimulationContext.Properties cprop = new SimulationContext.Properties();
144 if (valid == 0) { // Input of new project context
146 getSimulationContextService().selectType("product"))
148 } else { // Selection of existing project context
149 cprop.setIndex(valid);
151 Study study = getScenarioService().createStudy(sprop, oprop, cprop);
152 // Update of the session
154 open(study); // Opens the study,
156 setMenuProperty("study");
157 setToolProperty("none");
158 setLeftMenuProperty("open");
159 initializationFullScreenContext(_menuProperty, _toolProperty,
163 } catch (Exception error) {
164 LOG.error("Unable to save the study, reason:", error);
165 setMenuProperty("none");
166 initializationScreenContext(_menuProperty);
171 // ==============================================================================================================================
172 // Getters and setters
173 // ==============================================================================================================================
176 * Get the selected project context for the new study.
178 * @return the selected project context
180 public String getProjectContext() {
181 return _projectContext;
185 * Get the list of available project contexts.
187 * @return the list of context values
189 public List<SimulationContext> getProjectContextValues() {
194 * Get the title of the new study.
198 public String getTitle() {
203 * Set the project context for the new study.
206 * the project context value.
208 public void setProjectContext(final String value) {
209 this._projectContext = value;
213 * Set the title of the new study.
218 public void setTitle(final String value) {
223 * Get the simulationContextService.
225 * @return the simulationContextService
227 public SimulationContextService getSimulationContextService() {
228 return _simulationContextService;
232 * Set the simulationContextService.
234 * @param simulationContextService
235 * the simulationContextService to set
237 public void setSimulationContextService(
238 final SimulationContextService simulationContextService) {
239 _simulationContextService = simulationContextService;
243 * Get the scenarioService.
245 * @return the scenarioService
247 public ScenarioService getScenarioService() {
248 return _scenarioService;
252 * Set the scenarioService.
254 * @param scenarioService
255 * the scenarioService to set
257 public void setScenarioService(final ScenarioService scenarioService) {
258 _scenarioService = scenarioService;
262 * Get the menuProperty.
264 * @return the menuProperty
266 public String getMenuProperty() {
267 return _menuProperty;
271 * Set the menuProperty.
273 * @param menuProperty
274 * the menuProperty to set
276 public void setMenuProperty(final String menuProperty) {
277 this._menuProperty = menuProperty;
281 * Get the toolProperty.
283 * @return the toolProperty
285 public String getToolProperty() {
286 return _toolProperty;
290 * Set the toolProperty.
292 * @param toolProperty
293 * the toolProperty to set
295 public void setToolProperty(final String toolProperty) {
296 _toolProperty = toolProperty;
300 * Get the leftMenuProperty.
302 * @return the leftMenuProperty
304 public String getLeftMenuProperty() {
305 return _leftMenuProperty;
309 * Set the leftMenuProperty.
311 * @param leftMenuProperty
312 * the leftMenuProperty to set
314 public void setLeftMenuProperty(final String leftMenuProperty) {
315 _leftMenuProperty = leftMenuProperty;