Salome HOME
createStudy method is added for calling from Python.
authorrkv <rkv@opencascade.com>
Mon, 11 Mar 2013 08:52:29 +0000 (08:52 +0000)
committerrkv <rkv@opencascade.com>
Mon, 11 Mar 2013 08:52:29 +0000 (08:52 +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/service/StudyService.java

index 200d3a94d0106bd521df53a0ef65f967151f3435..e00d67869d2f6ff142cbf0aeed2449b513a1f40e 100644 (file)
@@ -41,6 +41,29 @@ public interface ScenarioService {
         */
        List<StepDTO> getScenarioInfo(long scenarioId);
 
+       /**
+        * Create a new study.
+        * 
+        * @param username
+        *            user login
+        * @param title
+        *            study title
+        * @param productName
+        *            study product simulation context value
+        * @param description
+        *            study summary
+        * @return the created study id
+        * @throws InvalidPropertyException
+        *             if an invalid value is passed to a property
+        * @throws MissedPropertyException
+        *             if a mandatory property is missed
+        * @throws MultiplyDefinedException
+        *             if some property is defined several times
+        */
+       long createStudy(final String username, final String title,
+                       final String productName, final String description)
+                       throws InvalidPropertyException, MissedPropertyException, MultiplyDefinedException;
+
        /**
         * Create a new study with one scenario and "product" simulation context.
         * 
@@ -73,7 +96,7 @@ public interface ScenarioService {
         * @throws MissedPropertyException
         *             if a mandatory property is missed
         * @throws InvalidPropertyException
-        *             if some property doesn't exist
+        *             if an invalid value is passed to a property
         * @throws MultiplyDefinedException
         *             if some property occurs several times
         */
@@ -92,7 +115,7 @@ public interface ScenarioService {
         * @throws MissedPropertyException
         *             if a mandatory property is missed
         * @throws InvalidPropertyException
-        *             if some property doesn't exist
+        *             if an invalid value is passed to a property
         * @throws MultiplyDefinedException
         *             if some property is defined several times
         */
index 5ecf611329de12975de5b87d633394d1a2bcd219..85815f726033facc427668f4627166c7733c1ac4 100644 (file)
@@ -35,6 +35,7 @@ import org.splat.dal.bo.som.ProgressState;
 import org.splat.dal.bo.som.Publication;
 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.dal.bo.som.UsedByRelation;
 import org.splat.dal.bo.som.UsesRelation;
@@ -45,6 +46,7 @@ import org.splat.dal.dao.som.KnowledgeElementDAO;
 import org.splat.dal.dao.som.KnowledgeElementTypeDAO;
 import org.splat.dal.dao.som.ScenarioDAO;
 import org.splat.dal.dao.som.StudyDAO;
+import org.splat.i18n.I18nUtils;
 import org.splat.kernel.InvalidPropertyException;
 import org.splat.kernel.MismatchException;
 import org.splat.kernel.MissedPropertyException;
@@ -275,6 +277,53 @@ public class ScenarioServiceImpl implements ScenarioService {
                return res;
        }
 
+       /**
+        * {@inheritDoc}
+        * 
+        * @see org.splat.service.ScenarioService#createStudy(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+        */
+       @Override
+       public long createStudy(final String username, final String title,
+                       final String productName, final String description)
+                       throws InvalidPropertyException, MissedPropertyException,
+                       MultiplyDefinedException {
+               long id = 0;
+
+               // Find the author
+               User author = getUserService().selectUser(username);
+               if (author == null) {
+                       // User is not found
+                       throw new InvalidPropertyException(MessageKeyEnum.USR_000001
+                                       .toString(), username);
+               }
+
+               // Set the study properties
+               Study.Properties sprop = new Study.Properties();
+               sprop.setTitle(title).setManager(author);
+               sprop.setDescription(description);
+
+               // Find the product simulation context
+               SimulationContextType productContextType = getSimulationContextService()
+                               .selectType("product");
+               SimulationContext.Properties cprop = new SimulationContext.Properties();
+               cprop.setType(productContextType).setValue(productName);
+               SimulationContext productCtx = getSimulationContextService()
+                               .selectSimulationContext(productContextType, productName);
+               if (productCtx != null) {
+                       cprop.setIndex(productCtx.getIndex());
+               }
+
+               // Set a first scenario properties
+               Scenario.Properties oprop = new Scenario.Properties();
+               oprop.setTitle(I18nUtils.getMessageLocaleDefault("label.scenario")
+                               + " 1");
+
+               Study study = createStudy(sprop, oprop, cprop);
+               id = study.getIndex();
+
+               return id;
+       }
+
        /**
         * Create a new study with one scenario and "product" simulation context.
         * 
@@ -324,44 +373,45 @@ public class ScenarioServiceImpl implements ScenarioService {
                        throws MissedPropertyException, InvalidPropertyException,
                        MultiplyDefinedException {
                KnowledgeElement kelm = null;
-//             try {
-                       long aScenarioId = aScenarioDTO.getIndex();
-                       if (LOG.isDebugEnabled()) {
-                               LOG.debug("Add a knowledge element to the scenario #"
-                                               + aScenarioId);
-                       }
-                       // 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.
-                       getUserDAO().merge(kprop.getAuthor());
-                       getKnowledgeElementTypeDAO().merge(kprop.getType());
-                       // Create a transient knowledge element related to the given scenario.
-                       kelm = new KnowledgeElement(kprop.setOwnerScenario(aScenario));
-                       // Save the new knowledge in the database.
-                       getKnowledgeElementDAO().create(kelm);
-                       // Update scenario transient data.
-                       if (kelm.getType().equals("usecase")) {
-                               aScenarioDTO.setUcase(kelm);
-                       } else if (aScenarioDTO.getKnowledgeElementsList() != null) { // If null, knowl will be initialized when needed
-                               aScenarioDTO.getKnowledgeElementsList().add(kelm);
-                       }
+               // try {
+               long aScenarioId = aScenarioDTO.getIndex();
+               if (LOG.isDebugEnabled()) {
+                       LOG
+                                       .debug("Add a knowledge element to the scenario #"
+                                                       + aScenarioId);
+               }
+               // 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.
+               getUserDAO().merge(kprop.getAuthor());
+               getKnowledgeElementTypeDAO().merge(kprop.getType());
+               // Create a transient knowledge element related to the given scenario.
+               kelm = new KnowledgeElement(kprop.setOwnerScenario(aScenario));
+               // Save the new knowledge in the database.
+               getKnowledgeElementDAO().create(kelm);
+               // Update scenario transient data.
+               if (kelm.getType().equals("usecase")) {
+                       aScenarioDTO.setUcase(kelm);
+               } else if (aScenarioDTO.getKnowledgeElementsList() != null) { // If null, knowl will be initialized when needed
+                       aScenarioDTO.getKnowledgeElementsList().add(kelm);
+               }
 
-                       // Load the workflow for the parent study to take into account
-                       // all study actors durng reindexing.
-                       getStudyService().loadWorkflow(aScenario.getOwnerStudy());
+               // Load the workflow for the parent study to take into account
+               // all study actors durng reindexing.
+               getStudyService().loadWorkflow(aScenario.getOwnerStudy());
 
-//                     // Update the lucene index of knowledge elements.
-//                     getIndexService().add(kelm);
-                       if (LOG.isDebugEnabled()) {
-                               LOG.debug("A knowledge element #" + kelm.getIndex()
-                                               + " is added to the scenario #" + aScenario.getIndex());
-                       }
-//             } catch (IOException error) {
-//                     LOG.error("Unable to index the knowedge element '"
-//                                     + kelm.getIndex() + "', reason:", error);
-//                     kelm = null;
-//             }
+               // // Update the lucene index of knowledge elements.
+               // getIndexService().add(kelm);
+               if (LOG.isDebugEnabled()) {
+                       LOG.debug("A knowledge element #" + kelm.getIndex()
+                                       + " is added to the scenario #" + aScenario.getIndex());
+               }
+               // } catch (IOException error) {
+               // LOG.error("Unable to index the knowedge element '"
+               // + kelm.getIndex() + "', reason:", error);
+               // kelm = null;
+               // }
 
                return kelm;
        }
index 9726ddb83f055c39b38cc231eac14851c017124f..ddc4c0f9316f5fa1241288d98bf38cd3094588f9 100644 (file)
@@ -17,8 +17,8 @@ import org.splat.dal.bo.som.DocumentType;
 import org.splat.dal.bo.som.Publication;
 import org.splat.dal.bo.som.SimulationContext;
 import org.splat.dal.bo.som.Study;
-import org.splat.dal.bo.som.Study.Properties;
 import org.splat.dal.bo.som.ValidationCycle;
+import org.splat.dal.bo.som.Study.Properties;
 import org.splat.exception.IncompatibleDataException;
 import org.splat.exception.InvalidParameterException;
 import org.splat.kernel.InvalidPropertyException;
@@ -61,13 +61,12 @@ public interface StudyService {
         * @throws MissedPropertyException
         *             if a mandatory property is missed
         * @throws InvalidPropertyException
-        *             if some property doesn't exist
+        *             if an invalid value is passed to a property
         * @throws MultiplyDefinedException
         *             if some property is defined several times
         */
-       Study createStudy(Study.Properties sprop)
-                       throws MissedPropertyException, InvalidPropertyException,
-                       MultiplyDefinedException;
+       Study createStudy(Study.Properties sprop) throws MissedPropertyException,
+                       InvalidPropertyException, MultiplyDefinedException;
 
        /**
         * Add a simulation context to the first step of the study. If the context doesn't yet saved it is created in the database.
@@ -80,7 +79,7 @@ public interface StudyService {
         * @throws MissedPropertyException
         *             if a mandatory property is missed
         * @throws InvalidPropertyException
-        *             if some property doesn't exist
+        *             if an invalid value is passed to a property
         * @throws MultiplyDefinedException
         *             if some property occurs several times
         */
@@ -97,8 +96,7 @@ public interface StudyService {
         *            the simulation context to add
         * @return the added simulation context
         */
-       SimulationContext addProjectContext(Study aStudy,
-                       SimulationContext context);
+       SimulationContext addProjectContext(Study aStudy, SimulationContext context);
 
        /**
         * Remove a simulation context from a study.
@@ -175,7 +173,7 @@ public interface StudyService {
         * @see #isPublic()
         */
        boolean moveToPublic(Study aStudy);
-       
+
        /**
         * Moves this study from the Public to the Private area of the repository.
         * 
@@ -207,7 +205,7 @@ public interface StudyService {
         *            new properties of the study
         * @return true if the study has been updated successfully
         * @throws InvalidPropertyException
-        *             if some property doesn't exist
+        *             if an invalid value is passed to a property
         */
        boolean update(Study aStudy, Properties sprop)
                        throws InvalidPropertyException;
@@ -263,58 +261,71 @@ public interface StudyService {
         * @return the unmodifiable not null transient list of contributors of this study
         */
        List<User> getContributors(Study aStudy);
-       
+
        /**
         * Mark study as reference.
         * 
-        * @param aStudy - the Study
+        * @param aStudy -
+        *            the Study
         */
        void markStudyAsReference(Study aStudy);
-       
+
        /**
-        * Remove study as reference.
-        * This operation is inverse one to Mark as reference.
+        * Remove study as reference. This operation is inverse one to Mark as reference.
         * 
-        * @param aStudy - the Study
+        * @param aStudy -
+        *            the Study
         */
        void removeStudyAsReference(Study aStudy);
-       
+
        /**
-        * Get the description attribute related to the study
-        *              (there supposed to be the only one such attribute in the database).
-        * @param studyId the study id
+        * Get the description attribute related to the study (there supposed to be the only one such attribute in the database).
+        * 
+        * @param studyId
+        *            the study id
         * @return the description attribute value (null if does not exist)
-        * @throws InvalidParameterException if a study with such id does not exist in the database.
+        * @throws InvalidParameterException
+        *             if a study with such id does not exist in the database.
         */
        String getDescription(Long studyId) throws InvalidParameterException;
-       
+
        /**
         * Set the description attribute related to the study.
-        * @param studyId the study id
-        * @param descriptionText the description text
-        * @throws InvalidParameterException if some parameters are invalid.
+        * 
+        * @param studyId
+        *            the study id
+        * @param descriptionText
+        *            the description text
+        * @throws InvalidParameterException
+        *             if some parameters are invalid.
         */
-       void setDescription(Long studyId, String descriptionText) throws InvalidParameterException;
+       void setDescription(Long studyId, String descriptionText)
+                       throws InvalidParameterException;
 
        /**
         * Remove a description attached to a study.
         * 
-        * @param studyId the study id
+        * @param studyId
+        *            the study id
         * @throws InvalidParameterException
-        *              if no study with such Id has been found in the database.
+        *             if no study with such Id has been found in the database.
         * @return true if succeeded, false if study doesn't have a description.
         */
-       boolean removeDescription(final Long studyId) throws InvalidParameterException;
-       
+       boolean removeDescription(final Long studyId)
+                       throws InvalidParameterException;
+
        /**
         * Compare the studies and generate the file that contains the result chart.
-        * @param docsList the list of dtos each contains information: 
-        *        StudyTitle, ScenarioTitle, PathToFile in vault. 
-        * @param userName the name of the user who compare the results.       
+        * 
+        * @param docsList
+        *            the list of dtos each contains information: StudyTitle, ScenarioTitle, PathToFile in vault.
+        * @param userName
+        *            the name of the user who compare the results.
         * @throws IncompatibleDataException
-        *         if data is incompatible for "Compare the studies" functionality.
+        *             if data is incompatible for "Compare the studies" functionality.
         * 
         * @return path to result file in the vault.
         */
-       String compare (List<DocToCompareDTO> docsList, final String userName) throws IncompatibleDataException;
+       String compare(List<DocToCompareDTO> docsList, final String userName)
+                       throws IncompatibleDataException;
 }