=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/InMemoryQueryEngine.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/InMemoryQueryEngine.java 2016-01-04 02:27:49 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/InMemoryQueryEngine.java 2016-01-07 08:48:29 +0000 @@ -34,6 +34,7 @@ import org.hisp.dhis.schema.Property; import org.hisp.dhis.schema.Schema; import org.hisp.dhis.schema.SchemaService; +import org.hisp.dhis.system.util.HibernateUtils; import org.hisp.dhis.system.util.ReflectionUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -45,7 +46,7 @@ /** * @author Morten Olav Hansen */ -public class InMemoryQueryEngine +public class InMemoryQueryEngine implements QueryEngine { @Autowired @@ -241,7 +242,16 @@ throw new QueryException( "No property found for path " + path ); } - object = ReflectionUtils.invokeMethod( object, property.getGetterMethod() ); + if ( property.isCollection() ) + { + currentSchema = schemaService.getDynamicSchema( property.getItemKlass() ); + } + else + { + currentSchema = schemaService.getDynamicSchema( property.getKlass() ); + } + + object = collect( object, property ); if ( i == (paths.length - 1) ) { @@ -253,36 +263,37 @@ return object; } - if ( property.isCollection() ) - { - currentSchema = schemaService.getDynamicSchema( property.getItemKlass() ); - } - else - { - currentSchema = schemaService.getDynamicSchema( property.getKlass() ); - } - - if ( property.isCollection() && i == (paths.length - 2) ) - { - property = currentSchema.getProperty( paths[paths.length - 1] ); - - if ( property == null ) - { - throw new QueryException( "No property found for path " + path ); - } - - Collection collection = (Collection) object; - List items = new ArrayList<>(); - - for ( Object item : collection ) - { - items.add( ReflectionUtils.invokeMethod( item, property.getGetterMethod() ) ); - } - - return items; - } } throw new QueryException( "No values found for path " + path ); } + + private Object collect( Object object, Property property ) + { + object = HibernateUtils.unwrap( object ); + + if ( Collection.class.isInstance( object ) ) + { + Collection collection = (Collection) object; + List items = new ArrayList<>(); + + for ( Object item : collection ) + { + Object collect = collect( item, property ); + + if ( Collection.class.isInstance( collect ) ) + { + items.addAll( ((Collection) collect) ); + } + else + { + items.add( collect ); + } + } + + return items; + } + + return ReflectionUtils.invokeMethod( object, property.getGetterMethod() ); + } } === modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/InMemoryQueryEngineTest.java' --- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/InMemoryQueryEngineTest.java 2016-01-05 10:16:27 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/InMemoryQueryEngineTest.java 2016-01-07 08:48:29 +0000 @@ -560,6 +560,18 @@ } @Test + public void testCollectionDeep() + { + Query query = Query.from( schemaService.getDynamicSchema( DataElementGroup.class ) ); + query.setObjects( dataElementGroups ); + + query.add( Restrictions.like( "dataElements.dataElementGroups.name", "A", MatchMode.END ) ); + List objects = queryEngine.query( query ); + + System.err.println( "xyz: " + objects ); + } + + @Test public void testCollectionEqSize() { Query query = Query.from( schemaService.getDynamicSchema( DataElementGroup.class ) );