package org.splat.simer;
import java.text.SimpleDateFormat;
+import java.util.Iterator;
+import java.util.List;
import java.util.ResourceBundle;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
import org.splat.dal.bo.kernel.User;
-import org.splat.dal.dao.som.Database;
import org.splat.dal.bo.som.Scenario;
+import org.splat.dal.bo.som.Study;
+import org.splat.kernel.InvalidPropertyException;
import org.splat.service.ProjectElementService;
import org.splat.service.ScenarioService;
import org.splat.som.Step;
import org.splat.som.StepRights;
+import org.splat.wapp.Constants;
public class EditScenarioPropertiesAction extends DisplayStudyStepAction {
- private Scenario myscenario;
- private String lasdate;
- private String subject;
+ /**
+ * Serial version ID.
+ */
+ private static final long serialVersionUID = 4964740932426016171L;
+
+ private transient Scenario _myscenario;
+ private transient String _lasdate;
+ private transient String _subject;
+
+ /**
+ * Title of the selected scenario.
+ */
+ private String _selectedScenarioTitle;
+
+ /**
+ * The Scenario service.
+ */
private ScenarioService _scenarioService;
- private ProjectElementService _projectElementService;
- private static final long serialVersionUID = 4964740932426016171L;
+ /**
+ * The PojectElement service.
+ */
+ private ProjectElementService _projectElementService;
// ==============================================================================================================================
// Action methods
// ==============================================================================================================================
public String doInitialize() {
- // -----------------------------
ResourceBundle label = ResourceBundle.getBundle("labels",
- ApplicationSettings.getCurrentLocale());
+ getApplicationSettings().getCurrentLocale());
ResourceBundle custom = ResourceBundle.getBundle("som",
- ApplicationSettings.getCurrentLocale());
- SimpleDateFormat datstring = new SimpleDateFormat(
- custom.getString("date.format")); // Locale date display format
+ getApplicationSettings().getCurrentLocale());
+ SimpleDateFormat datstring = new SimpleDateFormat(custom
+ .getString("date.format")); // Locale date display format
Step step;
- mystudy = getOpenStudy();
- step = mystudy.getSelectedStep();
- myscenario = (Scenario) step.getOwner(); // The selected step belong to a scenario
- lasdate = datstring.format(myscenario.getLastModificationDate());
- subject = label.getString("label.study") + " " + mystudy.getTitle();
+ _openStudy = getOpenStudy();
+ step = _openStudy.getSelectedStep();
+ _myscenario = (Scenario) step.getOwner(); // The selected step belong to a scenario
+ _lasdate = datstring.format(_myscenario.getLastModificationDate());
+ _subject = label.getString("label.study") + " " + _openStudy.getTitle();
+ _selectedScenarioTitle = _myscenario.getTitle();
+
+ initializationFullScreenContext(Constants.STUDY_MENU,
+ Constants.STUDY_MENU, "true", "back", "open");
return SUCCESS;
}
- public String doCheckin() {
- // --------------------------
- Session connex = Database.getSession();
- Transaction transax = connex.beginTransaction();
+ /**
+ * Mark the scenario as checked in.
+ *
+ * @return SUCCESS
+ * @throws InvalidPropertyException
+ * if scenario is not found in the database
+ */
+ public String doCheckin() throws InvalidPropertyException {
Step step;
- mystudy = getOpenStudy();
- selection = mystudy.getSelection();
- step = mystudy.getSelectedStep();
- myscenario = (Scenario) step.getOwner(); // The selected step belong to a scenario
+ _openStudy = getOpenStudy();
+ _selection = _openStudy.getSelection();
+ step = _openStudy.getSelectedStep();
+ _myscenario = (Scenario) step.getOwner(); // The selected step belong to a scenario
- getScenarioService().checkin(myscenario);
- transax.commit();
+ getScenarioService().checkin(_myscenario.getIndex());
+ // TODO: Do it in the business service after moving to DTO instead of id parameter
+ // or reread the scenario.
+ _myscenario.setUser(null);
+
+ _openStudy.getMenu().refreshGivenStepItem(
+ getProjectElementService().getFirstStep(_myscenario)); // For updating the scenario icon
+
+ if ("true".equals(getWriteAccess())
+ && getUserRights().canCreateDocument()) {
+ setToolProperty(Constants.STUDY_MENU);
+ } else {
+ setToolProperty(Constants.STANDARD_MENU);
+ }
+ initializationFullScreenContext(Constants.STUDY_MENU,
+ getToolProperty(), Constants.STUDY_MENU);
- mystudy.getMenu().refreshGivenStepItem(
- getProjectElementService().getFirstStep(myscenario)); // For updating the scenario icon
return SUCCESS;
}
+ /**
+ * Rename the scenario functionality.
+ * @return SUCCESS
+ */
+ public String doEditScenarioTitle() {
+ OpenStudy openStudy = getOpenStudy();
+ Study study = openStudy.getStudyObject();
+ List<Scenario> scenarios = study.getScenariiList();
+ Iterator<Scenario> iter = scenarios.iterator();
+ for (; iter.hasNext();) {
+ Scenario scenario = iter.next();
+ if (openStudy.getSelectedScenarioId().equals(String.valueOf(scenario.getIndex()))) {
+ scenario.setTitle(getSelectedScenarioTitle());
+ _scenarioService.renameScenario(scenario);
+ }
+ }
+ return SUCCESS;
+ }
+
// ==============================================================================================================================
// Getters
// ==============================================================================================================================
+ /**
+ * Get current scenario editor or author if the scenario is not checked out.
+ *
+ * @return the scenario editor or author
+ */
public User getAuthor() {
- // ------------------------
- if (myscenario.isCheckedout())
- return myscenario.getUser();
- else
- return myscenario.getAuthor();
+ User author;
+ if (_myscenario.isCheckedout()) {
+ author = _myscenario.getUser();
+ } else {
+ author = _myscenario.getAuthor();
+ }
+ return author;
}
public String getLastModificationDate() {
- // ----------------------------------------
- return lasdate;
+ return _lasdate;
}
public StepRights getSelectedStep() {
- // ------------------------------------
- return mystudy.getSelectedStepRights(); // Forget about the step as only step enabling is tested
+ return _openStudy.getSelectedStepRights(); // Forget about the step as only step enabling is tested
}
public String getSubject() {
- // ---------------------------
- return subject;
+ return _subject;
}
- public String getTitle() {
- // -------------------------
- return myscenario.getTitle();
- }
public boolean isCheckedout() {
- // ------------------------------
- return myscenario.isCheckedout();
+ return _myscenario.isCheckedout();
+ }
+
+
+
+ /**
+ * Get the selectedScenarioTitle.
+ * @return the selectedScenarioTitle
+ */
+ public String getSelectedScenarioTitle() {
+ return _selectedScenarioTitle;
+ }
+
+ /**
+ * Set the selectedScenarioTitle.
+ * @param selectedScenarioTitle the selectedScenarioTitle to set
+ */
+ public void setSelectedScenarioTitle(final String selectedScenarioTitle) {
+ _selectedScenarioTitle = selectedScenarioTitle;
}
/**
* @param scenarioService
* the scenarioService to set
*/
- public void setScenarioService(ScenarioService scenarioService) {
+ public void setScenarioService(final ScenarioService scenarioService) {
_scenarioService = scenarioService;
}
* the projectElementService to set
*/
public void setProjectElementService(
- ProjectElementService projectElementService) {
+ final ProjectElementService projectElementService) {
_projectElementService = projectElementService;
}
}
\ No newline at end of file