Salome HOME
Logger is changed to AppLogger
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / service / StudyServiceImpl.java
index ab57263c27ca9cf22ba4cbb41c1dbe988262412e..0af12a2baf98965dc31336e154ba1ebaa28b9a80 100644 (file)
@@ -1,10 +1,10 @@
 /*****************************************************************************
  * Company         EURIWARE
  * Application     SIMAN
- * File            $Id$ 
- * Creation date   06.10.2012
- * @author         $Author$
- * @version        $Revision$
+ * File            Id: 
+ * Creation date   02.10.2012
+ * @author         Author: Maria KRUCHININA
+ * @version        Revision: 
  *****************************************************************************/
 
 package org.splat.service;
@@ -17,6 +17,7 @@ import java.util.List;
 
 import org.apache.log4j.Logger;
 import org.hibernate.Session;
+import org.hibernate.Transaction;
 import org.splat.dal.bo.kernel.Relation;
 import org.splat.dal.bo.kernel.User;
 import org.splat.dal.bo.som.ActorRelation;
@@ -31,6 +32,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.ValidationCycle;
 import org.splat.dal.bo.som.ValidationCycleRelation;
@@ -41,17 +43,22 @@ import org.splat.kernel.InvalidPropertyException;
 import org.splat.kernel.MissedPropertyException;
 import org.splat.kernel.MultiplyDefinedException;
 import org.splat.kernel.UserDirectory;
+import org.splat.log.AppLogger;
 import org.splat.service.technical.IndexService;
 import org.splat.service.technical.ProjectSettingsService;
 import org.splat.som.Revision;
 
 /**
- * @author RKV
- * 
+ * This class defines all methods for creation, modification the study.
+ * @author Maria KRUCHININA
+ *
  */
 public class StudyServiceImpl implements StudyService {
 
-       public final static Logger logger = org.splat.service.StudyServiceImpl.logger;
+       /**
+        * logger for the service.
+        */
+       public final static AppLogger logger = AppLogger.getLogger(StudyServiceImpl.class);
 
        private IndexService _indexService;
 
@@ -62,6 +69,48 @@ public class StudyServiceImpl implements StudyService {
        private ProjectSettingsService _projectSettingsService;
 
        private ProjectElementService _projectElementService;
+       
+       /**
+        * Get the simulation context list for displaying drop-down list values populating
+        * on the "Create new study" screen.
+        * {@inheritDoc}
+        * @see org.splat.service.StudyService#getSimulationContextList()
+        */
+       public List<SimulationContext> getSimulationContextList() {
+               //TODO: remove the commit transaction ...
+               Session      connex  = Database.getSession();
+               Transaction  transax = connex.beginTransaction();
+               
+               SimulationContext.Properties cprop   = new SimulationContext.Properties();
+           SimulationContextType        product = SimulationContext.selectType("product");
+           List<SimulationContext> resList = Database.selectSimulationContextsWhere(cprop.setType(product));
+           
+           transax.commit();
+                 
+           return resList;
+       }
+       
+       public Study selectStudy(int index) {
+               // -------------------------------------------
+               StringBuffer query = new StringBuffer("from Study where rid='").append(
+                               index).append("'");
+               Study result = (Study) Database.getSession().createQuery(
+                               query.toString()).uniqueResult();
+
+               result.loadWorkflow();
+               return result;
+       }
+
+       public Study selectStudy(String refid) {
+               // ----------------------------------------------
+               StringBuffer query = new StringBuffer("from Study where sid='").append(
+                               refid).append("'");
+               Study result = (Study) Database.getSession().createQuery(
+                               query.toString()).uniqueResult();
+
+               result.loadWorkflow();
+               return result;
+       }
 
        public Study createStudy(Study.Properties sprop)
                        throws MissedPropertyException, InvalidPropertyException,
@@ -100,17 +149,6 @@ public class StudyServiceImpl implements StudyService {
                return added;
        }
 
-       /**
-        * @return
-        */
-       public StepService getStepService() {
-               return _stepService;
-       }
-
-       public void setStepService(StepService stepService) {
-               _stepService = stepService;
-       }
-
        public SimulationContext addProjectContext(Study aStudy,
                        SimulationContext context) {
                // ----------------------------------------------------------------------
@@ -292,7 +330,7 @@ public class StudyServiceImpl implements StudyService {
 
        public int generateLocalIndex(Study aStudy) {
                aStudy.setLastLocalIndex(aStudy.getLastLocalIndex() + 1);
-               Database.getSession().update(this);
+               Database.getSession().update(aStudy);
                return aStudy.getLastLocalIndex();
        }
 
@@ -320,7 +358,7 @@ public class StudyServiceImpl implements StudyService {
                        aStudy.getScenariiList().add(
                                        aStudy.getScenariiList().indexOf(previous) + 1, scenario);
                }
-               session.update(this); // No need to update the Lucene index
+               session.update(aStudy); // No need to update the Lucene index
                session.save(scenario); // Must be done after updating this study because of the back reference to the study
                if (sprop.getBaseStep() != null) {
                        // No need to update the Knowledge Element index as Knowledge Elements are not copied
@@ -473,4 +511,20 @@ public class StudyServiceImpl implements StudyService {
                        ProjectElementService projectElementService) {
                _projectElementService = projectElementService;
        }
+
+       /**
+        * Get the stepService.
+        * @return the stepService
+        */
+       public StepService getStepService() {
+               return _stepService;
+       }
+
+       /**
+        * Set the stepService.
+        * @param stepService the stepService to set
+        */
+       public void setStepService(StepService stepService) {
+               _stepService = stepService;
+       }
 }