← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18186: support field filter in /api/trackedEntityInstances/ID endpoint

 

------------------------------------------------------------
revno: 18186
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-02-06 11:16:45 +0700
message:
  support field filter in /api/trackedEntityInstances/ID endpoint
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/TrackedEntityInstanceController.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/event/TrackedEntityInstanceController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/TrackedEntityInstanceController.java	2015-02-06 03:50:03 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/TrackedEntityInstanceController.java	2015-02-06 04:16:45 +0000
@@ -43,6 +43,7 @@
 import org.hisp.dhis.dxf2.utils.JacksonUtils;
 import org.hisp.dhis.event.EventStatus;
 import org.hisp.dhis.importexport.ImportStrategy;
+import org.hisp.dhis.node.types.CollectionNode;
 import org.hisp.dhis.node.types.RootNode;
 import org.hisp.dhis.program.ProgramStatus;
 import org.hisp.dhis.schema.descriptors.TrackedEntityInstanceSchemaDescriptor;
@@ -241,10 +242,10 @@
 
     @RequestMapping( value = "/{id}", method = RequestMethod.GET )
     @PreAuthorize( "hasRole('ALL') or hasRole('F_TRACKED_ENTITY_INSTANCE_SEARCH')" )
-    public @ResponseBody RootNode getTrackedEntityInstanceById( @PathVariable( "id" ) String pvId )
+    public @ResponseBody RootNode getTrackedEntityInstanceById( @PathVariable( "id" ) String pvId,
+        @RequestParam( value = "realObject", required = false, defaultValue = "false" ) boolean realObject )
         throws NotFoundException
     {
-        List<TrackedEntityInstance> trackedEntityInstances = Lists.newArrayList( getTrackedEntityInstance( pvId ) );
         List<String> fields = Lists.newArrayList( contextService.getParameterValues( "fields" ) );
 
         if ( fields.isEmpty() )
@@ -252,12 +253,23 @@
             fields.add( ":all" );
         }
 
-        RootNode rootNode = new RootNode( "metadata" );
+        CollectionNode collectionNode;
+
+        if ( !realObject )
+        {
+            collectionNode = fieldFilterService.filter( TrackedEntityInstance.class,
+                Lists.newArrayList( getTrackedEntityInstance( pvId ) ), fields );
+        }
+        else
+        {
+            collectionNode = fieldFilterService.filter( org.hisp.dhis.trackedentity.TrackedEntityInstance.class,
+                Lists.newArrayList( instanceService.getTrackedEntityInstance( pvId ) ), fields );
+        }
+
+        RootNode rootNode = new RootNode( collectionNode.getChildren().get( 0 ) );
         rootNode.setDefaultNamespace( DxfNamespaces.DXF_2_0 );
         rootNode.setNamespace( DxfNamespaces.DXF_2_0 );
 
-        rootNode.addChild( fieldFilterService.filter( TrackedEntityInstance.class, trackedEntityInstances, fields ) );
-
         return rootNode;
     }