← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19215: Reapply changes from R19194

 

------------------------------------------------------------
revno: 19215
committer: Mark Polak <markpo@xxxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2015-05-31 13:34:07 +0200
message:
  Reapply changes from R19194
  
  Added back the user settings changes that broke the headerbar in
  apps that used the d2-header-bar directive from dhis2.menu.ui.
  The headerbar was fixed so the new user settings now work correctly
  
  References #19214
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-05-28 10:12:01 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/UserSettingController.java	2015-05-31 11:34:07 +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 )