← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19237: remove duplicate getValue method in CriteriaQueryEngine, now uses getValue from QueryUtils instead

 

------------------------------------------------------------
revno: 19237
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-06-02 10:30:57 +0700
message:
  remove duplicate getValue method in CriteriaQueryEngine, now uses getValue from QueryUtils instead
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/CriteriaQueryEngine.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/QueryUtils.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/CriteriaQueryEngine.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/CriteriaQueryEngine.java	2015-06-01 09:33:06 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/CriteriaQueryEngine.java	2015-06-02 03:30:57 +0000
@@ -37,12 +37,10 @@
 import org.hisp.dhis.hibernate.HibernateGenericStore;
 import org.hisp.dhis.schema.Property;
 import org.hisp.dhis.schema.Schema;
-import org.hisp.dhis.system.util.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -170,6 +168,7 @@
         return criteria;
     }
 
+    @SuppressWarnings( "unchecked" )
     private Criterion getHibernateCriterion( Schema schema, Restriction restriction )
     {
         if ( restriction == null || restriction.getOperator() == null )
@@ -183,7 +182,7 @@
 
         for ( Object parameter : restriction.getParameters() )
         {
-            parameters.add( getValue( property, parameter ) );
+            parameters.add( QueryUtils.getValue( property.getKlass(), parameter ) );
         }
 
         if ( parameters.isEmpty() )
@@ -287,68 +286,4 @@
         initStoreMap();
         return stores.get( klass );
     }
-
-    private Object getValue( Property property, Object objectValue )
-    {
-        Class<?> klass = property.getKlass();
-
-        if ( !String.class.isInstance( objectValue ) )
-        {
-            return objectValue;
-        }
-
-        String value = (String) objectValue;
-
-        if ( klass.isInstance( value ) )
-        {
-            return value;
-        }
-
-        if ( Boolean.class.isAssignableFrom( klass ) )
-        {
-            try
-            {
-                return Boolean.valueOf( value );
-            }
-            catch ( Exception ignored )
-            {
-            }
-        }
-        else if ( Integer.class.isAssignableFrom( klass ) )
-        {
-            try
-            {
-                return Integer.valueOf( value );
-            }
-            catch ( Exception ignored )
-            {
-            }
-        }
-        else if ( Float.class.isAssignableFrom( klass ) )
-        {
-            try
-            {
-                return Float.valueOf( value );
-            }
-            catch ( Exception ignored )
-            {
-            }
-        }
-        else if ( Double.class.isAssignableFrom( klass ) )
-        {
-            try
-            {
-                return Double.valueOf( value );
-            }
-            catch ( Exception ignored )
-            {
-            }
-        }
-        else if ( Date.class.isAssignableFrom( klass ) )
-        {
-            return DateUtils.parseDate( value );
-        }
-
-        return null;
-    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/QueryUtils.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/QueryUtils.java	2015-04-09 08:59:36 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/QueryUtils.java	2015-06-02 03:30:57 +0000
@@ -42,12 +42,19 @@
 public final class QueryUtils
 {
     @SuppressWarnings( "unchecked" )
-    static public <T> T getValue( Class<T> klass, String value )
+    static public <T> T getValue( Class<T> klass, Object objectValue )
     {
-        if ( klass.isInstance( value ) )
-        {
-            return (T) value;
-        }
+        if ( klass.isInstance( objectValue ) )
+        {
+            return (T) objectValue;
+        }
+
+        if ( !String.class.isInstance( objectValue ) )
+        {
+            return (T) objectValue;
+        }
+
+        String value = (String) objectValue;
 
         if ( Boolean.class.isAssignableFrom( klass ) )
         {
@@ -104,7 +111,7 @@
         }
         else if ( Collection.class.isAssignableFrom( klass ) )
         {
-            if ( value == null || !value.startsWith( "[" ) || !value.endsWith( "]" ) )
+            if ( !value.startsWith( "[" ) || !value.endsWith( "]" ) )
             {
                 return null;
             }