import org.splat.dal.bo.som.Study;
import org.splat.service.ScenarioService;
import org.splat.service.SimulationContextService;
-import org.splat.service.StudyService;
+/**
+ * Action for creation of a new study.
+ */
public class NewStudyAction extends Action {
- private String title = null;
- private List<SimulationContext> contelm = null;
- private String context = null;
-
- private static int number = 0;
/**
* Serial version ID.
*/
private static final long serialVersionUID = 693943641800113782L;
+ /**
+ * Sequential number of the new study for appending to its default title.
+ */
+ private static int number = 0;
+
+ /**
+ * Title of the new study.
+ */
+ private String title = null;
+ /**
+ * List of available project contexts for selection for the new study.
+ */
+ private List<SimulationContext> contelm = null;
+ /**
+ * Project context.
+ */
+ private String context = null;
/**
- * The injected Study service.
+ * Injected simulation context service.
*/
- private StudyService _studyService;
private SimulationContextService _simulationContextService;
/**
* Injected scenario service.
*/
private ScenarioService _scenarioService;
-
+
/**
- * Value of the menu property.
- * It can be: none, create, open, study, knowledge, sysadmin, help.
+ * Value of the menu property. It can be: none, create, open, study, knowledge, sysadmin, help.
*/
private String _menuProperty;
+
+ /**
+ * Value of the tool bar property.
+ * It can be: none, standard, study, back.
+ */
+ private String _toolProperty;
+
+ /**
+ * Value of the left menu property.
+ * It can be: open, study, knowledge, scenario.
+ */
+ private String _leftMenuProperty;
// ==============================================================================================================================
// Action methods
// ==============================================================================================================================
- // Fill the values of the drop-down list.
+ /**
+ * Fill the values of the drop-down list, and initialize a menu.
+ *
+ * @return SUCCESS
+ */
public String doInitialize() {
// get the list of the simulation contexts of the study
// set the default name of the new study
ResourceBundle locale = ResourceBundle.getBundle("labels",
- ApplicationSettings.getCurrentLocale());
+ getApplicationSettings().getCurrentLocale());
title = locale.getString("label.study") + " "
+ String.valueOf(number + 1);
-
+
setMenuProperty("create");
- initializationScreenContext(_menuProperty);
+ setToolProperty("none");
+ setLeftMenuProperty("open");
+ initializationFullScreenContext(_menuProperty, _toolProperty, _leftMenuProperty);
return SUCCESS;
}
+ /**
+ * Create a new study.
+ *
+ * @return SUCCESS if the new study is created, INPUT if project context is not defined, ERROR if failed
+ * @throws Exception
+ * if properties of the new study are invalid
+ */
public String doCreate() throws Exception {
String[] input = context.split(",");
int valid = Integer.valueOf(input[0]);
Study.Properties sprop = new Study.Properties();
// Check arguments and creation of the study
- try {
- if (valid == -1)
- throw new Exception();
- if (valid == 0) {
- value = input[1].trim();
- if (value.length() == 0) {
-
- setMenuProperty("create");
- initializationScreenContext(_menuProperty);
-
- return INPUT; // No need to reinitialize the list of existing products
- }
- }
- sprop.setTitle(title).setManager(getConnectedUser());
- sprop.checkValidity();
- sprop.disableCheck();
- } catch (Exception error) {
+ if (valid == -1) {
SimulationContext.Properties cprop = new SimulationContext.Properties();
SimulationContextType product = getSimulationContextService()
.selectType("product");
contelm = getSimulationContextService()
.selectSimulationContextsWhere(cprop.setType(product));
-
- setMenuProperty("create");
- initializationScreenContext(_menuProperty);
-
return INPUT; // Title empty, simply wait for input without error message
}
+ if (valid == 0) {
+ value = input[1].trim();
+ if (value.length() == 0) {
+ setMenuProperty("create");
+ initializationScreenContext(_menuProperty);
+ return INPUT; // No need to reinitialize the list of existing products
+ }
+ }
+ sprop.setTitle(title).setManager(getConnectedUser());
+ sprop.checkValidity();
+ sprop.disableCheck();
try {
- Study study = getStudyService().createStudy(sprop);
-
// Addition of a default scenario
ResourceBundle locale = ResourceBundle.getBundle("labels",
- ApplicationSettings.getCurrentLocale());
+ getApplicationSettings().getCurrentLocale());
Scenario.Properties oprop = new Scenario.Properties();
oprop.setTitle(locale.getString("label.scenario") + " 1");
- getScenarioService().addScenario(study, oprop);
// Addition of the entered project context
+ SimulationContext.Properties cprop = new SimulationContext.Properties();
if (valid == 0) { // Input of new project context
- SimulationContext.Properties cprop = new SimulationContext.Properties();
cprop.setType(
getSimulationContextService().selectType("product"))
.setValue(value);
- getStudyService().addProjectContext(study, cprop);
} else { // Selection of existing project context
- SimulationContext context = getSimulationContextService()
- .selectSimulationContext(valid);
- getStudyService().addProjectContext(study, context);
+ cprop.setIndex(valid);
}
+ Study study = getScenarioService().createStudy(sprop, oprop, cprop);
// Update of the session
number += 1;
open(study); // Opens the study,
-
+
setMenuProperty("study");
- initializationScreenContext(_menuProperty);
-
+ setToolProperty("none");
+ setLeftMenuProperty("open");
+ initializationFullScreenContext(_menuProperty, _toolProperty, _leftMenuProperty);
+
return SUCCESS;
} catch (Exception error) {
logger.error("Unable to save the study, reason:", error);
// Getters and setters
// ==============================================================================================================================
+ /**
+ * Get the selected project context for the new study.
+ * @return the selected project context
+ */
public String getProjectContext() {
- // ----------------------------------
return context;
}
+ /**
+ * Get the list of available project contexts.
+ * @return the list of context values
+ */
public List<SimulationContext> getProjectContextValues() {
- // ---------------------------------------------------------
return contelm;
}
+ /**
+ * Get the title of the new study.
+ * @return the title
+ */
public String getTitle() {
- // ----------------------------
return title;
}
- public void setProjectContext(String value) {
- // --------------------------------------------
- this.context = value;
- }
-
- public void setTitle(String value) {
- // -----------------------------------
- this.title = value;
- }
-
/**
- * Get the studyService.
- *
- * @return the studyService
+ * Set the project context for the new study.
+ * @param value the project context value.
*/
- public StudyService getStudyService() {
- return _studyService;
+ public void setProjectContext(String value) {
+ this.context = value;
}
/**
- * Set the studyService.
- *
- * @param studyService
- * the studyService to set
+ * Set the title of the new study.
+ * @param value the title to set
*/
- public void setStudyService(StudyService studyService) {
- _studyService = studyService;
+ public void setTitle(String value) {
+ this.title = value;
}
/**
/**
* Get the scenarioService.
+ *
* @return the scenarioService
*/
public ScenarioService getScenarioService() {
/**
* Set the scenarioService.
- * @param scenarioService the scenarioService to set
+ *
+ * @param scenarioService
+ * the scenarioService to set
*/
public void setScenarioService(ScenarioService scenarioService) {
_scenarioService = scenarioService;
}
-
+
/**
* Get the menuProperty.
+ *
* @return the menuProperty
*/
public String getMenuProperty() {
/**
* Set the menuProperty.
- * @param menuProperty the menuProperty to set
+ *
+ * @param menuProperty
+ * the menuProperty to set
*/
public void setMenuProperty(String menuProperty) {
this._menuProperty = menuProperty;
}
+
+ /**
+ * Get the toolProperty.
+ * @return the toolProperty
+ */
+ public String getToolProperty() {
+ return _toolProperty;
+ }
+
+ /**
+ * Set the toolProperty.
+ * @param toolProperty the toolProperty to set
+ */
+ public void setToolProperty(final String toolProperty) {
+ _toolProperty = toolProperty;
+ }
+
+ /**
+ * Get the leftMenuProperty.
+ * @return the leftMenuProperty
+ */
+ public String getLeftMenuProperty() {
+ return _leftMenuProperty;
+ }
+
+ /**
+ * Set the leftMenuProperty.
+ * @param leftMenuProperty the leftMenuProperty to set
+ */
+ public void setLeftMenuProperty(final String leftMenuProperty) {
+ _leftMenuProperty = leftMenuProperty;
+ }
}
\ No newline at end of file