dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #25795
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12818: Web api, system and user settings, supporting value as part of body
------------------------------------------------------------
revno: 12818
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-10-28 11:18:38 +0100
message:
Web api, system and user settings, supporting value as part of body
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/SystemSettingController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/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/api/controller/SystemSettingController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/SystemSettingController.java 2013-09-22 14:42:10 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/SystemSettingController.java 2013-10-28 10:18:38 +0000
@@ -36,6 +36,7 @@
import org.springframework.security.access.prepost.PreAuthorize;
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;
@@ -51,16 +52,26 @@
@Autowired
private SystemSettingManager systemSettingManager;
- @RequestMapping( value = "/{key}", method = RequestMethod.POST )
+ @RequestMapping( value = "/{key}", method = RequestMethod.POST, consumes = { ContextUtils.CONTENT_TYPE_TEXT, ContextUtils.CONTENT_TYPE_HTML } )
@PreAuthorize( "hasRole('ALL') or hasRole('F_SYSTEM_SETTING')" )
- public void setSystemSetting( @PathVariable( "key" ) String key, @RequestParam String value, HttpServletResponse response )
+ public void setSystemSetting(
+ @PathVariable String key,
+ @RequestParam(required = false) String value,
+ @RequestBody(required=false) String valuePayload, HttpServletResponse response )
{
- if ( key == null || value == null )
+ if ( key == null )
{
- ContextUtils.conflictResponse( response, "Key and value must be specified" );
+ ContextUtils.conflictResponse( response, "Key must be specified" );
return;
}
+ if ( value == null && valuePayload == null )
+ {
+ ContextUtils.conflictResponse( response, "Value must be specified as query param or as payload" );
+ }
+
+ value = value != null ? value : valuePayload;
+
systemSettingManager.saveSystemSetting( key, value );
ContextUtils.okResponse( response, "System setting saved" );
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/UserSettingController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/UserSettingController.java 2013-09-22 14:42:10 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/UserSettingController.java 2013-10-28 10:18:38 +0000
@@ -35,6 +35,7 @@
import org.springframework.beans.factory.annotation.Autowired;
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;
@@ -50,14 +51,24 @@
@Autowired
private UserSettingService userSettingService;
- @RequestMapping( value = "/{key}", method = RequestMethod.POST )
- public void setUserSetting( @PathVariable( "key" ) String key, @RequestParam String value, HttpServletResponse response )
+ @RequestMapping( value = "/{key}", method = RequestMethod.POST, consumes = { ContextUtils.CONTENT_TYPE_TEXT, ContextUtils.CONTENT_TYPE_HTML } )
+ public void setUserSetting(
+ @PathVariable String key,
+ @RequestParam(required = false) String value,
+ @RequestBody(required=false) String valuePayload, HttpServletResponse response )
{
- if ( key == null || value == null )
+ if ( key == null )
{
- ContextUtils.conflictResponse( response, "Key and value must be specified" );
+ ContextUtils.conflictResponse( response, "Key must be specified" );
return;
}
+
+ if ( value == null && valuePayload == null )
+ {
+ ContextUtils.conflictResponse( response, "Value must be specified as query param or as payload" );
+ }
+
+ value = value != null ? value : valuePayload;
userSettingService.saveUserSetting( key, value );