← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15413: use AbstractCrudController which uses importer for CRUD operations on TrackedEntity objects

 

------------------------------------------------------------
revno: 15413
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-05-26 14:52:12 +0200
message:
  use AbstractCrudController which uses importer for CRUD operations on TrackedEntity objects
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/TrackedEntityController.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/TrackedEntityController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/TrackedEntityController.java	2014-05-22 12:40:24 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/TrackedEntityController.java	2014-05-26 12:52:12 +0000
@@ -28,22 +28,10 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.trackedentity.TrackedEntity;
 import org.hisp.dhis.webapi.controller.AbstractCrudController;
-import org.hisp.dhis.webapi.utils.ContextUtils;
-import org.hisp.dhis.dxf2.utils.JacksonUtils;
-import org.hisp.dhis.trackedentity.TrackedEntity;
-import org.hisp.dhis.trackedentity.TrackedEntityService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpStatus;
 import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.ResponseStatus;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.InputStream;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -53,92 +41,4 @@
 public class TrackedEntityController extends AbstractCrudController<TrackedEntity>
 {
     public static final String RESOURCE_PATH = "/trackedEntities";
-
-    @Autowired
-    private TrackedEntityService trackedEntityService;
-
-    //--------------------------------------------------------------------------
-    // POST
-    //--------------------------------------------------------------------------
-
-    @RequestMapping( method = RequestMethod.POST, consumes = { "application/xml", "text/xml" } )
-    @ResponseStatus( HttpStatus.CREATED )
-    public void postXmlObject( HttpServletResponse response, HttpServletRequest request, InputStream input ) throws Exception
-    {
-        TrackedEntity trackedEntity = JacksonUtils.fromXml( input, TrackedEntity.class );
-        trackedEntityService.addTrackedEntity( trackedEntity );
-
-        response.setHeader( "Location", ContextUtils.getRootPath( request ) + RESOURCE_PATH + "/" + trackedEntity.getUid() );
-    }
-
-    @RequestMapping( method = RequestMethod.POST, consumes = "application/json" )
-    @ResponseStatus( HttpStatus.CREATED )
-    public void postJsonObject( HttpServletResponse response, HttpServletRequest request, InputStream input ) throws Exception
-    {
-        TrackedEntity trackedEntity = JacksonUtils.fromJson( input, TrackedEntity.class );
-        trackedEntityService.addTrackedEntity( trackedEntity );
-
-        response.setHeader( "Location", ContextUtils.getRootPath( request ) + RESOURCE_PATH + "/" + trackedEntity.getUid() );
-    }
-
-    //--------------------------------------------------------------------------
-    // PUT
-    //--------------------------------------------------------------------------
-
-    @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, consumes = { "application/xml", "text/xml" } )
-    @ResponseStatus( value = HttpStatus.NO_CONTENT )
-    public void putXmlObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, InputStream input ) throws Exception
-    {
-        TrackedEntity trackedEntity = trackedEntityService.getTrackedEntity( uid );
-
-        if ( trackedEntity == null )
-        {
-            ContextUtils.conflictResponse( response, "TrackedEntity does not exist: " + uid );
-            return;
-        }
-
-        TrackedEntity newTrackedEntity = JacksonUtils.fromXml( input, TrackedEntity.class );
-        newTrackedEntity.setUid( trackedEntity.getUid() );
-        trackedEntity.mergeWith( newTrackedEntity );
-
-        trackedEntityService.updateTrackedEntity( trackedEntity );
-    }
-
-    @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, consumes = "application/json" )
-    @ResponseStatus( value = HttpStatus.NO_CONTENT )
-    public void putJsonObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, InputStream input ) throws Exception
-    {
-        TrackedEntity trackedEntity = trackedEntityService.getTrackedEntity( uid );
-
-        if ( trackedEntity == null )
-        {
-            ContextUtils.conflictResponse( response, "TrackedEntity does not exist: " + uid );
-            return;
-        }
-
-        TrackedEntity newTrackedEntity = JacksonUtils.fromJson( input, TrackedEntity.class );
-        newTrackedEntity.setUid( trackedEntity.getUid() );
-        trackedEntity.mergeWith( newTrackedEntity );
-
-        trackedEntityService.updateTrackedEntity( trackedEntity );
-    }
-
-    //--------------------------------------------------------------------------
-    // DELETE
-    //--------------------------------------------------------------------------
-
-    @RequestMapping( value = "/{uid}", method = RequestMethod.DELETE )
-    @ResponseStatus( value = HttpStatus.NO_CONTENT )
-    public void deleteObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid ) throws Exception
-    {
-        TrackedEntity trackedEntity = trackedEntityService.getTrackedEntity( uid );
-
-        if ( trackedEntity == null )
-        {
-            ContextUtils.conflictResponse( response, "TrackedEntity does not exist: " + uid );
-            return;
-        }
-
-        trackedEntityService.deleteTrackedEntity( trackedEntity );
-    }
 }