Salome HOME
NewStudyAction is improved. Specific business method for creation of a new study...
authorrkv <rkv@opencascade.com>
Thu, 25 Oct 2012 10:55:45 +0000 (10:55 +0000)
committerrkv <rkv@opencascade.com>
Thu, 25 Oct 2012 10:55:45 +0000 (10:55 +0000)
Workspace/Siman-Common/src/conf/log-messages.properties
Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Persistent.java
Workspace/Siman-Common/src/org/splat/service/ScenarioService.java
Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java
Workspace/Siman-Common/src/spring/businessServiceContext.xml
Workspace/Siman/src/org/splat/simer/EditKnowledgeElementAction.java
Workspace/Siman/src/org/splat/simer/NewStudyAction.java

index 974cf9e2cacc4fedc024b8879836a8863ec3735e..708f15d0d378bed3c627115b43ff27cb1a979da4 100644 (file)
@@ -2,4 +2,5 @@
 LCK-000001=Lock reference already exists for user {2}.
 LCK-000002=Lock reference does not exists.
 LCK-000003=Lock reference protected and can be only deleted or updated by user {2}.
-LCK-000004=Lock reference is timeout and could have been modified by user {2}.
\ No newline at end of file
+LCK-000004=Lock reference is timeout and could have been modified by user {2}.
+STD-000001="Unable to re-index the study #{1}, reason: {2}"
\ No newline at end of file
index 42629f251affcbab6394d7d14ededace60add091..f9f01d6d3725fe9034b59259ceb200d93f67ab99 100644 (file)
@@ -6,152 +6,187 @@ import org.splat.kernel.MultiplyDefinedException;
 import org.splat.kernel.ObjectProperties;
 
 /**
- * Base implementation of the API Design Pattern of objects which persistence is based on Hibernate.<br/>
- * This Design Pattern supports the following features:
+ * Base implementation of the API Design Pattern of objects which persistence is based on Hibernate.<br/> This Design Pattern supports the
+ * following features:
  * <ul>
  * <li>Flexible API for constructing objects from many variable arguments</li>
  * <li>Impossible to leave persistent objects in inconsistent state, even temporarily, during their construction</li>
  * <li>Same Object Oriented API for constructing and selecting objects from the database</li>
  * <li>Centralized validity check of arguments</li>
  * </ul>
- * The API is based on intermediate properties objects used for collecting arguments and checking their validity.
- * These properties objects are passed to persistent object constructors and database select functions for execution.
- * For example, as based on this Design Pattern, a User object could be created that way:
+ * The API is based on intermediate properties objects used for collecting arguments and checking their validity. These properties objects
+ * are passed to persistent object constructors and database select functions for execution. For example, as based on this Design Pattern, a
+ * User object could be created that way:
+ * 
  * <pre>
- *   User.Properties  args = new User.Properties();
- *   User  user = new User( args.setUsername("mypseudo").setMailAddress("me@provider.domain") );
+ * User.Properties args = new User.Properties();
+ * User user = new User(args.setUsername(&quot;mypseudo&quot;).setMailAddress(
+ *             &quot;me@provider.domain&quot;));
  * </pre>
- * Classes implementing this Design Pattern must inherit from Persistent and implement their Properties class as a nested
- * subclass of Persistent.Properties.<br/>
- * <br/>
- * Naturally, as usual with Hibernate, any class can be persistent (you don't need to inherit from Persistent for being
- * persistent). Inheriting from Persistent is only a matter of enabling the API supported by the above Design Pattern.
+ * 
+ * Classes implementing this Design Pattern must inherit from Persistent and implement their Properties class as a nested subclass of
+ * Persistent.Properties.<br/> <br/> Naturally, as usual with Hibernate, any class can be persistent (you don't need to inherit from
+ * Persistent for being persistent). Inheriting from Persistent is only a matter of enabling the API supported by the above Design Pattern.
  * 
  * @see ObjectProperties
  * @see Persistent.Properties
- * @author    Daniel Brunier-Coulin
+ * @author Daniel Brunier-Coulin
  * @copyright OPEN CASCADE 2012
  */
 
