← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14237: allow deletion of TrackedEntity in web-api

 

------------------------------------------------------------
revno: 14237
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-03-17 11:17:13 +0100
message:
  allow deletion of TrackedEntity in web-api
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/relationship/RelationshipType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityService.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/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-api/src/main/java/org/hisp/dhis/relationship/RelationshipType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/relationship/RelationshipType.java	2013-09-27 17:04:23 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/relationship/RelationshipType.java	2014-03-17 10:17:13 +0000
@@ -39,7 +39,6 @@
 
 /**
  * @author Abyot Asalefew
- * @version $Id$
  */
 @JacksonXmlRootElement( localName = "relationshipType", namespace = DxfNamespaces.DXF_2_0 )
 public class RelationshipType

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityService.java	2014-02-17 15:00:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityService.java	2014-03-17 10:17:13 +0000
@@ -75,6 +75,15 @@
     TrackedEntity getTrackedEntity( int id );
 
     /**
+     * Returns a {@link TrackedEntity}.
+     *
+     * @param id the id of the TrackedEntity to return.
+     *
+     * @return the TrackedEntity with the given id
+     */
+    TrackedEntity getTrackedEntity( String uid );
+
+    /**
      * Returns a {@link TrackedEntity} with a given name.
      * 
      * @param name the name of the TrackedEntity to return.

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityService.java	2014-02-17 15:00:27 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityService.java	2014-03-17 10:17:13 +0000
@@ -27,14 +27,13 @@
 
 package org.hisp.dhis.trackedentity;
 
-import java.util.Collection;
-
 import org.hisp.dhis.common.GenericIdentifiableObjectStore;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.Collection;
+
 /**
  * @author Chau Thu Tran
- * 
  * @version $ DefaultTrackedEntityService.java Feb 15, 2014 7:28:41 PM $
  */
 @Transactional
@@ -81,6 +80,12 @@
     }
 
     @Override
+    public TrackedEntity getTrackedEntity( String uid )
+    {
+        return trackedEntityStore.getByUid( uid );
+    }
+
+    @Override
     public TrackedEntity getTrackedEntityByName( String name )
     {
         return trackedEntityStore.getByName( name );

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java	2014-03-14 11:08:21 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java	2014-03-17 10:17:13 +0000
@@ -271,7 +271,6 @@
     {
         throw new HttpRequestMethodNotSupportedException( RequestMethod.POST.toString() );
     }
-
     //--------------------------------------------------------------------------
     // PUT
     //--------------------------------------------------------------------------
@@ -319,6 +318,7 @@
      * Override to process entities after it has been retrieved from
      * storage and before it is returned to the view. Entities is null-safe.
      */
+
     protected void postProcessEntities( List<T> entityList )
     {
 

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/TrackedEntityController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/TrackedEntityController.java	2014-03-17 09:35:36 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/TrackedEntityController.java	2014-03-17 10:17:13 +0000
@@ -29,9 +29,21 @@
  */
 
 import org.hisp.dhis.api.controller.AbstractCrudController;
+import org.hisp.dhis.api.utils.ContextUtils;
 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.HttpRequestMethodNotSupportedException;
+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>
@@ -41,4 +53,59 @@
 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" } )
+    public void postXmlObject( HttpServletResponse response, HttpServletRequest request, InputStream input ) throws Exception
+    {
+        throw new HttpRequestMethodNotSupportedException( RequestMethod.POST.toString() );
+    }
+
+    @RequestMapping( method = RequestMethod.POST, consumes = "application/json" )
+    public void postJsonObject( HttpServletResponse response, HttpServletRequest request, InputStream input ) throws Exception
+    {
+        throw new HttpRequestMethodNotSupportedException( RequestMethod.POST.toString() );
+    }
+
+    //--------------------------------------------------------------------------
+    // 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
+    {
+        throw new HttpRequestMethodNotSupportedException( RequestMethod.PUT.toString() );
+    }
+
+    @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
+    {
+        throw new HttpRequestMethodNotSupportedException( RequestMethod.PUT.toString() );
+    }
+
+    //--------------------------------------------------------------------------
+    // 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 );
+        }
+
+        trackedEntityService.deleteTrackedEntity( trackedEntity );
+    }
 }