← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13950: default to showing only idObjectProps on filtered view

 

------------------------------------------------------------
revno: 13950
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-02-06 16:59:02 +0700
message:
  default to showing only idObjectProps on filtered view
modified:
  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-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-02-06 08:24:34 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebUtils.java	2014-02-06 09:59:02 +0000
@@ -214,11 +214,18 @@
 
                     if ( !ReflectionUtils.isCollection( o ) )
                     {
-                        objMap.put( field, o );
+                        if ( IdentifiableObject.class.isInstance( o ) )
+                        {
+                            objMap.put( field, getIdentifiableObjectProperties( (IdentifiableObject) o ) );
+                        }
+                        else
+                        {
+                            objMap.put( field, o );
+                        }
                     }
                     else
                     {
-                        objMap.put( field, getIdentifiableObjectProperties( o ) );
+                        objMap.put( field, getIdentifiableObjectCollectionProperties( o ) );
                     }
                 }
             }
@@ -230,7 +237,7 @@
     }
 
     @SuppressWarnings( "unchecked" )
-    private static Object getIdentifiableObjectProperties( Object o )
+    private static Object getIdentifiableObjectCollectionProperties( Object o )
     {
         List<Map<String, Object>> idPropertiesList = Lists.newArrayList();
         Collection<IdentifiableObject> identifiableObjects;
@@ -246,22 +253,28 @@
 
         for ( IdentifiableObject identifiableObject : identifiableObjects )
         {
-            Map<String, Object> idProps = Maps.newLinkedHashMap();
-
-            idProps.put( "id", identifiableObject.getUid() );
-            idProps.put( "name", identifiableObject.getDisplayName() );
-
-            if ( identifiableObject.getCode() == null )
-            {
-                idProps.put( "code", identifiableObject.getCode() );
-            }
-
-            idProps.put( "created", identifiableObject.getCreated() );
-            idProps.put( "lastUpdated", identifiableObject.getLastUpdated() );
-
+            Map<String, Object> idProps = getIdentifiableObjectProperties( identifiableObject );
             idPropertiesList.add( idProps );
         }
 
         return idPropertiesList;
     }
+
+    private static Map<String, Object> getIdentifiableObjectProperties( IdentifiableObject identifiableObject )
+    {
+        Map<String, Object> idProps = Maps.newLinkedHashMap();
+
+        idProps.put( "id", identifiableObject.getUid() );
+        idProps.put( "name", identifiableObject.getDisplayName() );
+
+        if ( identifiableObject.getCode() != null )
+        {
+            idProps.put( "code", identifiableObject.getCode() );
+        }
+
+        idProps.put( "created", identifiableObject.getCreated() );
+        idProps.put( "lastUpdated", identifiableObject.getLastUpdated() );
+
+        return idProps;
+    }
 }