-
 public abstract class Persistent {
 
-    private  long rid;                                     // Primary key of persistent objects
-
-    protected abstract static class Properties implements ObjectProperties {
-//  ----------------------------------------------------------------------
-      private boolean tobechecked = true;                 // Property validity check flag
-
-         public void disableCheck () {
-        tobechecked = false;
-      }
-         public boolean mustBeChecked () {
-               return tobechecked;
-         }
-         public void clear () {
-               tobechecked = true;
-         }
-    }
-
-//  ==============================================================================================================================
-//  Constructors
-//  ==============================================================================================================================
-/**
- * Database fetch constructor.
- */
-    protected Persistent () {
-//  -----------------------
-      rid = 0;                                            // Set when loading the object
-    }
+       private long rid; // Primary key of persistent objects
+
+       protected abstract static class Properties implements ObjectProperties {
+               private long rid; // Primary key of persistent objects
+
+               private boolean tobechecked = true; // Property validity check flag
+
+               public void disableCheck() {
+                       tobechecked = false;
+               }
+
+               public boolean mustBeChecked() {
+                       return tobechecked;
+               }
+
+               public void clear() {
+                       tobechecked = true;
+               }
+
+               /**
+                * Get the rid.
+                * 
+                * @return the rid
+                */
+               public long getIndex() {
+                       return rid;
+               }
+
+               /**
+                * Set the rid.
+                * 
+                * @param rid
+                *            the rid to set
+                */
+               public void setIndex(long rid) {
+                       this.rid = rid;
+               }
+       }
 
-/**
- * Checks the mutual compatibility of arguments previously set in the given properties object, if the validity check is enabled.
- * As this validity depends on concrete classes, the check is delegated to subclasses of the given Persistent.Properties.
- */
-    protected Persistent (ObjectProperties oprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException {
-//  ---------------------------------------------
-      if (oprop.mustBeChecked()) oprop.checkValidity();   // Throws one of the above exception if not valid
-      rid = 0;                                            // Set when saving the object
-    }
-
-//  ==============================================================================================================================
-//  Public member functions
-//  ==============================================================================================================================
-
-    public boolean equals(Object entity) {
-//  ------------------------------------
-      if (entity == null) return false;
-      if (entity.getClass().equals(this.getClass())) {
-        Persistent object = (Persistent)entity;
-        long   he = object.getIndex();                     // getIndex() is supposed fetching the index if not yet done
-        long   me = this.getIndex();                       // getIndex() is supposed fetching the index if not yet done
-        if (me*he != 0) return (he == me);
-        if (me+he == 0) return (this == object);
-      }
-      return false;
-    }
+       // ==============================================================================================================================
+       // Constructors
+       // ==============================================================================================================================
+       /**
+        * Database fetch constructor.
+        */
+       protected Persistent() {
+               // -----------------------
+               rid = 0; // Set when loading the object
+       }
 
-/**
- * Returns the Persistent ID of this object. The PID is set when saving this object. It is unique in the scope of the class
- * of this object only.
- * 
- * @return the PID of this, or 0 if this is not saved.
- * @see    isSaved()
- */
-    public long getIndex () {
-//  ----------------------
-      return rid;
-    }
+       /**
+        * Checks the mutual compatibility of arguments previously set in the given properties object, if the validity check is enabled. As this
+        * validity depends on concrete classes, the check is delegated to subclasses of the given Persistent.Properties.
+        */
+       protected Persistent(ObjectProperties oprop)
+                       throws MissedPropertyException, InvalidPropertyException,
+                       MultiplyDefinedException {
+               // ---------------------------------------------
+               if (oprop.mustBeChecked())
+                       oprop.checkValidity(); // Throws one of the above exception if not valid
+               rid = 0; // Set when saving the object
+       }
+
+       // ==============================================================================================================================
+       // Public member functions
+       // ==============================================================================================================================
+
+       public boolean equals(Object entity) {
+               // ------------------------------------
+               if (entity == null)
+                       return false;
+               if (entity.getClass().equals(this.getClass())) {
+                       Persistent object = (Persistent) entity;
+                       long he = object.getIndex(); // getIndex() is supposed fetching the index if not yet done
+                       long me = this.getIndex(); // getIndex() is supposed fetching the index if not yet done
+                       if (me * he != 0)
+                               return (he == me);
+                       if (me + he == 0)
+                               return (this == object);
+               }
+               return false;
+       }
+
+       /**
+        * Returns the Persistent ID of this object. The PID is set when saving this object. It is unique in the scope of the class of this
+        * object only.
+        * 
+        * @return the PID of this, or 0 if this is not saved.
+        * @see isSaved()
+        */
+       public long getIndex() {
+               // ----------------------
+               return rid;
+       }
 
        /**
         * Set an id for the object.
-        * @param anId id to set
+        * 
+        * @param anId
+        *            id to set
         */
        public void setIndex(long anId) {
                rid = anId;
        }
-       
-    public int hashCode () {
-//  ----------------------
-      return toString().hashCode();
-    }
 
-/**
- * Returns true if this object is saved.
- * 
- * @return true if this is saved.
- * @see    getIndex()
- */
-    public boolean isSaved () {
-//  -------------------------
-      return (getIndex() != 0);                           // getIndex() is supposed fetching the index if not yet done
-    }
+       public int hashCode() {
+               // ----------------------
+               return toString().hashCode();
+       }
 
-/**
- * Return a string representing uniquely this object.
- * 
- * @return the unique string representation of this object.
- */
-    public String toString () {
-//  -------------------------
-      long oid = getIndex();                               // getIndex() is supposed fetching the index if not yet done
-      if (oid == 0) oid = super.hashCode();               //WARNING: Must not call super.toString() as it goes back here (this.toString())
-      return new StringBuffer("object ").append(getClass().getName()).append("@").append(oid).toString();
-    }
+       /**
+        * Returns true if this object is saved.
+        * 
+        * @return true if this is saved.
+        * @see getIndex()
+        */
+       public boolean isSaved() {
+               // -------------------------
+               return (getIndex() != 0); // getIndex() is supposed fetching the index if not yet done
+       }
 
-/**
- * Get the rid.
- * @return the rid
- */
-public long getRid() {
-       return rid;
-}
+       /**
+        * Return a string representing uniquely this object.
+        * 
+        * @return the unique string representation of this object.
+        */
+       public String toString() {
+               // -------------------------
+               long oid = getIndex(); // getIndex() is supposed fetching the index if not yet done
+               if (oid == 0)
+                       oid = super.hashCode(); // WARNING: Must not call super.toString() as it goes back here (this.toString())
+               return new StringBuffer("object ").append(getClass().getName()).append(
+                               "@").append(oid).toString();
+       }
 
-/**
- * Set the rid.
- * @param rid the rid to set
- */
-public void setRid(long rid) {
-       this.rid = rid;
-}
+       /**
+        * Get the rid.
+        * 
+        * @return the rid
+        */
+       public long getRid() {
+               return rid;
+       }
+
+       /**
+        * Set the rid.
+        * 
+        * @param rid
+        *            the rid to set
+        */
+       public void setRid(long rid) {
+               this.rid = rid;
+       }
 }
\ No newline at end of file
index b5903e2b392da404ed07fe0ef13fd9fe3815b09d..025a6cb5e3e64e00f1089ee9b349e60d6b8363c7 100644 (file)
@@ -12,6 +12,7 @@ package org.splat.service;
 import org.splat.dal.bo.kernel.User;
 import org.splat.dal.bo.som.KnowledgeElement;
 import org.splat.dal.bo.som.Scenario;
+import org.splat.dal.bo.som.SimulationContext;
 import org.splat.dal.bo.som.Study;
 import org.splat.kernel.InvalidPropertyException;
 import org.splat.kernel.MissedPropertyException;
@@ -25,6 +26,27 @@ import org.splat.som.Step;
  */
 public interface ScenarioService {
 
+       /**
+        * Create a new study with one scenario and "product" simulation context.
+        * 
+        * @param sprop
+        *            the study properties
+        * @param oprop
+        *            the scenario properties
+        * @param cprop
+        *            the "product" simulation context properties
+        * @return the created study
+        * @throws MissedPropertyException
+        *             if a mandatory property is missed
+        * @throws InvalidPropertyException
+        *             if a property is invalid
+        * @throws MultiplyDefinedException
+        *             if some property occurs several times
+        */
+       public Study createStudy(Study.Properties sprop, Scenario.Properties oprop,
+                       SimulationContext.Properties cprop) throws MissedPropertyException,
+                       InvalidPropertyException, MultiplyDefinedException;
+
        /**
         * Add a new scenario to the study.
         * 
index 0f8ea31442a6bdb4bea60d485e10fe4d119b7882..464eff57440108fcbfc1ddab8534fe110a243ce4 100644 (file)
@@ -101,6 +101,11 @@ public class ScenarioServiceImpl implements ScenarioService {
         */
        private KnowledgeElementTypeDAO _knowledgeElementTypeDAO;
 
+       /**
+        * Injected simulation context service.
+        */
+       private SimulationContextService _simulationContextService;
+
        /**
         * Get the projectElementService.
         * 
@@ -159,6 +164,41 @@ public class ScenarioServiceImpl implements ScenarioService {
                _stepService = stepService;
        }
 
+       /**
+        * Create a new study with one scenario and "product" simulation context.
+        * 
+        * @param sprop
+        *            the study properties
+        * @param oprop
+        *            the scenario properties
+        * @param cprop
+        *            the "product" simulation context properties
+        * @return the created study
+        * @throws MissedPropertyException
+        *             if a mandatory property is missed
+        * @throws InvalidPropertyException
+        *             if a property is invalid
+        * @throws MultiplyDefinedException
+        *             if some property occurs several times
+        */
+       @Transactional
+       public Study createStudy(Study.Properties sprop, Scenario.Properties oprop,
+                       SimulationContext.Properties cprop) throws MissedPropertyException,
+                       InvalidPropertyException, MultiplyDefinedException {
+               Study study = getStudyService().createStudy(sprop);
+               addScenario(study, oprop);
+               if (cprop.getIndex() == 0) { // Input of new project context
+                       cprop.setType(getSimulationContextService().selectType("product"))
+                                       .setValue(cprop.getValue());
+                       getStudyService().addProjectContext(study, cprop);
+               } else { // Selection of existing project context
+                       SimulationContext context = getSimulationContextService()
+                                       .selectSimulationContext(cprop.getIndex());
+                       getStudyService().addProjectContext(study, context);
+               }
+               return study;
+       }
+
        /**
         * {@inheritDoc}
         * 
@@ -179,7 +219,7 @@ public class ScenarioServiceImpl implements ScenarioService {
                        // Get the persistent scenario.
                        Scenario aScenario = getScenarioDAO().get(aScenarioId);
                        // Get persistent objects for creating a new knowledge.
-                       //TODO: Actions must use DTO instead of persistent objects.
+                       // TODO: Actions must use DTO instead of persistent objects.
                        getUserDAO().merge(kprop.getAuthor());
                        getKnowledgeElementTypeDAO().merge(kprop.getType());
                        // Create a transient knowledge element related to the given scenario.
@@ -559,4 +599,24 @@ public class ScenarioServiceImpl implements ScenarioService {
                _knowledgeElementTypeDAO = knowledgeElementTypeDAO;
        }
 
+       /**
+        * Get the simulationContextService.
+        * 
+        * @return the simulationContextService
+        */
+       public SimulationContextService getSimulationContextService() {
+               return _simulationContextService;
+       }
+
+       /**
+        * Set the simulationContextService.
+        * 
+        * @param simulationContextService
+        *            the simulationContextService to set
+        */
+       public void setSimulationContextService(
+                       SimulationContextService simulationContextService) {
+               _simulationContextService = simulationContextService;
+       }
+
 }
index aaf0249d217d2fd9c4cc5251aefa7c0cbdbe137d..e6a6191795712f00867441fbc76271c83a69764e 100644 (file)
@@ -176,6 +176,7 @@ public class StudyServiceImpl implements StudyService {
         * 
         * @see org.splat.service.StudyService#addProjectContext(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.SimulationContext.Properties)
         */
+       @Transactional
        public SimulationContext addProjectContext(Study aStudy,
                        SimulationContext.Properties cprop) throws MissedPropertyException,
                        InvalidPropertyException, MultiplyDefinedException {
@@ -190,6 +191,7 @@ public class StudyServiceImpl implements StudyService {
         * 
         * @see org.splat.service.StudyService#addProjectContext(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.SimulationContext)
         */
+       @Transactional
        public SimulationContext addProjectContext(Study aStudy,
                        SimulationContext context) {
                SimulationContext added = getStepService().addSimulationContext(
@@ -445,9 +447,8 @@ public class StudyServiceImpl implements StudyService {
                        setShortCuts(aStudy); // RKV: initialize transient actors set
                        getIndex().update(aStudy); // Update of Lucene index
                        isOk = true;
-               } catch (Exception error) {
-                       logger.error("Unable to re-index the study '" + aStudy.getIndex()
-                                       + "', reason:", error);
+               } catch (Exception e) {
+                       logger.error("STD-000001", e, aStudy.getIndex(), e.getMessage());
                }
                return isOk;
        }
@@ -517,8 +518,8 @@ public class StudyServiceImpl implements StudyService {
                                                if (i == format.length)
                                                        break;
                                        }
-                                       DecimalFormat tostring = new DecimalFormat(
-                                                       pattern.substring(n, i));
+                                       DecimalFormat tostring = new DecimalFormat(pattern
+                                                       .substring(n, i));
                                        String number = tostring.format(next);
                                        for (int j = 0; j < number.length(); j++) {
                                                ref[count] = number.charAt(j);
@@ -649,15 +650,13 @@ public class StudyServiceImpl implements StudyService {
                                        if (actype[i] == Actor.manager) {
                                                actor = from.getAuthor();
                                        } else if (actype[i] == Actor.Nx1) {
-                                               List<User> manager = getUserService()
-                                                               .selectUsersWhere(uprop
-                                                                               .setOrganizationName("Nx1"));
+                                               List<User> manager = getUserService().selectUsersWhere(
+                                                               uprop.setOrganizationName("Nx1"));
                                                if (manager.size() == 1)
                                                        actor = manager.get(0);
                                        } else if (actype[i] == Actor.Nx2) {
-                                               List<User> manager = getUserService()
-                                                               .selectUsersWhere(uprop
-                                                                               .setOrganizationName("Nx2"));
+                                               List<User> manager = getUserService().selectUsersWhere(
+                                                               uprop.setOrganizationName("Nx2"));
                                                if (manager.size() == 1)
                                                        actor = manager.get(0);
                                        } else { /* Actor.customer */
@@ -1111,6 +1110,7 @@ public class StudyServiceImpl implements StudyService {
 
        /**
         * Get the userService.
+        * 
         * @return the userService
         */
        public UserService getUserService() {
@@ -1119,7 +1119,9 @@ public class StudyServiceImpl implements StudyService {
 
        /**
         * Set the userService.
-        * @param userService the userService to set
+        * 
+        * @param userService
+        *            the userService to set
         */
        public void setUserService(UserService userService) {
                _userService = userService;
index f0ad06dd2539f0de05b8d0270d52d107de762e42..2bb17ee80ccbfbd941676a7d62441a4bbe941026 100644 (file)
@@ -83,6 +83,8 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
                <property name="userDAO" ref="userDAO" />
                <property name="knowledgeElementTypeDAO"
                        ref="knowledgeElementTypeDAO" />
+        <property name="simulationContextService"
+            ref="simulationContextService" />
        </bean>
 
        <bean id="searchService"
index 16f48baa66dd6178c4cdb0c7edd50462167eff10..da4e7072fa9358857cc0f5c1d9df46acffd0d6ec 100644 (file)
@@ -43,10 +43,9 @@ public class EditKnowledgeElementAction extends DisplayStudyStepAction {
         * Injected knowledge element type service.
         */
        private KnowledgeElementTypeService _knowledgeElementTypeService;
-       
+
        /**
-        * Value of the menu property. 
-        * It can be: none, create, open, study, knowledge, sysadmin, help.
+        * Value of the menu property. It can be: none, create, open, study, knowledge, sysadmin, help.
         */
        private String _menuProperty;
 
@@ -61,10 +60,10 @@ public class EditKnowledgeElementAction extends DisplayStudyStepAction {
         */
        public String doInitialize() {
                mystudy = getOpenStudy();
-               
+
                setMenuProperty("study");
                initializationScreenContext(_menuProperty);
-               
+
                return SUCCESS;
        }
 
@@ -74,10 +73,10 @@ public class EditKnowledgeElementAction extends DisplayStudyStepAction {
         * @return SUCCESS if operation succeeded, ERROR if Runtime exception, otherwise INPUT
         */
        public String doSetKnowledge() {
-               
+
                setMenuProperty("study");
                initializationScreenContext(_menuProperty);
-               
+
                try {
                        User user = getConnectedUser();
                        mystudy = getOpenStudy();
@@ -131,7 +130,7 @@ public class EditKnowledgeElementAction extends DisplayStudyStepAction {
 
                mystudy.remove(kelm);
                getMenu("study").selects(mystudy.getSelection()); // Updates the menu icon, in case of last removed document
-               
+
                setMenuProperty("study");
                initializationScreenContext(_menuProperty);
 
@@ -236,6 +235,7 @@ public class EditKnowledgeElementAction extends DisplayStudyStepAction {
 
        /**
         * Get the knowledgeElementTypeService.
+        * 
         * @return the knowledgeElementTypeService
         */
        public KnowledgeElementTypeService getKnowledgeElementTypeService() {
@@ -244,15 +244,18 @@ public class EditKnowledgeElementAction extends DisplayStudyStepAction {
 
        /**
         * Set the knowledgeElementTypeService.
-        * @param knowledgeElementTypeService the knowledgeElementTypeService to set
+        * 
+        * @param knowledgeElementTypeService
+        *            the knowledgeElementTypeService to set
         */
        public void setKnowledgeElementTypeService(
                        KnowledgeElementTypeService knowledgeElementTypeService) {
                _knowledgeElementTypeService = knowledgeElementTypeService;
        }
-       
+
        /**
         * Get the menuProperty.
+        * 
         * @return the menuProperty
         */
        public String getMenuProperty() {
@@ -261,7 +264,9 @@ public class EditKnowledgeElementAction extends DisplayStudyStepAction {
 
        /**
         * Set the menuProperty.
-        * @param menuProperty the menuProperty to set
+        * 
+        * @param menuProperty
+        *            the menuProperty to set
         */
        public void setMenuProperty(String menuProperty) {
                this._menuProperty = menuProperty;
index df6211e979c82f639a6af9b9be6f51f00a883723..ae2fb2375b479838ac0df25a8903d593f1bc6e7b 100644 (file)
@@ -11,31 +11,48 @@ import org.splat.service.ScenarioService;
 import org.splat.service.SimulationContextService;
 import org.splat.service.StudyService;
 
+/**
+ * Action for creation of a new study.
+ */
 public class NewStudyAction extends Action {
 
-       private String title = null;
-       private List<SimulationContext> contelm = null;
-       private String context = null;
-
-       private static int number = 0;
        /**
         * Serial version ID.
         */
        private static final long serialVersionUID = 693943641800113782L;
+       /**
+        * Sequential number of the new study for appending to its default title.
+        */
+       private static int number = 0;
+
+       /**
+        * Title of the new study.
+        */
+       private String title = null;
+       /**
+        * List of available project contexts for selection for the new study.
+        */
+       private List<SimulationContext> contelm = null;
+       /**
+        * Project context.
+        */
+       private String context = null;
 
        /**
         * The injected Study service.
         */
        private StudyService _studyService;
+       /**
+        * Injected simulation context service.
+        */
        private SimulationContextService _simulationContextService;
        /**
         * Injected scenario service.
         */
        private ScenarioService _scenarioService;
-       
+
        /**
-        * Value of the menu property. 
-        * It can be: none, create, open, study, knowledge, sysadmin, help.
+        * Value of the menu property. It can be: none, create, open, study, knowledge, sysadmin, help.
         */
        private String _menuProperty;
 
@@ -43,7 +60,11 @@ public class NewStudyAction extends Action {
        // Action methods
        // ==============================================================================================================================
 
-       // Fill the values of the drop-down list.
+       /**
+        * Fill the values of the drop-down list, and initialize a menu.
+        * 
+        * @return SUCCESS
+        */
        public String doInitialize() {
 
                // get the list of the simulation contexts of the study
@@ -54,13 +75,20 @@ public class NewStudyAction extends Action {
                                ApplicationSettings.getCurrentLocale());
                title = locale.getString("label.study") + " "
                                + String.valueOf(number + 1);
-               
+
                setMenuProperty("create");
                initializationScreenContext(_menuProperty);
 
                return SUCCESS;
        }
 
+       /**
+        * Create a new study.
+        * 
+        * @return SUCCESS if the new study is created, INPUT if project context is not defined, ERROR if failed
+        * @throws Exception
+        *             if properties of the new study are invalid
+        */
        public String doCreate() throws Exception {
                String[] input = context.split(",");
                int valid = Integer.valueOf(input[0]);
@@ -69,63 +97,49 @@ public class NewStudyAction extends Action {
                Study.Properties sprop = new Study.Properties();
 
                // Check arguments and creation of the study
-               try {
-                       if (valid == -1)
-                               throw new Exception();
-                       if (valid == 0) {
-                               value = input[1].trim();
-                               if (value.length() == 0) {
-                                       
-                                       setMenuProperty("create");
-                                       initializationScreenContext(_menuProperty);
-                                       
-                                       return INPUT; // No need to reinitialize the list of existing products
-                               }
-                       }
-                       sprop.setTitle(title).setManager(getConnectedUser());
-                       sprop.checkValidity();
-                       sprop.disableCheck();
-               } catch (Exception error) {
+               if (valid == -1) {
                        SimulationContext.Properties cprop = new SimulationContext.Properties();
                        SimulationContextType product = getSimulationContextService()
                                        .selectType("product");
                        contelm = getSimulationContextService()
                                        .selectSimulationContextsWhere(cprop.setType(product));
-                       
-                       setMenuProperty("create");
-                       initializationScreenContext(_menuProperty);
-                       
                        return INPUT; // Title empty, simply wait for input without error message
                }
+               if (valid == 0) {
+                       value = input[1].trim();
+                       if (value.length() == 0) {
+                               setMenuProperty("create");
+                               initializationScreenContext(_menuProperty);
+                               return INPUT; // No need to reinitialize the list of existing products
+                       }
+               }
+               sprop.setTitle(title).setManager(getConnectedUser());
+               sprop.checkValidity();
+               sprop.disableCheck();
                try {
-                       Study study = getStudyService().createStudy(sprop);
-
                        // Addition of a default scenario
                        ResourceBundle locale = ResourceBundle.getBundle("labels",
                                        ApplicationSettings.getCurrentLocale());
                        Scenario.Properties oprop = new Scenario.Properties();
                        oprop.setTitle(locale.getString("label.scenario") + " 1");
-                       getScenarioService().addScenario(study, oprop);
 
                        // Addition of the entered project context
+                       SimulationContext.Properties cprop = new SimulationContext.Properties();
                        if (valid == 0) { // Input of new project context
-                               SimulationContext.Properties cprop = new SimulationContext.Properties();
                                cprop.setType(
                                                getSimulationContextService().selectType("product"))
                                                .setValue(value);
-                               getStudyService().addProjectContext(study, cprop);
                        } else { // Selection of existing project context
-                               SimulationContext context = getSimulationContextService()
-                                               .selectSimulationContext(valid);
-                               getStudyService().addProjectContext(study, context);
+                               cprop.setIndex(valid);
                        }
+                       Study study = getScenarioService().createStudy(sprop, oprop, cprop);
                        // Update of the session
                        number += 1;
                        open(study); // Opens the study,
-                       
+
                        setMenuProperty("study");
                        initializationScreenContext(_menuProperty);
-                       
+
                        return SUCCESS;
                } catch (Exception error) {
                        logger.error("Unable to save the study, reason:", error);
@@ -205,6 +219,7 @@ public class NewStudyAction extends Action {
 
        /**
         * Get the scenarioService.
+        * 
         * @return the scenarioService
         */
        public ScenarioService getScenarioService() {
@@ -213,14 +228,17 @@ public class NewStudyAction extends Action {
 
        /**
         * Set the scenarioService.
-        * @param scenarioService the scenarioService to set
+        * 
+        * @param scenarioService
+        *            the scenarioService to set
         */
        public void setScenarioService(ScenarioService scenarioService) {
                _scenarioService = scenarioService;
        }
-       
+
        /**
         * Get the menuProperty.
+        * 
         * @return the menuProperty
         */
        public String getMenuProperty() {
@@ -229,7 +247,9 @@ public class NewStudyAction extends Action {
 
        /**
         * Set the menuProperty.
-        * @param menuProperty the menuProperty to set
+        * 
+        * @param menuProperty
+        *            the menuProperty to set
         */
        public void setMenuProperty(String menuProperty) {
                this._menuProperty = menuProperty;