From d2195ee45281d74241f9cd1362d79e2dd24c0ad2 Mon Sep 17 00:00:00 2001 From: mka Date: Thu, 19 Sep 2013 07:33:59 +0000 Subject: [PATCH] Remove the scenario functionality is implemented --- .../org/splat/service/ScenarioService.java | 8 +++ .../splat/service/ScenarioServiceImpl.java | 70 +++++++++++++++++++ .../src/org/splat/som/StudyRights.java | 11 +++ .../src/spring/businessServiceContext.xml | 1 + .../org/splat/simer/ApplicationSettings.java | 54 ++++++++++++-- .../splat/simer/DisplayStudyStepAction.java | 1 + .../simer/EditScenarioPropertiesAction.java | 23 ++++++ .../Siman/src/org/splat/simer/OpenStudy.java | 38 ++++++---- Workspace/Siman/src/struts.xml | 13 +++- 9 files changed, 196 insertions(+), 23 deletions(-) diff --git a/Workspace/Siman-Common/src/org/splat/service/ScenarioService.java b/Workspace/Siman-Common/src/org/splat/service/ScenarioService.java index 4012fa9..bb37542 100644 --- a/Workspace/Siman-Common/src/org/splat/service/ScenarioService.java +++ b/Workspace/Siman-Common/src/org/splat/service/ScenarioService.java @@ -293,4 +293,12 @@ public interface ScenarioService { * 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); } diff --git a/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java index d1a7f1b..f75f2d7 100644 --- a/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java @@ -14,6 +14,7 @@ import java.util.ArrayList; 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; @@ -47,6 +48,7 @@ import org.splat.dal.bo.som.ValidationCycle; 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; @@ -148,6 +150,11 @@ public class ScenarioServiceImpl implements ScenarioService { * Injected knowledge element type DAO. */ private KnowledgeElementTypeDAO _knowledgeElementTypeDAO; + + /** + * Injected document DAO. + */ + private DocumentDAO _documentDAO; /** * Injected simulation context service. @@ -1375,6 +1382,53 @@ public class ScenarioServiceImpl implements ScenarioService { 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 untouched = new HashSet(); + + List 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 toRemove = new HashSet(); + 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. @@ -1549,6 +1603,22 @@ public class ScenarioServiceImpl implements ScenarioService { 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. diff --git a/Workspace/Siman-Common/src/org/splat/som/StudyRights.java b/Workspace/Siman-Common/src/org/splat/som/StudyRights.java index 62c0a1e..e869784 100644 --- a/Workspace/Siman-Common/src/org/splat/som/StudyRights.java +++ b/Workspace/Siman-Common/src/org/splat/som/StudyRights.java @@ -152,6 +152,17 @@ public class StudyRights { .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. diff --git a/Workspace/Siman-Common/src/spring/businessServiceContext.xml b/Workspace/Siman-Common/src/spring/businessServiceContext.xml index 7f911ca..c38f3d4 100644 --- a/Workspace/Siman-Common/src/spring/businessServiceContext.xml +++ b/Workspace/Siman-Common/src/spring/businessServiceContext.xml @@ -100,6 +100,7 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> + 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 diff --git a/Workspace/Siman/src/org/splat/simer/OpenStudy.java b/Workspace/Siman/src/org/splat/simer/OpenStudy.java index cad212a..946317d 100644 --- a/Workspace/Siman/src/org/splat/simer/OpenStudy.java +++ b/Workspace/Siman/src/org/splat/simer/OpenStudy.java @@ -124,8 +124,10 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices { .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 @@ -135,7 +137,9 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices { _description = _mystudy.getDescription(); _involving = new ArrayList(1); _context = new ArrayList(); - _ustep = getProjectElementService().getFirstStep(_mystudy); + if (_selection.equals("0.1")) { + _ustep = getProjectElementService().getFirstStep(_mystudy); + } _ustep.setActor(_cuser); _involving.add(_ustep); for (Iterator i = _ustep.getAllSimulationContexts() @@ -165,19 +169,25 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices { _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); } } diff --git a/Workspace/Siman/src/struts.xml b/Workspace/Siman/src/struts.xml index 172b88f..250e023 100644 --- a/Workspace/Siman/src/struts.xml +++ b/Workspace/Siman/src/struts.xml @@ -364,7 +364,6 @@ page.displaystudy - @@ -373,7 +372,15 @@ open-study - + + + open-study + + + step-study + + @@ -412,7 +419,7 @@ step-study - step-study + open-study page.displaystudy -- 2.39.2