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 setErrorCode("message.error.newstudy");
166 setMenuProperty("none");
167 initializationScreenContext(_menuProperty);
172 // ==============================================================================================================================
173 // Getters and setters
174 // ==============================================================================================================================
177 * Get the selected project context for the new study.
179 * @return the selected project context
181 public String getProjectContext() {
182 return _projectContext;
186 * Get the list of available project contexts.
188 * @return the list of context values
190 public List<SimulationContext> getProjectContextValues() {
195 * Get the title of the new study.
199 public String getTitle() {
204 * Set the project context for the new study.
207 * the project context value.
209 public void setProjectContext(final String value) {
210 this._projectContext = value;
214 * Set the title of the new study.
219 public void setTitle(final String value) {
224 * Get the simulationContextService.
226 * @return the simulationContextService
228 public SimulationContextService getSimulationContextService() {
229 return _simulationContextService;
233 * Set the simulationContextService.
235 * @param simulationContextService
236 * the simulationContextService to set
238 public void setSimulationContextService(
239 final SimulationContextService simulationContextService) {
240 _simulationContextService = simulationContextService;
244 * Get the scenarioService.
246 * @return the scenarioService
248 public ScenarioService getScenarioService() {
249 return _scenarioService;
253 * Set the scenarioService.
255 * @param scenarioService
256 * the scenarioService to set
258 public void setScenarioService(final ScenarioService scenarioService) {
259 _scenarioService = scenarioService;
263 * Get the menuProperty.
265 * @return the menuProperty
267 public String getMenuProperty() {
268 return _menuProperty;
272 * Set the menuProperty.
274 * @param menuProperty
275 * the menuProperty to set
277 public void setMenuProperty(final String menuProperty) {
278 this._menuProperty = menuProperty;
282 * Get the toolProperty.
284 * @return the toolProperty
286 public String getToolProperty() {
287 return _toolProperty;
291 * Set the toolProperty.
293 * @param toolProperty
294 * the toolProperty to set
296 public void setToolProperty(final String toolProperty) {
297 _toolProperty = toolProperty;
301 * Get the leftMenuProperty.
303 * @return the leftMenuProperty
305 public String getLeftMenuProperty() {
306 return _leftMenuProperty;
310 * Set the leftMenuProperty.
312 * @param leftMenuProperty
313 * the leftMenuProperty to set
315 public void setLeftMenuProperty(final String leftMenuProperty) {
316 _leftMenuProperty = leftMenuProperty;