dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #31133
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15835: Web api, systemSettings, support for retrieving multiple specified settings in one request
------------------------------------------------------------
revno: 15835
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-06-24 21:25:03 +0200
message:
Web api, systemSettings, support for retrieving multiple specified settings in one request
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultSystemSettingManager.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SystemSettingController.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-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java 2014-05-20 15:16:46 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java 2014-06-24 19:25:03 +0000
@@ -37,6 +37,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
* @author Stian Strandli
@@ -162,4 +163,6 @@
Integer credentialsExpires();
Map<String, Serializable> getSystemSettingsAsMap();
+
+ Map<String, Serializable> getSystemSettings( Set<String> names );
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultSystemSettingManager.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultSystemSettingManager.java 2014-05-20 15:16:46 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultSystemSettingManager.java 2014-06-24 19:25:03 +0000
@@ -37,6 +37,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
* @author Stian Strandli
@@ -209,4 +210,21 @@
return settingsMap;
}
+
+ public Map<String, Serializable> getSystemSettings( Set<String> names )
+ {
+ Map<String, Serializable> map = new HashMap<>();
+
+ for ( String name : names )
+ {
+ Serializable setting = getSystemSetting( name );
+
+ if ( setting != null )
+ {
+ map.put( name, setting );
+ }
+ }
+
+ return map;
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SystemSettingController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SystemSettingController.java 2014-06-11 20:02:58 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SystemSettingController.java 2014-06-24 19:25:03 +0000
@@ -28,6 +28,12 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.io.Serializable;
+import java.util.Map;
+import java.util.Set;
+
+import javax.servlet.http.HttpServletResponse;
+
import org.hisp.dhis.setting.SystemSettingManager;
import org.hisp.dhis.webapi.utils.ContextUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -40,10 +46,6 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
-import javax.servlet.http.HttpServletResponse;
-import java.io.Serializable;
-import java.util.Map;
-
/**
* @author Lars Helge Overland
*/
@@ -57,11 +59,12 @@
@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 String key,
+ @PathVariable( value = "key" ) String key,
+ @RequestParam( required = false, value = "key" ) String keyParam,
@RequestParam( required = false ) String value,
@RequestBody( required = false ) String valuePayload, HttpServletResponse response )
{
- if ( key == null )
+ if ( key == null && keyParam == null )
{
ContextUtils.conflictResponse( response, "Key must be specified" );
return;
@@ -73,6 +76,8 @@
}
value = value != null ? value : valuePayload;
+
+ key = key != null ? key : keyParam;
systemSettingManager.saveSystemSetting( key, value );
@@ -92,17 +97,24 @@
}
@RequestMapping( value = "/{key}", method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_TEXT )
- public @ResponseBody String getSystemSetting( @PathVariable( "key" ) String key )
+ public @ResponseBody String getSystemSettingAsText( @PathVariable( "key" ) String key )
{
Serializable setting = systemSettingManager.getSystemSetting( key );
return setting != null ? String.valueOf( setting ) : null;
}
-
+
@RequestMapping( method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_JSON )
- public @ResponseBody Map<String, Serializable> getSystemSetting()
+ public @ResponseBody Map<String, Serializable> getSystemSettings( @RequestParam( value = "key", required = false ) Set<String> key )
{
- return systemSettingManager.getSystemSettingsAsMap();
+ if ( key != null && !key.isEmpty() )
+ {
+ return systemSettingManager.getSystemSettings( key );
+ }
+ else
+ {
+ return systemSettingManager.getSystemSettingsAsMap();
+ }
}
@RequestMapping( value = "/{key}", method = RequestMethod.DELETE )