← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15636: add new generic endpoint, /api/type/id/property, allows to get property directly, works as a alia...

 

------------------------------------------------------------
revno: 15636
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-06-11 21:54:06 +0200
message:
  add new generic endpoint, /api/type/id/property, allows to get property directly, works as a alias for ?fields=property
modified:
  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/IdentifiableObjectController.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 11:18:03 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java	2014-06-11 19:54:06 +0000
@@ -191,6 +191,15 @@
         return rootNode;
     }
 
+    @RequestMapping( value = "/{uid}/{property}", method = RequestMethod.GET )
+    public @ResponseBody RootNode getObjectProperty( @PathVariable( "uid" ) String uid,
+        @PathVariable( "property" ) String propertyName, @RequestParam Map<String, String> parameters,
+        Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception
+    {
+        return getObjectInternal( uid, parameters, model, request, response,
+            Lists.<String>newArrayList(), Lists.newArrayList( propertyName ) );
+    }
+
     @RequestMapping( value = "/{uid}", method = RequestMethod.GET )
     public @ResponseBody RootNode getObject( @PathVariable( "uid" ) String uid, @RequestParam Map<String, String> parameters,
         Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception
@@ -203,6 +212,13 @@
             fields.add( ":all" );
         }
 
+        return getObjectInternal( uid, parameters, model, request, response, filters, fields );
+    }
+
+    private RootNode getObjectInternal( String uid, Map<String, String> parameters,
+        Model model, HttpServletRequest request, HttpServletResponse response,
+        List<String> filters, List<String> fields ) throws Exception
+    {
         WebOptions options = new WebOptions( parameters );
         List<T> entities = getEntity( uid, options );
 

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/IdentifiableObjectController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/IdentifiableObjectController.java	2014-06-11 11:03:34 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/IdentifiableObjectController.java	2014-06-11 19:54:06 +0000
@@ -40,7 +40,7 @@
  * @author Lars Helge Overland
  */
 @Controller
-@RequestMapping(value = IdentifiableObjectController.RESOURCE_PATH)
+@RequestMapping( value = IdentifiableObjectController.RESOURCE_PATH )
 public class IdentifiableObjectController
     extends AbstractCrudController<IdentifiableObject>
 {