=== 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 )