← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20891: KeyJsonValue controller, returning web message instead of full message on post, put, delete.

 

------------------------------------------------------------
revno: 20891
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-10-29 11:49:44 -0400
message:
  KeyJsonValue controller, returning web message instead of full message on post, put, delete.
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/KeyJsonValueController.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/KeyJsonValueController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/KeyJsonValueController.java	2015-10-12 17:04:46 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/KeyJsonValueController.java	2015-10-29 15:49:44 +0000
@@ -37,10 +37,10 @@
 import org.hisp.dhis.appmanager.App;
 import org.hisp.dhis.appmanager.AppManager;
 import org.hisp.dhis.dxf2.render.RenderService;
-import org.hisp.dhis.dxf2.webmessage.WebMessage;
 import org.hisp.dhis.dxf2.webmessage.WebMessageException;
 import org.hisp.dhis.keyjsonvalue.KeyJsonValue;
 import org.hisp.dhis.keyjsonvalue.KeyJsonValueService;
+import org.hisp.dhis.webapi.service.WebMessageService;
 import org.hisp.dhis.webapi.utils.WebMessageUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
@@ -61,6 +61,9 @@
 
     @Autowired
     private AppManager appManager;
+    
+    @Autowired
+    private WebMessageService messageService;
 
     /**
      * Returns a JSON array of strings representing the different namespaces used.
@@ -93,7 +96,7 @@
      * Deletes all keys with the given namespace.
      */
     @RequestMapping( value = "/{namespace}", method = RequestMethod.DELETE )
-    public @ResponseBody WebMessage deleteNamespace( @PathVariable String namespace, HttpServletResponse response )
+    public void deleteNamespace( @PathVariable String namespace, HttpServletResponse response )
         throws WebMessageException
     {
         if ( !hasAccess( namespace ) )
@@ -109,8 +112,8 @@
         }
 
         keyJsonValueService.deleteNamespace( namespace );
-
-        return WebMessageUtils.ok( "Namespace '" + namespace + "' deleted." );
+        
+        messageService.sendJson( WebMessageUtils.ok( "Namespace '" + namespace + "' deleted." ), response );
     }
 
     /**
@@ -142,7 +145,7 @@
      * Creates a new KeyJsonValue Object on the given namespace with the key and value supplied.
      */
     @RequestMapping( value = "/{namespace}/{key}", method = RequestMethod.POST, produces = "application/json", consumes = "application/json" )
-    public @ResponseBody KeyJsonValue addKey(
+    public void addKeyJsonValue(
         @PathVariable String namespace, @PathVariable String key, @RequestBody String body, HttpServletResponse response )
         throws IOException, WebMessageException
     {
@@ -172,14 +175,14 @@
         keyJsonValueService.addKeyJsonValue( keyJsonValue );
 
         response.setStatus( HttpServletResponse.SC_CREATED );
-        return keyJsonValue;
+        messageService.sendJson( WebMessageUtils.created( "Key '" + key + "' created." ), response );
     }
 
     /**
      * Update a key in the given namespace.
      */
     @RequestMapping( value = "/{namespace}/{key}", method = RequestMethod.PUT, produces = "application/json", consumes = "application/json" )
-    public @ResponseBody KeyJsonValue updateKeyJsonValue( @PathVariable String namespace, @PathVariable String key, @RequestBody String body,
+    public void updateKeyJsonValue( @PathVariable String namespace, @PathVariable String key, @RequestBody String body,
         HttpServletRequest request, HttpServletResponse response )
         throws WebMessageException, IOException
     {
@@ -205,15 +208,16 @@
         keyJsonValue.setValue( body );
 
         keyJsonValueService.updateKeyJsonValue( keyJsonValue );
-
-        return keyJsonValue;
+        
+        response.setStatus( HttpServletResponse.SC_OK );
+        messageService.sendJson( WebMessageUtils.ok( "Key '" + key + "' updated." ), response );
     }
 
     /**
      * Delete a key from the given namespace.
      */
     @RequestMapping( value = "/{namespace}/{key}", method = RequestMethod.DELETE, produces = "application/json" )
-    public @ResponseBody WebMessage deleteKeyJsonValue(
+    public void deleteKeyJsonValue(
         @PathVariable String namespace, @PathVariable String key, HttpServletResponse response )
         throws WebMessageException
     {
@@ -233,7 +237,7 @@
 
         keyJsonValueService.deleteKeyJsonValue( keyJsonValue );
 
-        return WebMessageUtils.ok( "Key '" + key + "' deleted from namespace '" + namespace + "'." );
+        messageService.sendJson( WebMessageUtils.ok( "Key '" + key + "' deleted from namespace '" + namespace + "'." ), response );
     }
 
     private boolean hasAccess( String namespace )