dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #29917
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15184: Applied patch from Mahendra Kariya, TW. Implements GET of /systemSettings in web api.
------------------------------------------------------------
revno: 15184
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-05-06 18:34:26 +0200
message:
Applied patch from Mahendra Kariya, TW. Implements GET of /systemSettings in web api.
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-services/dhis-service-core/src/test/java/org/hisp/dhis/setting/SystemSettingManagerTest.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/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-04-30 15:46:01 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java 2014-05-06 16:34:26 +0000
@@ -36,6 +36,7 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
/**
* @author Stian Strandli
@@ -155,4 +156,6 @@
String googleAnalyticsUA();
Integer credentialsExpires();
+
+ Map<String, Serializable> getSystemSettingsAsMap();
}
=== 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-04-30 15:46:01 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultSystemSettingManager.java 2014-05-06 16:34:26 +0000
@@ -34,7 +34,9 @@
import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
/**
* @author Stian Strandli
@@ -189,4 +191,17 @@
{
return (Integer) (getSystemSetting( KEY_CREDENTIALS_EXPIRES ) == null ? 0 : getSystemSetting( KEY_CREDENTIALS_EXPIRES ));
}
+
+ public Map<String, Serializable> getSystemSettingsAsMap()
+ {
+ Map<String, Serializable> settingsMap = new HashMap<String, Serializable>();
+ Collection<SystemSetting> systemSettings = getAllSystemSettings();
+
+ for ( SystemSetting systemSetting : systemSettings )
+ {
+ settingsMap.put( systemSetting.getName(), systemSetting.getValue() );
+ }
+
+ return settingsMap;
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/setting/SystemSettingManagerTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/setting/SystemSettingManagerTest.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/setting/SystemSettingManagerTest.java 2014-05-06 16:34:26 +0000
@@ -30,8 +30,11 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import java.io.Serializable;
import java.util.Collection;
+import java.util.Map;
import org.hisp.dhis.DhisSpringTest;
import org.hisp.dhis.setting.SystemSetting;
@@ -84,4 +87,21 @@
assertNotNull( settings );
assertEquals( 3, settings.size() );
}
+
+ @Test
+ public void testGetSystemSettingsAsMap()
+ {
+ systemSettingManager.saveSystemSetting( "settingA", new String( "valueA" ) );
+ systemSettingManager.saveSystemSetting( "settingB", new String( "valueB" ) );
+ systemSettingManager.saveSystemSetting( "settingC", new String( "valueC" ) );
+
+ Map<String, Serializable> settingsMap = systemSettingManager.getSystemSettingsAsMap();
+
+ assertTrue( settingsMap.containsKey( "settingA" ) );
+ assertTrue( settingsMap.containsKey( "settingB" ) );
+ assertTrue( settingsMap.containsKey( "settingC" ) );
+ assertEquals( "valueA", settingsMap.get( "settingA" ) );
+ assertEquals( "valueB", settingsMap.get( "settingB" ) );
+ assertEquals( "valueC", settingsMap.get( "settingC" ) );
+ }
}
=== 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 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/SystemSettingController.java 2014-05-06 16:34:26 +0000
@@ -42,6 +42,7 @@
import javax.servlet.http.HttpServletResponse;
import java.io.Serializable;
+import java.util.Map;
/**
* @author Lars Helge Overland
@@ -86,6 +87,12 @@
return setting != null ? String.valueOf( setting ) : null;
}
+ @RequestMapping(method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_JSON)
+ public @ResponseBody Map<String, Serializable> getSystemSetting()
+ {
+ return systemSettingManager.getSystemSettingsAsMap();
+ }
+
@RequestMapping(value = "/{key}", method = RequestMethod.DELETE)
@PreAuthorize("hasRole('ALL') or hasRole('F_SYSTEM_SETTING')")
public void removeSystemSetting( @PathVariable("key") String key )