=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFilterService.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFilterService.java 2014-06-02 21:07:50 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFilterService.java 2014-06-02 21:35:16 +0000 @@ -47,6 +47,9 @@ */ public class DefaultFilterService implements FilterService { + private static final List IDENTIFIABLE_PROPERTIES = + Lists.newArrayList( "id", "name", "code", "created", "lastUpdated" ); + @Autowired private ParserService parserService; @@ -132,65 +135,62 @@ Map output = Maps.newHashMap(); Schema schema = schemaService.getDynamicSchema( object.getClass() ); - for ( String key : fieldMap.keySet() ) + for ( String fieldKey : fieldMap.keySet() ) { - if ( !schema.getPropertyMap().containsKey( key ) ) - { - continue; - } - - Map value = fieldMap.get( key ); - Property descriptor = schema.getPropertyMap().get( key ); - - Object returned = ReflectionUtils.invokeMethod( object, descriptor.getGetterMethod() ); - - if ( returned == null ) - { - continue; - } - - if ( value.isEmpty() ) - { - if ( !descriptor.isIdentifiableObject() ) + if ( !schema.getPropertyMap().containsKey( fieldKey ) ) + { + continue; + } + + Property property = schema.getPropertyMap().get( fieldKey ); + Object returnValue = ReflectionUtils.invokeMethod( object, property.getGetterMethod() ); + + if ( returnValue == null ) + { + continue; + } + + Map fieldValue = fieldMap.get( fieldKey ); + + if ( fieldValue.isEmpty() ) + { + if ( !property.isIdentifiableObject() ) { - output.put( key, returned ); + output.put( fieldKey, returnValue ); } - else if ( !descriptor.isCollection() ) + else if ( !property.isCollection() ) { - Map properties = getIdentifiableObjectProperties( returned ); - output.put( key, properties ); + output.put( fieldKey, getIdentifiableObjectProperties( returnValue ) ); } else { - List> properties = getIdentifiableObjectCollectionProperties( returned ); - output.put( key, properties ); + output.put( fieldKey, getIdentifiableObjectCollectionProperties( returnValue ) ); } } else { - if ( descriptor.isCollection() ) + if ( property.isCollection() ) { - Collection objects = (Collection) returned; - List arrayList = Lists.newArrayList(); - output.put( key, arrayList ); + List list = Lists.newArrayList(); + output.put( fieldKey, list ); - for ( Object obj : objects ) + for ( Object obj : (Collection) returnValue ) { - Map properties = buildObjectOutput( obj, value ); + Map properties = buildObjectOutput( obj, fieldValue ); if ( !properties.isEmpty() ) { - arrayList.add( properties ); + list.add( properties ); } } } else { - Map properties = buildObjectOutput( returned, value ); + Map map = buildObjectOutput( returnValue, fieldValue ); - if ( !properties.isEmpty() ) + if ( !map.isEmpty() ) { - output.put( key, properties ); + output.put( fieldKey, map ); } } } @@ -201,8 +201,7 @@ private List> getIdentifiableObjectCollectionProperties( Object object ) { - List fields = Lists.newArrayList( "id", "name", "code", "created", "lastUpdated" ); - return getIdentifiableObjectCollectionProperties( object, fields ); + return getIdentifiableObjectCollectionProperties( object, IDENTIFIABLE_PROPERTIES ); } @SuppressWarnings( "unchecked" ) @@ -232,33 +231,32 @@ private Map getIdentifiableObjectProperties( Object object ) { - List fields = Lists.newArrayList( "id", "name", "code", "created", "lastUpdated" ); - return getIdentifiableObjectProperties( object, fields ); + return getIdentifiableObjectProperties( object, IDENTIFIABLE_PROPERTIES ); } private Map getIdentifiableObjectProperties( Object object, List fields ) { - Map idProps = Maps.newLinkedHashMap(); + Map map = Maps.newLinkedHashMap(); Schema schema = schemaService.getDynamicSchema( object.getClass() ); for ( String field : fields ) { - Property descriptor = schema.getPropertyMap().get( field ); + Property property = schema.getPropertyMap().get( field ); - if ( descriptor == null ) + if ( property == null ) { continue; } - Object o = ReflectionUtils.invokeMethod( object, descriptor.getGetterMethod() ); + Object o = ReflectionUtils.invokeMethod( object, property.getGetterMethod() ); if ( o != null ) { - idProps.put( field, o ); + map.put( field, o ); } } - return idProps; + return map; } @SuppressWarnings( "unchecked" )