← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15732: use property name when building output in filterService

 

------------------------------------------------------------
revno: 15732
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-06-17 17:16:25 +0200
message:
  use property name when building output in filterService
modified:
  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/FilterService.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-17 14:35:37 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFilterService.java	2014-06-17 15:16:25 +0000
@@ -121,14 +121,14 @@
 
         for ( Object object : objects )
         {
-            collectionNode.addChild( buildObjectOutput( fieldMap, klass, object ) );
+            collectionNode.addChild( buildComplexNode( fieldMap, klass, object ) );
         }
 
         return collectionNode;
     }
 
     @SuppressWarnings( "unchecked" )
-    private ComplexNode buildObjectOutput( Map<String, Map> fieldMap, Class<?> klass, Object object )
+    private ComplexNode buildComplexNode( Map<String, Map> fieldMap, Class<?> klass, Object object )
     {
         Schema schema = schemaService.getDynamicSchema( klass );
 
@@ -150,6 +150,7 @@
             }
 
             Property property = schema.getPropertyMap().get( fieldKey );
+
             Object returnValue = ReflectionUtils.invokeMethod( object, property.getGetterMethod() );
             Schema propertySchema = schemaService.getDynamicSchema( property.getKlass() );
 
@@ -179,7 +180,7 @@
                     {
                         for ( Object collectionObject : collection )
                         {
-                            collectionNode.addChild( getProperties( property.getItemKlass(), collectionObject, fields ) );
+                            collectionNode.addChild( getProperties( property, collectionObject, fields ) );
                         }
                     }
                     else if ( !property.isSimple() )
@@ -188,7 +189,7 @@
 
                         for ( Object collectionObject : collection )
                         {
-                            ComplexNode node = buildObjectOutput( map, property.getItemKlass(), collectionObject );
+                            ComplexNode node = buildComplexNode( map, property.getItemKlass(), collectionObject );
 
                             if ( !node.getChildren().isEmpty() )
                             {
@@ -206,7 +207,7 @@
                 }
                 else if ( property.isIdentifiableObject() )
                 {
-                    complexNode.addChild( getProperties( property.getKlass(), returnValue, fields ) );
+                    complexNode.addChild( getProperties( property, returnValue, fields ) );
                 }
                 else
                 {
@@ -220,7 +221,7 @@
                     }
                     else
                     {
-                        complexNode.addChild( buildObjectOutput( getFullFieldMap( propertySchema ), property.getKlass(),
+                        complexNode.addChild( buildComplexNode( getFullFieldMap( propertySchema ), property.getKlass(),
                             returnValue ) );
                     }
                 }
@@ -234,7 +235,7 @@
 
                     for ( Object collectionObject : (Collection<?>) returnValue )
                     {
-                        ComplexNode node = buildObjectOutput( fieldValue, property.getItemKlass(), collectionObject );
+                        ComplexNode node = buildComplexNode( fieldValue, property.getItemKlass(), collectionObject );
 
                         if ( !node.getChildren().isEmpty() )
                         {
@@ -244,7 +245,7 @@
                 }
                 else
                 {
-                    ComplexNode node = buildObjectOutput( fieldValue, property.getKlass(), returnValue );
+                    ComplexNode node = buildComplexNode( fieldValue, property.getKlass(), returnValue );
 
                     if ( !node.getChildren().isEmpty() )
                     {
@@ -331,18 +332,28 @@
         return map;
     }
 
-    private ComplexNode getProperties( Class<?> klass, Object object, List<String> fields )
+    private ComplexNode getProperties( Property currentProperty, Object object, List<String> fields )
     {
-        Schema schema = schemaService.getDynamicSchema( klass );
-
-        ComplexNode complexNode = new ComplexNode( schema.getSingular() );
-        complexNode.setNamespace( schema.getNamespace() );
-
         if ( object == null )
         {
             return null;
         }
 
+        ComplexNode complexNode = new ComplexNode( currentProperty.getName() );
+        complexNode.setNamespace( currentProperty.getNamespace() );
+
+        Schema schema;
+
+        if ( currentProperty.isCollection() )
+        {
+            schema = schemaService.getDynamicSchema( currentProperty.getItemKlass() );
+
+        }
+        else
+        {
+            schema = schemaService.getDynamicSchema( currentProperty.getKlass() );
+        }
+
         for ( String field : fields )
         {
             Property property = schema.getPropertyMap().get( field );
@@ -352,9 +363,9 @@
                 continue;
             }
 
-            Object o = ReflectionUtils.invokeMethod( object, property.getGetterMethod() );
+            Object returnValue = ReflectionUtils.invokeMethod( object, property.getGetterMethod() );
 
-            SimpleNode simpleNode = new SimpleNode( field, o );
+            SimpleNode simpleNode = new SimpleNode( field, returnValue );
             simpleNode.setAttribute( property.isAttribute() );
             simpleNode.setNamespace( property.getNamespace() );
 

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/FilterService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/FilterService.java	2014-06-09 10:57:14 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/FilterService.java	2014-06-17 15:16:25 +0000
@@ -54,6 +54,5 @@
      * @param fieldList Field filter
      * @return List of objects with only wanted properties
      */
-    <T extends IdentifiableObject> CollectionNode fieldFilter( Class<?> klass, List<T> objects,
-        List<String> fieldList );
+    <T extends IdentifiableObject> CollectionNode fieldFilter( Class<?> klass, List<T> objects, List<String> fieldList );
 }