]> SALOME platform Git repositories - tools/siman.git/blobdiff - Workspace/Siman-Common/src/org/splat/service/SimulationContextServiceImpl.java
Salome HOME
Refactoring continues: UserService is created instead of UserDirectory. Database...
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / service / SimulationContextServiceImpl.java
index 81abc66eb2f1cfac6554bd8954bba5b5ef32aad0..0b31930a084eb1a5c105a15f5a75057336e5352a 100644 (file)
@@ -17,12 +17,12 @@ import org.hibernate.criterion.Restrictions;
 import org.splat.dal.bo.som.ProgressState;
 import org.splat.dal.bo.som.SimulationContext;
 import org.splat.dal.bo.som.SimulationContextType;
-import org.splat.dal.dao.som.Database;
 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.technical.ProjectSettingsService;
+import org.splat.service.technical.ProjectSettingsServiceImpl;
 import org.springframework.transaction.annotation.Transactional;
 
 /**
@@ -108,8 +108,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 +118,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(
@@ -161,12 +161,10 @@ public class SimulationContextServiceImpl implements SimulationContextService {
         * 
         * @see org.splat.service.SimulationContextService#selectAllTypes()
         */
-       @SuppressWarnings("unchecked")
        public List<SimulationContextType> selectAllTypes() {
                // Useless to order by names as the result mixes localized
                // and non localized types
-               return getSimulationContextTypeDAO().getFilteredList(null,
-                               Order.asc("step"));
+               return getSimulationContextTypeDAO().getAll(Order.asc("step"));
        }
 
        /**
@@ -174,19 +172,23 @@ public class SimulationContextServiceImpl implements SimulationContextService {
         * 
         * @see org.splat.service.SimulationContextService#selectTypesOf(org.splat.service.technical.ProjectSettingsService.Step[])
         */
-       @SuppressWarnings("unchecked")
        public List<SimulationContextType> selectTypesOf(
                        ProjectSettingsService.Step... step) {
-               // --------------------------------------------------------------------------------------
-               StringBuffer query = new StringBuffer(
-                               "from SimulationContextType where step='").append(
-                               step[0].getNumber()).append("'");
+               // StringBuffer query = new StringBuffer(
+               // "from SimulationContextType where step='").append(
+               // step[0].getNumber()).append("'");
+               // for (int i = 1; i < step.length; i++) { // Useless to order as the result mixes localized and non localized types
+               // query = query.append(" or step='").append(step[i].getNumber())
+               // .append("'");
+               // }
+               // 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
-                       query = query.append(" or step='").append(step[i].getNumber())
-                                       .append("'");
+                       aCondition = Restrictions.or(aCondition,
+                                       Restrictions.eq("step", step[i].getNumber()));
                }
-               query = query.append(" order by step asc");
-               return Database.getSession().createQuery(query.toString()).list();
+               return getSimulationContextTypeDAO().getFilteredList(aCondition,
+                               Order.asc("step"));
        }
 
        /**
@@ -194,34 +196,51 @@ public class SimulationContextServiceImpl implements SimulationContextService {
         * 
         * @see org.splat.service.SimulationContextService#selectTypesWhere(org.splat.dal.bo.som.SimulationContextType.Properties)
         */
-       @SuppressWarnings("unchecked")
        public List<SimulationContextType> selectTypesWhere(
                        SimulationContextType.Properties sprop) {
-               StringBuffer query = new StringBuffer("from SimulationContextType");
-               String separator = " where";
+               // StringBuffer query = new StringBuffer("from SimulationContextType");
+               // String separator = " where";
                ProjectSettingsService.Step step = sprop.getStep();
                ProgressState state = sprop.getProgressState();
-               String order = " order by step asc";
-
+               // String order = " order by step asc";
+               //
+               // if (step != null) {
+               // query = query.append(separator).append(" step='")
+               // .append(step.getNumber()).append("'");
+               // separator = " and";
+               // order = " order by state desc"; // APPROVED (upper case A) is grater than inCHECK (lower case i)
+               // }
+               // if (state != null) {
+               // query = query.append(separator).append(" state='")
+               // .append(state.toString()).append("'");
+               // // separator = " and";
+               // if (step != null) {
+               // if (state != ProgressState.APPROVED)
+               // order = " order by name asc";
+               // else
+               // order = ""; // Approved types are localized
+               // }
+               // }
+               // query = query.append(order);
+               Criterion aCondition = null;
+               Order anOrder = Order.asc("step");
                if (step != null) {
-                       query = query.append(separator).append(" step='").append(
-                                       step.getNumber()).append("'");
-                       separator = " and";
-                       order = " order by state desc"; // APPROVED (upper case A) is grater than inCHECK (lower case i)
+                       aCondition = Restrictions.eq("step", step.getNumber());
+                       anOrder = Order.desc("state"); // APPROVED (upper case A) is grater than inCHECK (lower case i)
                }
                if (state != null) {
-                       query = query.append(separator).append(" state='").append(
-                                       state.toString()).append("'");
-                       // separator = " and";
+                       aCondition = Restrictions.and(aCondition,
+                                       Restrictions.eq("state", state));
                        if (step != null) {
-                               if (state != ProgressState.APPROVED)
-                                       order = " order by name asc";
-                               else
-                                       order = ""; // Approved types are localized
+                               if (state != ProgressState.APPROVED) {
+                                       anOrder = Order.asc("name");
+                               } else {
+                                       anOrder = null; // Approved types are localized
+                               }
                        }
                }
-               query = query.append(order);
-               return Database.getSession().createQuery(query.toString()).list();
+               return getSimulationContextTypeDAO().getFilteredList(aCondition,
+                               anOrder);
        }
 
        /**
@@ -268,6 +287,47 @@ public class SimulationContextServiceImpl implements SimulationContextService {
                }
        }
 
+       /**
+        * Approve the simulation context.
+        * 
+        * @param simCtx
+        *            the context to approve
+        * @return true if approval succeeded
+        */
+       public boolean approve(SimulationContext simCtx) {
+               if (simCtx.getProgressState() != ProgressState.inCHECK)
+                       return false;
+               simCtx.setProgressState(ProgressState.APPROVED); // The type name is supposed being localized
+               if (simCtx.isSaved()) {
+                       getSimulationContextDAO().update(simCtx);
+               }
+               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
+        */
+       public ProjectSettingsService.Step getAttachedStep(
+                       SimulationContextType simCtxType) {
+               return ProjectSettingsServiceImpl.getStep(simCtxType.getStep());
+       }
+
        /**
         * Get the simulationContextDAO.
         *