dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #37584
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19194: minor updates to user settings API, return 404 on key not found, reuse accept header as content-t...
------------------------------------------------------------
revno: 19194
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-05-28 13:25:27 +0700
message:
minor updates to user settings API, return 404 on key not found, reuse accept header as content-type for setting output
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/UserSettingController.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/UserSettingController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/UserSettingController.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/UserSettingController.java 2015-05-28 06:25:27 +0000
@@ -32,15 +32,17 @@
import org.hisp.dhis.user.UserSettingService;
import org.hisp.dhis.webapi.utils.ContextUtils;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.ResponseBody;
+import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
import java.io.Serializable;
import java.util.Locale;
@@ -54,7 +56,7 @@
@Autowired
private UserSettingService userSettingService;
- @RequestMapping( value = "/{key}", method = RequestMethod.POST, consumes = { ContextUtils.CONTENT_TYPE_TEXT, ContextUtils.CONTENT_TYPE_HTML } )
+ @RequestMapping( value = "/{key}", method = RequestMethod.POST )
public void setUserSetting(
@PathVariable String key,
@RequestParam( value = "user", required = false ) String username,
@@ -88,10 +90,40 @@
ContextUtils.okResponse( response, "User setting saved" );
}
- @RequestMapping( value = "/{key}", method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_TEXT )
- public @ResponseBody String getSystemSetting( @PathVariable( "key" ) String key, @RequestParam( value = "user", required = false ) String username )
+ @RequestMapping( value = "/{key}", method = RequestMethod.GET )
+ public void getSystemSetting( @PathVariable( "key" ) String key,
+ @RequestParam( value = "user", required = false ) String username, HttpServletRequest request, HttpServletResponse response ) throws IOException
{
- return username == null ? getStringValue( key, userSettingService.getUserSetting( key ) ) : getStringValue( key, userSettingService.getUserSetting( key, username ) );
+ String value;
+
+ if ( username == null )
+ {
+ value = getStringValue( key, userSettingService.getUserSetting( key ) );
+ }
+ else
+ {
+ value = getStringValue( key, userSettingService.getUserSetting( key, username ) );
+ }
+
+ if ( value == null )
+ {
+ ContextUtils.notFoundResponse( response, "User setting not found." );
+ return;
+ }
+
+ String contentType;
+
+ if ( request.getHeader( "Accept" ) == null || "*/*".equals( request.getHeader( "Accept" ) ) )
+ {
+ contentType = MediaType.TEXT_PLAIN_VALUE;
+ }
+ else
+ {
+ contentType = request.getHeader( "Accept" );
+ }
+
+ response.setContentType( contentType );
+ response.getWriter().println( value );
}
@RequestMapping( value = "/{key}", method = RequestMethod.DELETE )