← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15572: properly handle collection of non-identifiable objects in field filtering

 

------------------------------------------------------------
revno: 15572
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-06-06 13:59:40 +0200
message:
  properly handle collection of non-identifiable objects in field filtering
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultPropertyIntrospectorService.java
  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-api/src/main/java/org/hisp/dhis/schema/Property.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java	2014-06-03 08:19:42 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java	2014-06-06 11:59:40 +0000
@@ -49,6 +49,11 @@
     private Class<?> klass;
 
     /**
+     * If this property is a collection, this is the class of the items inside the collection.
+     */
+    private Class<?> itemKlass;
+
+    /**
      * Direct link to getter for this property.
      */
     private Method getterMethod;
@@ -131,6 +136,18 @@
         this.klass = klass;
     }
 
+    @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public Class<?> getItemKlass()
+    {
+        return itemKlass;
+    }
+
+    public void setItemKlass( Class<?> itemKlass )
+    {
+        this.itemKlass = itemKlass;
+    }
+
     public Method getGetterMethod()
     {
         return getterMethod;

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultPropertyIntrospectorService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultPropertyIntrospectorService.java	2014-06-03 08:19:42 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultPropertyIntrospectorService.java	2014-06-06 11:59:40 +0000
@@ -186,6 +186,7 @@
                     {
                         ParameterizedType parameterizedType = (ParameterizedType) type;
                         Class<?> klass = (Class<?>) parameterizedType.getActualTypeArguments()[0];
+                        property.setItemKlass( klass );
 
                         if ( IdentifiableObject.class.isAssignableFrom( klass ) )
                         {

=== 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-06 11:09:36 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFilterService.java	2014-06-06 11:59:40 +0000
@@ -167,7 +167,20 @@
                     }
                     else
                     {
-                        complexNode.addChild( getCollectionProperties( returnValue, Lists.newArrayList( propertySchema.getPropertyMap().keySet() ), property ) );
+                        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 )
+                        {
+                            ComplexNode node = buildObjectOutput( map, collectionObject );
+
+                            if ( !node.getChildren().isEmpty() )
+                            {
+                                collectionNode.addChild( node );
+                            }
+                        }
                     }
                 }
                 else if ( property.isIdentifiableObject() )