* the scenario with a new title.
*/
void renameScenario(final Scenario scenario);
+
+ /**
+ * Remove the scenario.
+ *
+ * @param scenarioId -
+ * the id of the scenario to remove.
+ */
+ void removeScenario(final long scenarioId);
}
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.splat.dal.bo.som.Document.Properties;
import org.splat.dal.dao.kernel.RoleDAO;
import org.splat.dal.dao.kernel.UserDAO;
+import org.splat.dal.dao.som.DocumentDAO;
import org.splat.dal.dao.som.KnowledgeElementDAO;
import org.splat.dal.dao.som.KnowledgeElementTypeDAO;
import org.splat.dal.dao.som.ScenarioDAO;
* Injected knowledge element type DAO.
*/
private KnowledgeElementTypeDAO _knowledgeElementTypeDAO;
+
+ /**
+ * Injected document DAO.
+ */
+ private DocumentDAO _documentDAO;
/**
* Injected simulation context service.
public void renameScenario(final Scenario scenario) {
getScenarioDAO().merge(scenario);
}
+
+ /**
+ * {@inheritDoc}
+ * @see org.splat.service.ScenarioService#removeScenario(long)
+ */
+ @Transactional
+ public void removeScenario(final long scenarioId) {
+ Scenario scenario = getScenarioDAO().get(scenarioId);
+ Study study = scenario.getOwnerStudy();
+
+ if (scenario != null && study != null) {
+ getScenarioDAO().delete(scenario);
+
+ // Collect all documents which are published in another scenario
+ // or are previous versions of documents published in another scenario
+ Set<Document> untouched = new HashSet<Document>();
+
+ List<Scenario> otherScenarios = study.getScenariiList();
+ otherScenarios.remove(scenario);
+
+ for (Scenario otherScenario : otherScenarios) {
+ for (Publication publication : otherScenario.getDocums()) {
+ for (Document document = publication.value(); document != null;
+ document = document.getPreviousVersion()) {
+ untouched.add(document);
+ }
+ }
+ }
+
+ // Collect all documents which are published in this scenario
+ // or are previous versions of documents published in this scenario
+ Set<Document> toRemove = new HashSet<Document>();
+ for (Publication publication : scenario.getDocums()) {
+ for (Document document = publication.value(); document != null;
+ document = document.getPreviousVersion()) {
+ toRemove.add(document);
+ }
+ }
+
+ toRemove.removeAll(untouched);
+
+ // Delete all necessary documents
+ for (Document document : toRemove) {
+ _documentDAO.delete(document);
+ }
+ }
+ }
/**
* Get the knowledgeElementDAO.
final KnowledgeElementTypeDAO knowledgeElementTypeDAO) {
_knowledgeElementTypeDAO = knowledgeElementTypeDAO;
}
+
+ /**
+ * Get the documentDAO.
+ * @return the documentDAO
+ */
+ public DocumentDAO getDocumentDAO() {
+ return _documentDAO;
+ }
+
+ /**
+ * Set the documentDAO.
+ * @param documentDAO the documentDAO to set
+ */
+ public void setDocumentDAO(final DocumentDAO documentDAO) {
+ _documentDAO = documentDAO;
+ }
/**
* Get the simulationContextService.
.getProgressState() == ProgressState.inDRAFT)
&& _isauthor;
}
+
+ /**
+ * Check if the user can remove the selected scenario.
+ *
+ * @return true if the user can remove the scenario
+ */
+ public boolean canRemoveScenario() {
+ return (_operand.getProgressState() == ProgressState.inWORK
+ || _operand.getProgressState() == ProgressState.inDRAFT)
+ && _isauthor && _operand.getScenariiList().size() > 1;
+ }
/**
* Check if the user can version the study.
<property name="userService" ref="userService" />
<property name="userDAO" ref="userDAO" />
<property name="roleDAO" ref="roleDAO" />
+ <property name="documentDAO" ref="documentDAO" />
<property name="knowledgeElementTypeDAO"
ref="knowledgeElementTypeDAO" />
<property name="simulationContextService"
* Remove menu item name.
*/
private static final String MNU_NAME_REMOVE_VERSION = "menu.remove.version";
+ /**
+ * Remove scenario menu item name.
+ */
+ private static final String MNU_NAME_REMOVE_SCENARIO = "menu.remove.scenario";
/**
* Rename menu item name.
*/
* Remove as reference action name.
*/
private static final String ACT_REMOVE_AS_REFERENCE = "removeasref-study";
+ /**
+ * Remove scenario action name.
+ */
+ private static final String ACT_REMOVE_SCENARIO = "remove-study";
/**
* Promote the study action name.
*/
/**
* Mark the study as reference.
*/
- markasreference
+ markasreference,
+ /**
+ * Remove selected scenario.
+ */
+ removescenario
};
// Resources relative to studies
*/
protected transient StudyRights _user = null;
+ /**
+ * Specifies if a scenario is selected, hence the "remove scenario" menu item can be enabled.
+ */
+ private boolean _scenarioSlected = false;
+
/**
* Add items which are common for all study popup menus.
*/
.action("add-scenario"));
/*
* addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon( IMG_VERSION).action(ACT_NOT_YET_IMPLEMENTED));
- */
- addSeparator();
- /*
* addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE) .confirmation("message.purge.study")); addItem("export", new
* PopupItem("menu.export") .icon("image.export.png")); // For future needs
- */addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE_VERSION).icon(
- IMG_DELETE).action("remove-study").confirmation(
+ */
+ addItem(Item.removescenario.toString(),
+ new PopupItem(MNU_NAME_REMOVE_SCENARIO)
+ .icon(IMG_DELETE).action("remove-scenario"/*"ACT_REMOVE_SCENARIO"*/)
+ .confirmation("message.delete.scenario"));
+ addSeparator();
+ addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE_VERSION).icon(
+ IMG_DELETE).action(ACT_REMOVE_SCENARIO).confirmation(
"message.delete.study"));
}
res = _user.canRemoveStudyAsReference();
}
break;
+ case removescenario:
+ if(_scenarioSlected) {
+ res = _user.canRemoveScenario();
+ } else {
+ res =false;
+ }
+ break;
default:
res = false;
}
}
}
}
+
+ /**
+ * Set the scenarioSlected.
+ * @param scenarioSlected the scenarioSlected to set
+ */
+ public StudyPopup setScenarioSlected(final boolean scenarioSlected) {
+ _scenarioSlected = scenarioSlected;
+ return this;
+ }
}
/**
_popups.put("streviewable", new ReviewableStudyPopup());
_popups.put("stapprovable", new ApprovableStudyPopup());
+ _popups.put("steditablemarkpublicScenarioSelected",
+ new EditableMarkedStudyPopup(false, false).setScenarioSlected(true));
+ _popups.put("steditableScenarioSelected", new EditableStudyPopup().setScenarioSlected(true));
+ _popups.put("streviewableScenarioSelected", new ReviewableStudyPopup().setScenarioSlected(true));
+ _popups.put("stapprovableScenarioSelected", new ApprovableStudyPopup().setScenarioSlected(true));
+
_popups.put("editable", new EditableDocumentPopup());
_popups.put("notresult", new NotResultDocumentPopupAuthor());
_popups.put("reviewable", new ReviewableDocumentPopupAuthor());
_selection = _openStudy.getSelection();
} else { // Selection of a step of current study
_openStudy.setSelection(_selection);
+ _openStudy.open(getConnectedUser(), _openStudy.getStudyObject()); //needed to refresh pop-up menu
}
// Re-initialization of the properties menu according to the selected step
ProjectElement owner = _openStudy.getSelectedStep().getOwner();
doOpen();
return SUCCESS;
}
+
+ /**
+ * Remove the scenario functionality.
+ *
+ * @return SUCCESS
+ * if the scenario has been successfully removed
+ * ERROR
+ * if the user can not delete the scenario
+ */
+ public String doRemoveScenario() {
+ String res = ERROR;
+ List<Scenario> scenarios = getOpenStudy().getStudyObject().getScenariiList();
+ if (_openStudy.getStudyRights().canRemoveScenario()) {
+ for (Scenario scenario : scenarios) {
+ if (scenario.getIndex() == Long.valueOf(getOpenStudy().getSelectedScenarioId())) {
+ _scenarioService.removeScenario(scenario.getIndex());
+ res = SUCCESS;
+ }
+ }
+ }
+ _openStudy.setSelection("0.1"); // Default selection
+ return res;
+ }
// ==============================================================================================================================
// Getters
.getRevisionPattern());
_cuser = user; // May be null if nobody connected
+ if(!study.equals(_mystudy)) {
+ _selection = "0.1"; // Default selection
+ }
_mystudy = study;
- _selection = "0.1"; // Default selection
_selecdoc = null;
// Preparation of the display
_description = _mystudy.getDescription();
_involving = new ArrayList<Step>(1);
_context = new ArrayList<SimulationContextFacade>();
- _ustep = getProjectElementService().getFirstStep(_mystudy);
+ if (_selection.equals("0.1")) {
+ _ustep = getProjectElementService().getFirstStep(_mystudy);
+ }
_ustep.setActor(_cuser);
_involving.add(_ustep);
for (Iterator<SimulationContext> i = _ustep.getAllSimulationContexts()
_popup = getApplicationSettings().getPopupMenu(
"steditablemarkprivate");
} else {
- if (_mystudy.getProgressState() == ProgressState.inWORK) {
- _popup = getApplicationSettings().getPopupMenu(
- "steditable");
- } else if (_mystudy.getProgressState() == ProgressState.inDRAFT) {
- _popup = getApplicationSettings().getPopupMenu(
- "streviewable");
- } else if (_mystudy.getProgressState() == ProgressState.inCHECK) {
- _popup = getApplicationSettings().getPopupMenu(
- "stapprovable");
- } else { // APPROVED
- _popup = getApplicationSettings().getPopupMenu(
- "steditablemarkpublic");
+ String key = null;
+ switch(_mystudy.getProgressState()) {
+ case inWORK:
+ key = "steditable";
+ break;
+ case inDRAFT:
+ key = "streviewable";
+ break;
+ case inCHECK:
+ key = "stapprovable";
+ break;
+ default: // APPROVED
+ key = "steditablemarkpublic";
+ break;
+ }
+ if(Long.valueOf(getSelectedScenarioId()) != 0) {
+ key += "ScenarioSelected";
}
+ _popup = getApplicationSettings().getPopupMenu(key);
}
}
page.displaystudy
</result>
</action>
-
<action name="valid-rename" class="editScenarioPropertiesAction"
method="editScenarioTitle">
<interceptor-ref name="simanBasicStack" />
open-study
</result>
</action>
-
+ <action name="remove-scenario" class="editScenarioPropertiesAction"
+ method="removeScenario">
+ <result name="success" type="redirectAction">
+ open-study
+ </result>
+ <result name="error" type="redirectAction">
+ step-study
+ </result>
+ </action>
<action name="add-scenario" class="newScenarioAction"
method="initialize">
<result name="success" type="tiles">
step-study
</result>
<result name="success" type="redirectAction">
- step-study
+ open-study
</result>
<result name="error" type="tiles">page.displaystudy</result>
</action>