1 package org.splat.simer;
3 import java.io.IOException;
5 import java.util.ResourceBundle;
7 import org.apache.commons.lang3.StringUtils;
8 import org.splat.dal.bo.som.Scenario;
9 import org.splat.dal.bo.som.SimulationContext;
10 import org.splat.dal.bo.som.SimulationContextType;
11 import org.splat.dal.bo.som.Study;
12 import org.splat.exception.BusinessException;
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;
40 * Selected project context string value.
42 private String _projectContext = null;
44 * Selected project context id.
46 private long _projectContextId = -1;
48 * Injected simulation context service.
50 private SimulationContextService _simulationContextService;
52 * Injected scenario service.
54 private ScenarioService _scenarioService;
56 // ==============================================================================================================================
58 // ==============================================================================================================================
61 * Fill the values of the drop-down list, and initialize a menu.
65 public String doInitialize() {
67 // get the list of the simulation contexts of the study
68 _contelm = getSimulationContextService().getSimulationContextList();
70 // set the default name of the new study
71 if (StringUtils.isBlank(_title)) {
72 _title = getText("label.study") + " " + (number + 1);
75 initializationFullScreenContext(Constants.CREATE_MENU, Constants.NONE,
84 * @return SUCCESS if the new study is created, INPUT if project context is not defined, ERROR if failed
85 * @throws BusinessException
86 * if new study creation is failed
88 * if file operations are failed
90 public String doCreate() throws BusinessException, IOException {
93 // Check arguments and creation of the study
94 if (_projectContextId == -1) {
95 SimulationContext.Properties cprop = new SimulationContext.Properties();
96 SimulationContextType product = getSimulationContextService()
97 .selectType("product");
98 _contelm = getSimulationContextService()
99 .selectSimulationContextsWhere(cprop.setType(product));
100 // Title empty, simply wait for input without error message
103 String value; // if a new project context has to be created
104 if (_projectContextId == 0) {
105 value = _projectContext.trim();
106 if (value.length() == 0) {
107 initializationScreenContext(Constants.CREATE_MENU);
108 // No need to reinitialize the list of existing products
114 if (SUCCESS.equals(res)) {
115 Study.Properties sprop = new Study.Properties();
117 sprop.setTitle(_title).setManager(getConnectedUser());
118 sprop.checkValidity();
119 sprop.disableCheck();
121 // Addition of a default scenario
122 ResourceBundle locale = ResourceBundle.getBundle("labels",
123 getApplicationSettings().getCurrentLocale());
124 Scenario.Properties oprop = new Scenario.Properties();
125 oprop.setTitle(locale.getString("label.scenario") + " 1");
127 // Addition of the entered project context
128 SimulationContext.Properties cprop = new SimulationContext.Properties();
129 if (_projectContextId == 0) { // Input of new project context
130 SimulationContextType product = getSimulationContextService()
131 .selectType("product");
133 SimulationContext testContext = getSimulationContextService()
134 .selectSimulationContext(product, value);
136 if (testContext == null) {
138 getSimulationContextService().selectType(
139 "product")).setValue(value);
141 cprop.setIndex(testContext.getIndex());
143 } else { // Selection of existing project context
144 cprop.setIndex(_projectContextId);
146 Study study = getScenarioService().createStudy(sprop,
148 // Update of the session
150 open(study); // Opens the study,
152 initializationFullScreenContext(Constants.STUDY_MENU,
153 Constants.NONE, Constants.OPEN);
155 } catch (BusinessException error) {
156 LOG.error("Unable to save the study, reason:", error);
157 setErrorCode("message.error.newstudy");
158 initializationScreenContext(Constants.NONE);
170 * @see com.opensymphony.xwork2.ActionSupport#validate()
173 public void validate() {
175 if (LOG.isDebugEnabled()) {
176 LOG.debug("--- validate");
178 if (LOG.isDebugEnabled()) {
179 LOG.debug("======> MKA test");
180 LOG.debug(com.opensymphony.xwork2.ActionContext.getContext()
185 // ==============================================================================================================================
186 // Getters and setters
187 // ==============================================================================================================================
190 * Get the selected project context for the new study.
192 * @return the selected project context
194 public String getProjectContext() {
195 return _projectContext;
199 * Get the list of available project contexts.
201 * @return the list of context values
203 public List<SimulationContext> getProjectContextValues() {
208 * Get the title of the new study.
212 public String getTitle() {
217 * Set the project context for the new study.
220 * the project context value.
222 public void setProjectContext(final String value) {
223 this._projectContext = value;
227 * Set the title of the new study.
232 public void setTitle(final String value) {
237 * Get the simulationContextService.
239 * @return the simulationContextService
241 public SimulationContextService getSimulationContextService() {
242 return _simulationContextService;
246 * Set the simulationContextService.
248 * @param simulationContextService
249 * the simulationContextService to set
251 public void setSimulationContextService(
252 final SimulationContextService simulationContextService) {
253 _simulationContextService = simulationContextService;
257 * Get the scenarioService.
259 * @return the scenarioService
261 public ScenarioService getScenarioService() {
262 return _scenarioService;
266 * Set the scenarioService.
268 * @param scenarioService
269 * the scenarioService to set
271 public void setScenarioService(final ScenarioService scenarioService) {
272 _scenarioService = scenarioService;
276 * Get the projectContextId.
278 * @return the projectContextId
280 public long getProjectContextId() {
281 return _projectContextId;
285 * Set the projectContextId.
287 * @param projectContextId
288 * the projectContextId to set
290 public void setProjectContextId(final long projectContextId) {
291 _projectContextId = projectContextId;