Salome HOME
SimulationContextFacade has been moved into Siman-Common. Import document action...
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / service / SimulationContextServiceImpl.java
index 0b31930a084eb1a5c105a15f5a75057336e5352a..7165cd2c1ec77b07a076ce67a2821f2b738c08f5 100644 (file)
@@ -9,7 +9,9 @@
 
 package org.splat.service;
 
+import java.util.Iterator;
 import java.util.List;
+import java.util.Vector;
 
 import org.hibernate.criterion.Criterion;
 import org.hibernate.criterion.Order;
@@ -21,6 +23,7 @@ import org.splat.dal.dao.som.SimulationContextDAO;
 import org.splat.dal.dao.som.SimulationContextTypeDAO;
 import org.splat.kernel.InvalidPropertyException;
 import org.splat.log.AppLogger;
+import org.splat.service.dto.SimulationContextFacade;
 import org.splat.service.technical.ProjectSettingsService;
 import org.splat.service.technical.ProjectSettingsServiceImpl;
 import org.springframework.transaction.annotation.Transactional;
@@ -47,6 +50,35 @@ public class SimulationContextServiceImpl implements SimulationContextService {
         * Injected simulation context type DAO.
         */
        private SimulationContextTypeDAO _simulationContextTypeDAO;
+       /**
+        * Injected project settings service.
+        */
+       private ProjectSettingsService _projectSettingsService;
+
+       /**
+        * Get simulation contexts which are currently in the given state.
+        * 
+        * @param aState
+        *            the progress state to filter contexts
+        * @return the list of found contexts as a vector of SimulationContextFacade
+        * @throws InvalidPropertyException
+        *             if the given state is invalid
+        */
+       @Transactional(readOnly=true)
+       public Vector<SimulationContextFacade> getSimulationContextsInState(
+                       ProgressState aState) throws InvalidPropertyException {
+               SimulationContext.Properties cprop = new SimulationContext.Properties();
+               List<SimulationContext> context = selectSimulationContextsWhere(cprop
+                               .setState(aState));
+
+               Vector<SimulationContextFacade> result = new Vector<SimulationContextFacade>(
+                               context.size());
+               for (Iterator<SimulationContext> i = context.iterator(); i.hasNext();) {
+                       result.add(new SimulationContextFacade(i.next(),
+                                       getProjectSettings().getAllSteps()));
+               }
+               return result;
+       }
 
        /**
         * {@inheritDoc}
@@ -108,8 +140,8 @@ public class SimulationContextServiceImpl implements SimulationContextService {
                        // .append("'");
                        // separator = " and";
 
-                       aCondition = Restrictions.and(aCondition,
-                                       Restrictions.eq("value", value));
+                       aCondition = Restrictions.and(aCondition, Restrictions.eq("value",
+                                       value));
                }
                if (state != null) {
                        // query = query.append(separator).append(" state='").append(state)
@@ -118,8 +150,8 @@ public class SimulationContextServiceImpl implements SimulationContextService {
                                // order = " order by type asc";
                                anOrder = Order.asc("type");
                        }
-                       aCondition = Restrictions.and(aCondition,
-                                       Restrictions.eq("state", state));
+                       aCondition = Restrictions.and(aCondition, Restrictions.eq("state",
+                                       state));
                }
                // query.append(order);
                // return (List<SimulationContext>) Database.getSession().createQuery(
@@ -141,21 +173,6 @@ public class SimulationContextServiceImpl implements SimulationContextService {
                return resList;
        }
 
-       /**
-        * {@inheritDoc}
-        * 
-        * @see org.splat.service.SimulationContextService#createType(java.lang.String, org.splat.service.technical.ProjectSettingsService.Step)
-        */
-       @Transactional
-       public SimulationContextType createType(String name,
-                       ProjectSettingsService.Step step) throws InvalidPropertyException {
-               // TODO: Check for duplicate definition
-               SimulationContextType type = new SimulationContextType(name, step);
-               getSimulationContextTypeDAO().create(type);
-
-               return type;
-       }
-
        /**
         * {@inheritDoc}
         * 
@@ -184,8 +201,8 @@ public class SimulationContextServiceImpl implements SimulationContextService {
                // query = query.append(" order by step asc");
                Criterion aCondition = Restrictions.eq("step", step[0].getNumber());
                for (int i = 1; i < step.length; i++) { // Useless to order as the result mixes localized and non localized types
-                       aCondition = Restrictions.or(aCondition,
-                                       Restrictions.eq("step", step[i].getNumber()));
+                       aCondition = Restrictions.or(aCondition, Restrictions.eq("step",
+                                       step[i].getNumber()));
                }
                return getSimulationContextTypeDAO().getFilteredList(aCondition,
                                Order.asc("step"));
@@ -229,8 +246,8 @@ public class SimulationContextServiceImpl implements SimulationContextService {
                        anOrder = Order.desc("state"); // APPROVED (upper case A) is grater than inCHECK (lower case i)
                }
                if (state != null) {
-                       aCondition = Restrictions.and(aCondition,
-                                       Restrictions.eq("state", state));
+                       aCondition = Restrictions.and(aCondition, Restrictions.eq("state",
+                                       state));
                        if (step != null) {
                                if (state != ProgressState.APPROVED) {
                                        anOrder = Order.asc("name");
@@ -304,21 +321,6 @@ public class SimulationContextServiceImpl implements SimulationContextService {
                return true;
        }
 
-       /**
-        * Approve the simulation context type.
-        * 
-        * @param simCtxType
-        *            the type to approve
-        * @return true if approval succeeded
-        */
-       public boolean approve(SimulationContextType simCtxType) {
-               if (simCtxType.getState() != ProgressState.inCHECK)
-                       return false;
-               simCtxType.setState(ProgressState.APPROVED); // The type name is supposed being localized
-               getSimulationContextTypeDAO().update(simCtxType);
-               return true;
-       }
-
        /**
         * @param simCtxType
         * @return
@@ -367,4 +369,23 @@ public class SimulationContextServiceImpl implements SimulationContextService {
                        SimulationContextTypeDAO simulationContextTypeDAO) {
                _simulationContextTypeDAO = simulationContextTypeDAO;
        }
+
+       /**
+        * Get project settings.
+        * 
+        * @return Project settings service
+        */
+       private ProjectSettingsService getProjectSettings() {
+               return _projectSettingsService;
+       }
+
+       /**
+        * Set project settings service.
+        * 
+        * @param projectSettingsService
+        *            project settings service
+        */
+       public void setProjectSettings(ProjectSettingsService projectSettingsService) {
+               _projectSettingsService = projectSettingsService;
+       }
 }