]> SALOME platform Git repositories - tools/siman.git/blobdiff - Workspace/Siman/src/org/splat/simer/CopyStudyAction.java
Salome HOME
Creation of a new study from an existing one is implemented.
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / CopyStudyAction.java
index 1286f5114618a5170e84754a48f3320a16596427..edd7643621d5a7092f97928fb3a10609987cfdd1 100644 (file)
 
 package org.splat.simer;
 
+import java.io.IOException;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
-import org.splat.kernel.InvalidPropertyException;
-import org.splat.kernel.MissedPropertyException;
-import org.splat.kernel.MultiplyDefinedException;
+import org.splat.exception.BusinessException;
 import org.splat.service.SearchService;
 import org.splat.service.dto.Proxy;
 import org.splat.service.dto.ScenarioDTO;
@@ -50,6 +49,15 @@ public class CopyStudyAction extends NewStudyAction {
         * The selected source study id.
         */
        private long _fromStudyId = 0;
+       /**
+        * The selected source scenario id.
+        */
+       private long _fromScenarioId = 0;
+
+       /**
+        * The selected source study id.
+        */
+       private int _finalStep = 0;
        /**
         * Injected search service.
         */
@@ -62,14 +70,19 @@ public class CopyStudyAction extends NewStudyAction {
        /**
         * {@inheritDoc}
         * 
+        * @throws IOException
+        * 
         * @see org.splat.simer.NewStudyAction#doCreate()
         */
        @Override
-       public String doCreate() throws InvalidPropertyException,
-                       MissedPropertyException, MultiplyDefinedException {
+       public String doCreate() throws BusinessException, IOException {
                String res = super.doCreate();
                if (SUCCESS.equals(res)) {
                        // Copy content from the selected study
+                       getScenarioService().copyStudyContent(_fromStudyId,
+                                       _fromScenarioId, _finalStep, getOpenStudy().getIndex());
+               } else {
+                       doInitialize();
                }
                return res;
        }
@@ -83,31 +96,35 @@ public class CopyStudyAction extends NewStudyAction {
        public String doInitialize() {
                // Initialize contexts list, study title and menus.
                super.doInitialize();
-               
+
                // Initialize source studies list, scenarios list and steps list
-               
+
                // Get visible studies
                StudySearchFilterDTO filter = new StudySearchFilterDTO();
                if (getConnectedUser() != null) {
                        filter.setConnectedUserId(getConnectedUser().getIndex());
                }
                List<Proxy> studies = getSearchService().selectStudiesWhere(filter);
-               
+
                // Fill the studies list
-               for (Proxy study: studies) {
+               _studies.put(0L, "");
+               for (Proxy study : studies) {
                        _studies.put(study.getIndex(), study.getTitle());
                }
-               
+
                // Fill lists of scenarios and steps according to the selected study
                if (_fromStudyId > 0 && _studies.containsKey(_fromStudyId)) {
                        // Get scenarios from the selected study
-                       List<ScenarioDTO> scens = getScenarioService().getStudyScenarios(_fromStudyId);
-                       for (ScenarioDTO scen: scens) {
+                       List<ScenarioDTO> scens = getScenarioService().getStudyScenarios(
+                                       _fromStudyId);
+                       for (ScenarioDTO scen : scens) {
                                _scenarios.put(scen.getIndex(), scen.getTitle());
                        }
                        // Fill steps
-                       for (ProjectSettingsService.Step step: getStepsConfigService().getSteps()) {
-                               _steps.put(step.getNumber(), getText("folder.step." + step.getNumber()));
+                       for (ProjectSettingsService.Step step : getStepsConfigService()
+                                       .getSteps()) {
+                               _steps.put(step.getNumber(),
+                                               getText("folder.step." + step.getNumber()));
                        }
                }
 
@@ -198,4 +215,42 @@ public class CopyStudyAction extends NewStudyAction {
                        final StepsConfigService stepsConfigService) {
                _stepsConfigService = stepsConfigService;
        }
+
+       /**
+        * Get the fromScenarioId.
+        * 
+        * @return the fromScenarioId
+        */
+       public long getFromScenarioId() {
+               return _fromScenarioId;
+       }
+
+       /**
+        * Set the fromScenarioId.
+        * 
+        * @param fromScenarioId
+        *            the fromScenarioId to set
+        */
+       public void setFromScenarioId(final long fromScenarioId) {
+               _fromScenarioId = fromScenarioId;
+       }
+
+       /**
+        * Get the finalStep.
+        * 
+        * @return the finalStep
+        */
+       public int getFinalStep() {
+               return _finalStep;
+       }
+
+       /**
+        * Set the finalStep.
+        * 
+        * @param finalStep
+        *            the finalStep to set
+        */
+       public void setFinalStep(final int finalStep) {
+               _finalStep = finalStep;
+       }
 }