dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #42387
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21671: various fixes for QueryUtils.getValue, support secondary class for collection types, allows prope...
------------------------------------------------------------
revno: 21671
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2016-01-08 23:26:00 +0700
message:
various fixes for QueryUtils.getValue, support secondary class for collection types, allows proper parsing of :in: filter (including correct type conversion)
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/DefaultQueryParser.java
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/operators/InOperator.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/Operator.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/DefaultQueryParser.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/DefaultQueryParser.java 2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/DefaultQueryParser.java 2016-01-08 16:26:00 +0000
@@ -194,11 +194,11 @@
}
case "in":
{
- return Restrictions.in( path, QueryUtils.getValue( Collection.class, arg ) );
+ return Restrictions.in( path, QueryUtils.getValue( Collection.class, property.getKlass(), arg ) );
}
case "!in":
{
- return Restrictions.notIn( path, QueryUtils.getValue( Collection.class, arg ) );
+ return Restrictions.notIn( path, QueryUtils.getValue( Collection.class, property.getKlass(), arg ) );
}
case "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 2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/QueryUtils.java 2016-01-08 16:26:00 +0000
@@ -33,8 +33,10 @@
import com.google.common.collect.Lists;
import org.hisp.dhis.system.util.DateUtils;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
+import java.util.List;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -44,6 +46,12 @@
@SuppressWarnings( { "rawtypes", "unchecked" } )
static public <T> T getValue( Class<T> klass, Object objectValue )
{
+ return getValue( klass, null, objectValue );
+ }
+
+ @SuppressWarnings( { "rawtypes", "unchecked" } )
+ static public <T> T getValue( Class<T> klass, Class<?> secondaryKlass, Object objectValue )
+ {
if ( klass.isInstance( objectValue ) )
{
return (T) objectValue;
@@ -117,7 +125,26 @@
}
String[] split = value.substring( 1, value.length() - 1 ).split( "," );
- return (T) Lists.newArrayList( split );
+ List<String> items = Lists.newArrayList( split );
+
+ if ( secondaryKlass != null )
+ {
+ List<Object> convertedList = new ArrayList<>();
+
+ for ( String item : items )
+ {
+ Object convertedValue = getValue( secondaryKlass, null, item );
+
+ if ( convertedValue != null )
+ {
+ convertedList.add( convertedValue );
+ }
+ }
+
+ return (T) convertedList;
+ }
+
+ return (T) items;
}
return null;
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/InOperator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/InOperator.java 2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/InOperator.java 2016-01-08 16:26:00 +0000
@@ -50,7 +50,7 @@
@Override
public Criterion getHibernateCriterion( Property property )
{
- return Restrictions.in( property.getFieldName(), getValue( Collection.class, args.get( 0 ) ) );
+ return Restrictions.in( property.getFieldName(), getValue( Collection.class, property.getKlass(), args.get( 0 ) ) );
}
@Override
@@ -115,9 +115,10 @@
}
else if ( type.isEnum() )
{
+ String s1 = String.valueOf( item );
String s2 = String.valueOf( object );
- return item != null && s2.equals( item );
+ return s1 != null && s2.equals( s1 );
}
return false;
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/Operator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/Operator.java 2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/Operator.java 2016-01-08 16:26:00 +0000
@@ -73,9 +73,14 @@
return args;
}
+ protected <T> T getValue( Class<T> klass, Class<?> secondaryClass, int idx )
+ {
+ return QueryUtils.getValue( klass, secondaryClass, args.get( idx ) );
+ }
+
protected <T> T getValue( Class<T> klass, int idx )
{
- return QueryUtils.getValue( klass, args.get( idx ) );
+ return QueryUtils.getValue( klass, null, args.get( idx ) );
}
protected <T> T getValue( Class<T> klass )
@@ -83,6 +88,11 @@
return getValue( klass, 0 );
}
+ protected <T> T getValue( Class<T> klass, Class<?> secondaryClass, Object value )
+ {
+ return QueryUtils.getValue( klass, secondaryClass, value );
+ }
+
protected <T> T getValue( Class<T> klass, Object value )
{
return QueryUtils.getValue( klass, value );