← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15653: allow deep path on /api/type/id/property, /api/type/id/a/b/c works as alias for /api/type/id?fiel...

 

------------------------------------------------------------
revno: 15653
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-06-12 17:01:50 +0200
message:
  allow deep path on /api/type/id/property, /api/type/id/a/b/c works as alias for /api/type/id?fields=a[b[c]]
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.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/webapi/controller/AbstractCrudController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java	2014-06-11 20:34:56 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java	2014-06-12 15:01:50 +0000
@@ -68,6 +68,7 @@
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.servlet.HandlerMapping;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -192,12 +193,32 @@
         return rootNode;
     }
 
-    @RequestMapping( value = "/{uid}/{property}", method = RequestMethod.GET )
+    @RequestMapping( value = "/{uid}/**", method = RequestMethod.GET )
     public @ResponseBody RootNode getObjectProperty( @PathVariable( "uid" ) String uid,
-        @PathVariable( "property" ) String propertyName, @RequestParam Map<String, String> parameters,
-        HttpServletRequest request, HttpServletResponse response ) throws Exception
+        @RequestParam Map<String, String> parameters, HttpServletRequest request, HttpServletResponse response ) throws Exception
     {
-        return getObjectInternal( uid, parameters, Lists.<String>newArrayList(), Lists.newArrayList( propertyName ) );
+        String requestUrl = (String) request.getAttribute( HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE );
+        String[] fields = requestUrl.split( "/" );
+
+        String field = "";
+        String postfix = "";
+
+        for ( int i = 3; i < fields.length; i++ )
+        {
+            if ( i > 3 )
+            {
+                field += "[" + fields[i];
+                postfix += "]";
+            }
+            else
+            {
+                field = fields[i];
+            }
+        }
+
+        field += postfix;
+
+        return getObjectInternal( uid, parameters, Lists.<String>newArrayList(), Lists.newArrayList( field ) );
     }
 
     @RequestMapping( value = "/{uid}", method = RequestMethod.GET )