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;
15 import org.splat.wapp.Constants;
18 * Action for creation of a new study.
20 public class NewStudyAction extends Action {
25 private static final long serialVersionUID = 693943641800113782L;
27 * Sequential number of the new study for appending to its default title.
29 private static int number = 0;
32 * Title of the new study.
34 private String _title = null;
36 * List of available project contexts for selection for the new study.
38 private transient List<SimulationContext> _contelm = null;
42 private String _projectContext = null;
45 * Injected simulation context service.
47 private SimulationContextService _simulationContextService;
49 * Injected scenario service.
51 private ScenarioService _scenarioService;
53 // ==============================================================================================================================
55 // ==============================================================================================================================
58 * Fill the values of the drop-down list, and initialize a menu.
62 public String doInitialize() {
64 // get the list of the simulation contexts of the study
65 _contelm = getSimulationContextService().getSimulationContextList();
67 // set the default name of the new study
68 ResourceBundle locale = ResourceBundle.getBundle("labels",
69 getApplicationSettings().getCurrentLocale());
70 _title = locale.getString("label.study") + " "
71 + String.valueOf(number + 1);
73 initializationFullScreenContext(Constants.CREATE_MENU, Constants.NONE,
82 * @return SUCCESS if the new study is created, INPUT if project context is not defined, ERROR if failed
83 * @throws InvalidPropertyException
84 * if some property has invalid value
85 * @throws MultiplyDefinedException
86 * if some property is defined several times
87 * @throws MissedPropertyException
88 * if properties of the new study are invalid
90 public String doCreate() throws InvalidPropertyException,
91 MissedPropertyException, MultiplyDefinedException {
92 String[] input = _projectContext.split(",");
93 int valid = Integer.valueOf(input[0]);
94 String value = ""; // input[1] if exists
96 Study.Properties sprop = new Study.Properties();
98 // Check arguments and creation of the study
100 SimulationContext.Properties cprop = new SimulationContext.Properties();
101 SimulationContextType product = getSimulationContextService()
102 .selectType("product");
103 _contelm = getSimulationContextService()
104 .selectSimulationContextsWhere(cprop.setType(product));
105 return INPUT; // Title empty, simply wait for input without error message
108 value = input[1].trim();
109 if (value.length() == 0) {
110 initializationScreenContext(Constants.CREATE_MENU);
111 return INPUT; // No need to reinitialize the list of existing products
114 sprop.setTitle(_title).setManager(getConnectedUser());
115 sprop.checkValidity();
116 sprop.disableCheck();
118 // Addition of a default scenario
119 ResourceBundle locale = ResourceBundle.getBundle("labels",
120 getApplicationSettings().getCurrentLocale());
121 Scenario.Properties oprop = new Scenario.Properties();
122 oprop.setTitle(locale.getString("label.scenario") + " 1");
124 // Addition of the entered project context
125 SimulationContext.Properties cprop = new SimulationContext.Properties();
127 SimulationContextType product = getSimulationContextService()
128 .selectType("product");
130 SimulationContext testContext = getSimulationContextService().selectSimulationContext(product, value);
132 if (valid == 0) { // Input of new project context
133 if (testContext == null) {
135 getSimulationContextService().selectType("product"))
138 cprop.setIndex(testContext.getIndex());
140 } else { // Selection of existing project context
141 cprop.setIndex(valid);
143 Study study = getScenarioService().createStudy(sprop, oprop, cprop);
144 // Update of the session
146 open(study); // Opens the study,
148 initializationFullScreenContext(Constants.STUDY_MENU,
149 Constants.NONE, Constants.OPEN);
152 } catch (Exception error) {
153 LOG.error("Unable to save the study, reason:", error);
154 setErrorCode("message.error.newstudy");
155 initializationScreenContext(Constants.NONE);
163 * @see com.opensymphony.xwork2.ActionSupport#validate()
166 public void validate() {
168 if( LOG.isDebugEnabled() ) {
169 LOG.debug("--- validate");
171 com.opensymphony.xwork2.ActionContext context =
172 com.opensymphony.xwork2.ActionContext.getContext();
174 if( LOG.isDebugEnabled() ) {
175 LOG.debug("======> MKA test");
176 LOG.debug(context.getName());
180 // ==============================================================================================================================
181 // Getters and setters
182 // ==============================================================================================================================
185 * Get the selected project context for the new study.
187 * @return the selected project context
189 public String getProjectContext() {
190 return _projectContext;
194 * Get the list of available project contexts.
196 * @return the list of context values
198 public List<SimulationContext> getProjectContextValues() {
203 * Get the title of the new study.
207 public String getTitle() {
212 * Set the project context for the new study.
215 * the project context value.
217 public void setProjectContext(final String value) {
218 this._projectContext = value;
222 * Set the title of the new study.
227 public void setTitle(final String value) {
232 * Get the simulationContextService.
234 * @return the simulationContextService
236 public SimulationContextService getSimulationContextService() {
237 return _simulationContextService;
241 * Set the simulationContextService.
243 * @param simulationContextService
244 * the simulationContextService to set
246 public void setSimulationContextService(
247 final SimulationContextService simulationContextService) {
248 _simulationContextService = simulationContextService;
252 * Get the scenarioService.
254 * @return the scenarioService
256 public ScenarioService getScenarioService() {
257 return _scenarioService;
261 * Set the scenarioService.
263 * @param scenarioService
264 * the scenarioService to set
266 public void setScenarioService(final ScenarioService scenarioService) {
267 _scenarioService = scenarioService;