Salome HOME
Remove the scenario functionality is implemented
authormka <mka@opencascade.com>
Thu, 19 Sep 2013 07:33:59 +0000 (07:33 +0000)
committermka <mka@opencascade.com>
Thu, 19 Sep 2013 07:33:59 +0000 (07:33 +0000)
Workspace/Siman-Common/src/org/splat/service/ScenarioService.java
Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java
Workspace/Siman-Common/src/org/splat/som/StudyRights.java
Workspace/Siman-Common/src/spring/businessServiceContext.xml
Workspace/Siman/src/org/splat/simer/ApplicationSettings.java
Workspace/Siman/src/org/splat/simer/DisplayStudyStepAction.java
Workspace/Siman/src/org/splat/simer/EditScenarioPropertiesAction.java
Workspace/Siman/src/org/splat/simer/OpenStudy.java
Workspace/Siman/src/struts.xml

index 4012fa94c87daa0a140827ec088fb78ce965697e..bb375424d69218b03218d6767017fb4448a3ec32 100644 (file)
@@ -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);
 }
index d1a7f1b555ebdeadbb3ffbd50dd4adfd5d7391f7..f75f2d7146f71d92c57ff046a23c59b61a4a6bf2 100644 (file)
@@ -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<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.
@@ -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.
index 62c0a1e1bb7e90e226892a9993f87b24b1eb64db..e869784cefaf14a89a618f5f48c5d58495d1a48d 100644 (file)
@@ -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.
index 7f911caf3e2cd82660b91501086801563da63b05..c38f3d476f66ced88f668f9d2b5af5222ca6529e 100644 (file)
@@ -100,6 +100,7 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
                <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"
index e489c5d57aa993150bdf32cc47bff30f71d509ad..c9a84a2b776de03fb59c63334c09557fa0274140 100644 (file)
@@ -250,6 +250,10 @@ public class ApplicationSettings {
         * 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.
         */
@@ -290,6 +294,10 @@ public class ApplicationSettings {
         * 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.
         */
@@ -529,7 +537,11 @@ public class ApplicationSettings {
                /**
                 * Mark the study as reference.
                 */
-               markasreference
+               markasreference,
+               /**
+                * Remove selected scenario.
+                */
+               removescenario
        };
 
        // Resources relative to studies
@@ -542,6 +554,11 @@ public class ApplicationSettings {
                 */
                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.
                 */
@@ -555,13 +572,16 @@ public class ApplicationSettings {
                                        .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"));
                }
 
@@ -611,6 +631,13 @@ public class ApplicationSettings {
                                                        res = _user.canRemoveStudyAsReference();
                                                }
                                                break;
+                                       case removescenario:
+                                               if(_scenarioSlected) {
+                                                       res = _user.canRemoveScenario();
+                                               } else {
+                                                       res =false;
+                                               }
+                                               break;
                                        default:
                                                res = false;
                                }
@@ -636,6 +663,15 @@ public class ApplicationSettings {
                                }
                        }
                }
+
+               /**
+                * Set the scenarioSlected.
+                * @param scenarioSlected the scenarioSlected to set
+                */
+               public StudyPopup setScenarioSlected(final boolean scenarioSlected) {
+                       _scenarioSlected = scenarioSlected;
+                       return this;
+               }
        }
 
        /**
@@ -1330,6 +1366,12 @@ public class ApplicationSettings {
                _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());
index 8aa9106f3c7a6861e9e1f98625394cf0e9b691cf..cec8daafba68035379211111e00cd8c1a76083b7 100644 (file)
@@ -121,6 +121,7 @@ public class DisplayStudyStepAction extends AbstractDisplayAction {
                        _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();
index 2743e79ddeaecdd81841c4bb3e8e7151a85386cf..ea608341c8c642d47e65ae9416ddcd44210f93c7 100644 (file)
@@ -130,6 +130,29 @@ public class EditScenarioPropertiesAction extends DisplayStudyStepAction {
                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
index cad212ae8a2be79810024c0f06957ca00138ae8c..946317d5fef27f2a263036c490b328ca416382c3 100644 (file)
@@ -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<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()
@@ -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);
                                }
 
                        }
index 172b88ff1bf9b07d16f424860b24b273b42273b6..250e0239b307d9e737669c052c9495d3c14f4bbf 100644 (file)
                                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>