Salome HOME
Creation of a new study from an existing one is implemented.
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / NewStudyAction.java
index 4a7e0a97d9d5f859d72962fc6256ae70cf157fae..2058b0881a14a8463403cbc29c083e4573e763aa 100644 (file)
@@ -1,15 +1,15 @@
 package org.splat.simer;
 
+import java.io.IOException;
 import java.util.List;
 import java.util.ResourceBundle;
 
+import org.apache.commons.lang3.StringUtils;
 import org.splat.dal.bo.som.Scenario;
 import org.splat.dal.bo.som.SimulationContext;
 import org.splat.dal.bo.som.SimulationContextType;
 import org.splat.dal.bo.som.Study;
-import org.splat.kernel.InvalidPropertyException;
-import org.splat.kernel.MissedPropertyException;
-import org.splat.kernel.MultiplyDefinedException;
+import org.splat.exception.BusinessException;
 import org.splat.service.ScenarioService;
 import org.splat.service.SimulationContextService;
 import org.splat.wapp.Constants;
@@ -37,10 +37,13 @@ public class NewStudyAction extends Action {
         */
        private transient List<SimulationContext> _contelm = null;
        /**
-        * Project context.
+        * Selected project context string value.
         */
        private String _projectContext = null;
-
+       /**
+        * Selected project context id.
+        */
+       private long _projectContextId = -1;
        /**
         * Injected simulation context service.
         */
@@ -65,10 +68,9 @@ public class NewStudyAction extends Action {
                _contelm = getSimulationContextService().getSimulationContextList();
 
                // set the default name of the new study
-               ResourceBundle locale = ResourceBundle.getBundle("labels",
-                               getApplicationSettings().getCurrentLocale());
-               _title = locale.getString("label.study") + " "
-                               + (number + 1);
+               if (StringUtils.isBlank(_title)) {
+                       _title = getText("label.study") + " " + (number + 1);
+               }
 
                initializationFullScreenContext(Constants.CREATE_MENU, Constants.NONE,
                                Constants.OPEN);
@@ -80,21 +82,16 @@ public class NewStudyAction extends Action {
         * Create a new study.
         * 
         * @return SUCCESS if the new study is created, INPUT if project context is not defined, ERROR if failed
-        * @throws InvalidPropertyException
-        *             if some property has invalid value
-        * @throws MultiplyDefinedException
-        *             if some property is defined several times
-        * @throws MissedPropertyException
-        *             if properties of the new study are invalid
+        * @throws BusinessException
+        *             if new study creation is failed
+        * @throws IOException
+        *             if file operations are failed
         */
-       public String doCreate() throws InvalidPropertyException,
-                       MissedPropertyException, MultiplyDefinedException {
+       public String doCreate() throws BusinessException, IOException {
                String res = SUCCESS;
-               String[] input = _projectContext.split(",");
-               int valid = Integer.valueOf(input[0]);
 
                // Check arguments and creation of the study
-               if (valid == -1) {
+               if (_projectContextId == -1) {
                        SimulationContext.Properties cprop = new SimulationContext.Properties();
                        SimulationContextType product = getSimulationContextService()
                                        .selectType("product");
@@ -103,9 +100,9 @@ public class NewStudyAction extends Action {
                        // Title empty, simply wait for input without error message
                        res = INPUT;
                } else {
-                       String value; // input[1] if exists
-                       if (valid == 0) {
-                               value = input[1].trim();
+                       String value; // if new a project context has to be created
+                       if (_projectContextId == 0) {
+                               value = _projectContext.trim();
                                if (value.length() == 0) {
                                        initializationScreenContext(Constants.CREATE_MENU);
                                        // No need to reinitialize the list of existing products
@@ -126,34 +123,36 @@ public class NewStudyAction extends Action {
                                                        getApplicationSettings().getCurrentLocale());
                                        Scenario.Properties oprop = new Scenario.Properties();
                                        oprop.setTitle(locale.getString("label.scenario") + " 1");
-               
+
                                        // Addition of the entered project context
                                        SimulationContext.Properties cprop = new SimulationContext.Properties();
-                                       if (valid == 0) { // Input of new project context
+                                       if (_projectContextId == 0) { // Input of new project context
                                                SimulationContextType product = getSimulationContextService()
                                                                .selectType("product");
-                                               
-                                               SimulationContext testContext = getSimulationContextService().selectSimulationContext(product, value);
-                                               
+
+                                               SimulationContext testContext = getSimulationContextService()
+                                                               .selectSimulationContext(product, value);
+
                                                if (testContext == null) {
-                                               cprop.setType(
-                                                               getSimulationContextService().selectType("product"))
-                                                               .setValue(value);
+                                                       cprop.setType(
+                                                                       getSimulationContextService().selectType(
+                                                                                       "product")).setValue(value);
                                                } else {
                                                        cprop.setIndex(testContext.getIndex());
                                                }
                                        } else { // Selection of existing project context
-                                               cprop.setIndex(valid);
+                                               cprop.setIndex(_projectContextId);
                                        }
-                                       Study study = getScenarioService().createStudy(sprop, oprop, cprop);
+                                       Study study = getScenarioService().createStudy(sprop,
+                                                       oprop, cprop);
                                        // Update of the session
                                        number += 1;
                                        open(study); // Opens the study,
-               
+
                                        initializationFullScreenContext(Constants.STUDY_MENU,
                                                        Constants.NONE, Constants.OPEN);
-               
-                               } catch (Exception error) {
+
+                               } catch (BusinessException error) {
                                        LOG.error("Unable to save the study, reason:", error);
                                        setErrorCode("message.error.newstudy");
                                        initializationScreenContext(Constants.NONE);
@@ -163,21 +162,23 @@ public class NewStudyAction extends Action {
                }
                return res;
        }
-       
+
        /**
         * 
         * {@inheritDoc}
+        * 
         * @see com.opensymphony.xwork2.ActionSupport#validate()
         */
        @Override
        public void validate() {
-               
-               if( LOG.isDebugEnabled() ) {
+
+               if (LOG.isDebugEnabled()) {
                        LOG.debug("--- validate");
                }
-               if( LOG.isDebugEnabled() ) {
+               if (LOG.isDebugEnabled()) {
                        LOG.debug("======> MKA test");
-                       LOG.debug(com.opensymphony.xwork2.ActionContext.getContext().getName());
+                       LOG.debug(com.opensymphony.xwork2.ActionContext.getContext()
+                                       .getName());
                }
        }
 
@@ -270,4 +271,23 @@ public class NewStudyAction extends Action {
        public void setScenarioService(final ScenarioService scenarioService) {
                _scenarioService = scenarioService;
        }
+
+       /**
+        * Get the projectContextId.
+        * 
+        * @return the projectContextId
+        */
+       public long getProjectContextId() {
+               return _projectContextId;
+       }
+
+       /**
+        * Set the projectContextId.
+        * 
+        * @param projectContextId
+        *            the projectContextId to set
+        */
+       public void setProjectContextId(final long projectContextId) {
+               _projectContextId = projectContextId;
+       }
 }
\ No newline at end of file