]> SALOME platform Git repositories - tools/siman.git/blobdiff - Workspace/Siman-Common/src/org/splat/service/SimulationContextServiceImpl.java
Salome HOME
Modifications done to respect PMD rules. Versioning a document is fixed. Validation...
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / service / SimulationContextServiceImpl.java
index 209d9637d244dab2c105edab9432c3d7e4c4cf81..34a5cf3773431cdebcbe3fba9384af4c00bc0220 100644 (file)
@@ -38,8 +38,14 @@ public class SimulationContextServiceImpl implements SimulationContextService {
        /**
         * logger for the service.
         */
-       public final static AppLogger logger = AppLogger
+       public final static AppLogger LOG = AppLogger
                        .getLogger(SimulationContextServiceImpl.class);
+       
+       /**
+        * Step property name.
+        */
+       public final static String STEP_PROP = "step";
+       
        /**
         * Injected simulation context DAO.
         */
@@ -52,7 +58,7 @@ public class SimulationContextServiceImpl implements SimulationContextService {
        /**
         * Injected project settings service.
         */
-       private ProjectSettingsService _projectSettingsService;
+       private ProjectSettingsService _projectSettings;
 
        /**
         * Get simulation contexts which are currently in the given state.
@@ -104,7 +110,7 @@ public class SimulationContextServiceImpl implements SimulationContextService {
                                result = clist.get(0); // Supposed being the most used one if many exist
                        }
                } catch (InvalidPropertyException error) {
-                       logger.info("Attempt to select a simulation context \""
+                       LOG.info("Attempt to select a simulation context \""
                                        + celt.getName() + "\" with an invalid value.");
                }
                return result;
@@ -179,7 +185,7 @@ public class SimulationContextServiceImpl implements SimulationContextService {
        public List<SimulationContextType> selectAllTypes() {
                // Useless to order by names as the result mixes localized
                // and non localized types
-               return getSimulationContextTypeDAO().getAll(Order.asc("step"));
+               return getSimulationContextTypeDAO().getAll(Order.asc(STEP_PROP));
        }
 
        /**
@@ -197,13 +203,13 @@ public class SimulationContextServiceImpl implements SimulationContextService {
                // .append("'");
                // }
                // query = query.append(" order by step asc");
-               Criterion aCondition = Restrictions.eq("step", step[0].getNumber());
+               Criterion aCondition = Restrictions.eq(STEP_PROP, 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",
+                       aCondition = Restrictions.or(aCondition, Restrictions.eq(STEP_PROP,
                                        step[i].getNumber()));
                }
                return getSimulationContextTypeDAO().getFilteredList(aCondition,
-                               Order.asc("step"));
+                               Order.asc(STEP_PROP));
        }
 
        /**
@@ -238,19 +244,19 @@ public class SimulationContextServiceImpl implements SimulationContextService {
                // }
                // query = query.append(order);
                Criterion aCondition = null;
-               Order anOrder = Order.asc("step");
+               Order anOrder = Order.asc(STEP_PROP);
                if (step != null) {
-                       aCondition = Restrictions.eq("step", step.getNumber());
+                       aCondition = Restrictions.eq(STEP_PROP, step.getNumber());
                        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));
                        if (step != null) {
-                               if (state != ProgressState.APPROVED) {
-                                       anOrder = Order.asc("name");
-                               } else {
+                               if (state == ProgressState.APPROVED) {
                                        anOrder = null; // Approved types are localized
+                               } else {
+                                       anOrder = Order.asc("name");
                                }
                        }
                }
@@ -310,14 +316,14 @@ public class SimulationContextServiceImpl implements SimulationContextService {
         * @return true if approval succeeded
         */
        public boolean approve(final 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);
+               boolean res = (simCtx.getProgressState() == ProgressState.inCHECK);
+               if (res) {
+                       simCtx.setProgressState(ProgressState.APPROVED); // The type name is supposed being localized
+                       if (simCtx.isSaved()) {
+                               getSimulationContextDAO().update(simCtx);
+                       }
                }
-               return true;
+               return res;
        }
 
        /**
@@ -375,7 +381,7 @@ public class SimulationContextServiceImpl implements SimulationContextService {
         * @return Project settings service
         */
        private ProjectSettingsService getProjectSettings() {
-               return _projectSettingsService;
+               return _projectSettings;
        }
 
        /**
@@ -385,6 +391,6 @@ public class SimulationContextServiceImpl implements SimulationContextService {
         *            project settings service
         */
        public void setProjectSettings(final ProjectSettingsService projectSettingsService) {
-               _projectSettingsService = projectSettingsService;
+               _projectSettings = projectSettingsService;
        }
 }