← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14199: minor fix, handle collections with non-identifiable objects

 

------------------------------------------------------------
revno: 14199
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-03-12 18:30:37 +0100
message:
  minor fix, handle collections with non-identifiable objects
modified:
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ReflectionUtils.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebUtils.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-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ReflectionUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ReflectionUtils.java	2014-03-06 04:16:46 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ReflectionUtils.java	2014-03-12 17:30:37 +0000
@@ -404,7 +404,7 @@
         return methods;
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public static <T> T invokeMethod( Object target, Method method, Object... args )
     {
         try
@@ -421,7 +421,7 @@
         }
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public static <T> T getFieldObject( Field field, T target )
     {
         return (T) invokeGetterMethod( field.getName(), target );
@@ -745,6 +745,8 @@
                 }
                 else if ( Collection.class.isAssignableFrom( returnType ) )
                 {
+                    descriptor.setCollection( true );
+
                     Type type = method.getGenericReturnType();
 
                     if ( ParameterizedType.class.isInstance( type ) )
@@ -754,7 +756,6 @@
 
                         if ( IdentifiableObject.class.isAssignableFrom( klass ) )
                         {
-                            descriptor.setCollection( true );
                             descriptor.setIdentifiableObject( true );
                         }
                     }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebUtils.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebUtils.java	2014-03-10 18:36:41 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebUtils.java	2014-03-12 17:30:37 +0000
@@ -335,35 +335,32 @@
 
             if ( value.isEmpty() )
             {
-                if ( !descriptor.isCollection() && !descriptor.isIdentifiableObject() )
+                if ( !descriptor.isIdentifiableObject() )
                 {
                     output.put( key, returned );
                 }
-                else if ( descriptor.isIdentifiableObject() )
-                {
-                    if ( descriptor.isCollection() )
-                    {
-                        List<Map<String, Object>> properties = getIdentifiableObjectCollectionProperties( returned );
-                        output.put( key, properties );
-                    }
-                    else
-                    {
-                        Map<String, Object> properties = getIdentifiableObjectProperties( returned );
-                        output.put( key, properties );
-                    }
+                else if ( !descriptor.isCollection() )
+                {
+                    Map<String, Object> properties = getIdentifiableObjectProperties( returned );
+                    output.put( key, properties );
+                }
+                else if ( descriptor.isCollection() )
+                {
+                    List<Map<String, Object>> properties = getIdentifiableObjectCollectionProperties( returned );
+                    output.put( key, properties );
                 }
             }
             else
             {
                 if ( descriptor.isCollection() )
                 {
-                    Collection<IdentifiableObject> objects = (Collection<IdentifiableObject>) returned;
+                    Collection<?> objects = (Collection<?>) returned;
                     ArrayList<Object> arrayList = Lists.newArrayList();
                     output.put( key, arrayList );
 
-                    for ( IdentifiableObject identifiableObject : objects )
+                    for ( Object obj : objects )
                     {
-                        Map<String, Object> properties = buildObjectOutput( identifiableObject, value );
+                        Map<String, Object> properties = buildObjectOutput( obj, value );
                         arrayList.add( properties );
                     }
                 }