← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15590: Minor logic change in DefaultFilterService

 

------------------------------------------------------------
revno: 15590
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2014-06-07 21:14:09 +0200
message:
  Minor logic change in DefaultFilterService
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFilterService.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-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-07 13:45:37 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFilterService.java	2014-06-07 19:14:09 +0000
@@ -159,40 +159,47 @@
 
             if ( fieldValue.isEmpty() )
             {
+                List<String> fields = FilterService.FIELD_PRESETS.get( "identifiable" );
+
                 if ( property.isCollection() )
                 {
+                    Collection<?> collection = (Collection<?>) returnValue;
+
+                    CollectionNode collectionNode = complexNode.addChild( new CollectionNode( property.getCollectionName() ) );
+                    collectionNode.setNamespace( property.getNamespaceURI() );
+
                     if ( property.isIdentifiableObject() )
                     {
-                        complexNode.addChild( getCollectionProperties( returnValue, FilterService.FIELD_PRESETS.get( "identifiable" ), property ) );
+                        for ( Object collectionObject : collection )
+                        {
+                            collectionNode.addChild( getProperties( collectionObject, fields ) );
+                        }
                     }
-                    else
+                    else if ( !property.isSimple() )
                     {
-                        CollectionNode collectionNode = complexNode.addChild( new CollectionNode( property.getCollectionName() ) );
-                        collectionNode.setNamespace( property.getNamespaceURI() );
-
                         Map<String, Map> map = getFullFieldMap( schemaService.getDynamicSchema( property.getItemKlass() ) );
 
-                        for ( Object collectionObject : (Collection<?>) returnValue )
+                        for ( Object collectionObject : collection )
                         {
-                            if ( map.isEmpty() )
-                            {
-                                collectionNode.addChild( new SimpleNode( property.getName(), collectionObject ) );
-                            }
-                            else
-                            {
-                                ComplexNode node = buildObjectOutput( map, collectionObject );
+                            ComplexNode node = buildObjectOutput( map, collectionObject );
 
-                                if ( !node.getChildren().isEmpty() )
-                                {
-                                    collectionNode.addChild( node );
-                                }
+                            if ( !node.getChildren().isEmpty() )
+                            {
+                                collectionNode.addChild( node );
                             }
                         }
                     }
+                    else
+                    {
+                        for ( Object collectionObject : collection )
+                        {
+                            collectionNode.addChild( new SimpleNode( property.getName(), collectionObject ) );
+                        }
+                    }
                 }
                 else if ( property.isIdentifiableObject() )
                 {
-                    complexNode.addChild( getProperties( returnValue, FilterService.FIELD_PRESETS.get( "identifiable" ) ) );
+                    complexNode.addChild( getProperties( returnValue, fields ) );
                 }
                 else
                 {
@@ -312,32 +319,6 @@
         return map;
     }
 
-    @SuppressWarnings( "unchecked" )
-    private CollectionNode getCollectionProperties( Object object, List<String> fields, Property property )
-    {
-        if ( object == null )
-        {
-            return null;
-        }
-
-        if ( !Collection.class.isInstance( object ) )
-        {
-            return null;
-        }
-
-        CollectionNode collectionNode = new CollectionNode( property.getCollectionName() );
-        collectionNode.setNamespace( property.getNamespaceURI() );
-
-        Collection<?> collection = (Collection<?>) object;
-
-        for ( Object collectionObject : collection )
-        {
-            collectionNode.addChild( getProperties( collectionObject, fields ) );
-        }
-
-        return collectionNode;
-    }
-
     private ComplexNode getProperties( Object object, List<String> fields )
     {
         if ( object == null )
@@ -374,7 +355,7 @@
         return complexNode;
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     private <T> boolean evaluateWithFilters( T object, Filters filters )
     {
         Schema schema = schemaService.getDynamicSchema( object.getClass() );