dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #14261
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4784: Moved SystemSettingManager from dhis-service-options to dhis-service-core
------------------------------------------------------------
revno: 4784
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2011-09-30 15:48:31 +0200
message:
Moved SystemSettingManager from dhis-service-options to dhis-service-core
removed:
dhis-2/dhis-services/dhis-service-options/src/main/java/org/hisp/dhis/options/setting/
dhis-2/dhis-services/dhis-service-options/src/main/java/org/hisp/dhis/options/setting/DefaultSystemSettingManager.java
dhis-2/dhis-services/dhis-service-options/src/main/resources/org/
dhis-2/dhis-services/dhis-service-options/src/main/resources/org/hisp/
dhis-2/dhis-services/dhis-service-options/src/main/resources/org/hisp/dhis/
dhis-2/dhis-services/dhis-service-options/src/main/resources/org/hisp/dhis/option/
dhis-2/dhis-services/dhis-service-options/src/main/resources/org/hisp/dhis/option/setting/
dhis-2/dhis-services/dhis-service-options/src/main/resources/org/hisp/dhis/option/setting/hibernate/
dhis-2/dhis-services/dhis-service-options/src/main/resources/org/hisp/dhis/option/setting/hibernate/SystemSetting.hbm.xml
dhis-2/dhis-services/dhis-service-options/src/test/java/org/hisp/dhis/options/SystemSettingManagerTest.java
dhis-2/dhis-services/dhis-service-options/src/test/java/org/hisp/dhis/options/SystemSettingStoreTest.java
added:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/options/
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/options/setting/
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/options/setting/DefaultSystemSettingManager.java
dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/options/
dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/options/setting/
dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/options/setting/SystemSetting.hbm.xml
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/options/
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/options/setting/
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/options/setting/SystemSettingManagerTest.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/options/setting/SystemSettingStoreTest.java
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserSettingService.java
dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-services/dhis-service-options/src/main/resources/META-INF/dhis/beans.xml
--
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
=== added directory 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/options'
=== added directory 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/options/setting'
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/options/setting/DefaultSystemSettingManager.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/options/setting/DefaultSystemSettingManager.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/options/setting/DefaultSystemSettingManager.java 2011-09-30 13:48:31 +0000
@@ -0,0 +1,147 @@
+package org.hisp.dhis.options.setting;
+
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import org.hisp.dhis.common.GenericIdentifiableObjectStore;
+import org.hisp.dhis.options.SystemSetting;
+import org.hisp.dhis.options.SystemSettingManager;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * @author Stian Strandli
+ * @author Lars Helge Overland
+ */
+@Transactional
+public class DefaultSystemSettingManager
+ implements SystemSettingManager
+{
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private GenericIdentifiableObjectStore<SystemSetting> systemSettingStore;
+
+ public void setSystemSettingStore( GenericIdentifiableObjectStore<SystemSetting> systemSettingStore )
+ {
+ this.systemSettingStore = systemSettingStore;
+ }
+
+ private List<String> flags;
+
+ public void setFlags( List<String> flags )
+ {
+ this.flags = flags;
+ }
+
+ // -------------------------------------------------------------------------
+ // SystemSettingManager implementation
+ // -------------------------------------------------------------------------
+
+ public void saveSystemSetting( String name, Serializable value )
+ {
+ SystemSetting setting = systemSettingStore.getByName( name );
+
+ if ( setting == null )
+ {
+ setting = new SystemSetting();
+
+ setting.setName( name );
+ setting.setValue( value );
+
+ systemSettingStore.save( setting );
+ }
+ else
+ {
+ setting.setValue( value );
+
+ systemSettingStore.update( setting );
+ }
+ }
+
+ public Serializable getSystemSetting( String name )
+ {
+ SystemSetting setting = systemSettingStore.getByName( name );
+
+ return setting != null && setting.hasValue() ? setting.getValue() : null;
+ }
+
+ public Serializable getSystemSetting( String name, Serializable defaultValue )
+ {
+ SystemSetting setting = systemSettingStore.getByName( name );
+
+ return setting != null && setting.hasValue() ? setting.getValue() : defaultValue;
+ }
+
+ public Collection<SystemSetting> getAllSystemSettings()
+ {
+ return systemSettingStore.getAll();
+ }
+
+ public void deleteSystemSetting( String name )
+ {
+ SystemSetting setting = systemSettingStore.getByName( name );
+
+ if ( setting != null )
+ {
+ systemSettingStore.delete( setting );
+ }
+ }
+
+ // -------------------------------------------------------------------------
+ // Specific methods
+ // -------------------------------------------------------------------------
+
+ public List<String> getFlags()
+ {
+ Collections.sort( flags );
+ return flags;
+ }
+
+ public List<String> getAggregationStrategies()
+ {
+ return Arrays.asList( AGGREGATION_STRATEGY_REAL_TIME, AGGREGATION_STRATEGY_BATCH );
+ }
+
+ public String getSystemIdentifier()
+ {
+ return (String) getSystemSetting( KEY_SYSTEM_IDENTIFIER );
+ }
+
+ public String getFlagImage()
+ {
+ String flag = (String) getSystemSetting( KEY_FLAG );
+
+ return flag != null ? flag + ".png" : null;
+ }
+}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserSettingService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserSettingService.java 2011-09-30 09:19:11 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserSettingService.java 2011-09-30 13:48:31 +0000
@@ -29,6 +29,7 @@
import java.io.Serializable;
import java.util.Collection;
+import java.util.Collections;
import org.springframework.transaction.annotation.Transactional;
@@ -134,7 +135,7 @@
if ( currentUser == null )
{
- return null;
+ return Collections.emptySet();
}
return userService.getAllUserSettings( currentUser );
@@ -144,11 +145,9 @@
{
User currentUser = currentUserService.getCurrentUser();
- if ( currentUser == null )
+ if ( currentUser != null )
{
- return;
- }
-
- userService.deleteUserSetting( userService.getUserSetting( currentUser, name ) );
+ userService.deleteUserSetting( userService.getUserSetting( currentUser, name ) );
+ }
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2011-09-27 10:12:47 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2011-09-30 13:48:31 +0000
@@ -247,6 +247,12 @@
<property name="clazz" value="org.hisp.dhis.attribute.AttributeValue" />
</bean>
+ <bean id="org.hisp.dhis.options.SystemSettingStore" class="org.hisp.dhis.hibernate.HibernateGenericStore">
+ <property name="clazz" value="org.hisp.dhis.options.SystemSetting" />
+ <property name="sessionFactory" ref="sessionFactory" />
+ <property name="cacheable" value="true" />
+ </bean>
+
<!-- Service definitions -->
<bean id="org.hisp.dhis.dataelement.DataElementOperandService" class="org.hisp.dhis.dataelement.DefaultDataElementOperandService">
@@ -466,6 +472,56 @@
<property name="attributeValueStore" ref="org.hisp.dhis.attribute.AttributeValueStore" />
</bean>
+ <bean id="org.hisp.dhis.options.SystemSettingManager" class="org.hisp.dhis.options.setting.DefaultSystemSettingManager">
+ <property name="systemSettingStore" ref="org.hisp.dhis.options.SystemSettingStore" />
+ <property name="flags">
+ <list>
+ <value>armenia</value>
+ <value>bangladesh</value>
+ <value>benin</value>
+ <value>botswana</value>
+ <value>burkina_faso</value>
+ <value>cambodia</value>
+ <value>ethiopia</value>
+ <value>gambia</value>
+ <value>ghana</value>
+ <value>guinea</value>
+ <value>guinea_bissau</value>
+ <value>india</value>
+ <value>indonesia</value>
+ <value>irc</value>
+ <value>ivory_coast</value>
+ <value>kenya</value>
+ <value>lesotho</value>
+ <value>liberia</value>
+ <value>malawi</value>
+ <value>mali</value>
+ <value>mozambique</value>
+ <value>namibia</value>
+ <value>nigeria</value>
+ <value>norway</value>
+ <value>philippines</value>
+ <value>rwanda</value>
+ <value>senegal</value>
+ <value>sierra_leone</value>
+ <value>sierra_leone_coat_of_arms</value>
+ <value>south_africa</value>
+ <value>south_africa_department_of_health</value>
+ <value>sri_lanka</value>
+ <value>swaziland</value>
+ <value>tajikistan</value>
+ <value>tanzania</value>
+ <value>togo</value>
+ <value>uganda</value>
+ <value>vietnam</value>
+ <value>zambia</value>
+ <value>zanzibar</value>
+ <value>zimbabwe</value>
+ <value>who</value>
+ </list>
+ </property>
+ </bean>
+
<!-- I18nService -->
<bean id="org.hisp.dhis.i18n.I18nService" class="org.hisp.dhis.i18n.DefaultI18nService">
=== added directory 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/options'
=== added directory 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/options/setting'
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/options/setting/SystemSetting.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/options/setting/SystemSetting.hbm.xml 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/options/setting/SystemSetting.hbm.xml 2011-09-30 13:48:31 +0000
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping>
+ <class name="org.hisp.dhis.options.SystemSetting" table="systemsetting">
+
+ <cache usage="read-write" />
+
+ <id name="id" column="systemsettingid">
+ <generator class="native" />
+ </id>
+
+ <property name="name">
+ <column name="name" not-null="true" unique="true" />
+ </property>
+
+ <property name="value" type="serializable" length="65535" />
+
+ </class>
+</hibernate-mapping>
=== added directory 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/options'
=== added directory 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/options/setting'
=== added file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/options/setting/SystemSettingManagerTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/options/setting/SystemSettingManagerTest.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/options/setting/SystemSettingManagerTest.java 2011-09-30 13:48:31 +0000
@@ -0,0 +1,86 @@
+package org.hisp.dhis.options.setting;
+
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNotNull;
+
+import java.util.Collection;
+
+import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.options.SystemSetting;
+import org.hisp.dhis.options.SystemSettingManager;
+import org.junit.Test;
+
+/**
+ * @author Stian Strandli
+ * @author Lars Helge Overland
+ * @version $Id: SystemSettingManagerTest.java 4866 2008-04-11 10:40:35Z larshelg $
+ */
+public class SystemSettingManagerTest
+ extends DhisSpringTest
+{
+ private SystemSettingManager systemSettingManager;
+
+ @Override
+ public void setUpTest()
+ throws Exception
+ {
+ systemSettingManager = (SystemSettingManager) getBean( SystemSettingManager.ID );
+ }
+
+ @Test
+ public void testSaveGetSystemSetting()
+ {
+ systemSettingManager.saveSystemSetting( "settingA", new String( "valueA" ) );
+ systemSettingManager.saveSystemSetting( "settingB", new String( "valueB" ) );
+
+ assertEquals( new String( "valueA" ), systemSettingManager.getSystemSetting( "settingA" ) );
+ assertEquals( new String( "valueB" ), systemSettingManager.getSystemSetting( "settingB" ) );
+ }
+
+ @Test
+ public void testGetDefaultSystemSetting()
+ {
+ assertEquals( new String( "valueA" ), systemSettingManager.getSystemSetting( "settingA", new String( "valueA" ) ) );
+ assertEquals( new String( "valueB" ), systemSettingManager.getSystemSetting( "settingB", new String( "valueB" ) ) );
+ }
+
+ @Test
+ public void testGetAllSystemSettings()
+ {
+ systemSettingManager.saveSystemSetting( "settingA", new String( "valueA" ) );
+ systemSettingManager.saveSystemSetting( "settingB", new String( "valueB" ) );
+ systemSettingManager.saveSystemSetting( "settingC", new String( "valueC" ) );
+
+ Collection<SystemSetting> settings = systemSettingManager.getAllSystemSettings();
+
+ assertNotNull( settings );
+ assertEquals( 3, settings.size() );
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/options/setting/SystemSettingStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/options/setting/SystemSettingStoreTest.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/options/setting/SystemSettingStoreTest.java 2011-09-30 13:48:31 +0000
@@ -0,0 +1,155 @@
+package org.hisp.dhis.options.setting;
+
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertNull;
+
+import java.util.Collection;
+
+import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.common.GenericIdentifiableObjectStore;
+import org.hisp.dhis.options.SystemSetting;
+import org.junit.Test;
+
+/**
+ * @author Stian Strandli
+ * @version $Id: SystemSettingStoreTest.java 4866 2008-04-11 10:40:35Z larshelg $
+ */
+public class SystemSettingStoreTest
+ extends DhisSpringTest
+{
+ private GenericIdentifiableObjectStore<SystemSetting> systemSettingStore;
+
+ private SystemSetting settingA;
+ private SystemSetting settingB;
+ private SystemSetting settingC;
+
+ @Override
+ @SuppressWarnings( "unchecked" )
+ public void setUpTest()
+ throws Exception
+ {
+ systemSettingStore = (GenericIdentifiableObjectStore<SystemSetting>) getBean( "org.hisp.dhis.options.SystemSettingStore" );
+
+ settingA = new SystemSetting();
+ settingA.setName( "Setting1" );
+ settingA.setValue( new String( "Value1" ) );
+
+ settingB = new SystemSetting();
+ settingB.setName( "Setting2" );
+ settingB.setValue( new String( "Value2" ) );
+
+ settingC = new SystemSetting();
+ settingC.setName( "Setting3" );
+ settingC.setValue( new String( "Value3" ) );
+ }
+
+ @Test
+ public void testAddSystemSetting()
+ {
+ systemSettingStore.save( settingA );
+ systemSettingStore.save( settingB );
+ systemSettingStore.save( settingC );
+
+ SystemSetting s = systemSettingStore.getByName( settingA.getName() );
+ assertNotNull( s );
+ assertEquals( "Setting1", s.getName() );
+ assertEquals( "Value1", s.getValue() );
+
+ settingA.setValue( new String( "Value1.1" ) );
+ systemSettingStore.save( settingA );
+
+ s = systemSettingStore.getByName( settingA.getName() );
+ assertNotNull( s );
+ assertEquals( "Setting1", s.getName() );
+ assertEquals( "Value1.1", s.getValue() );
+ }
+
+ @Test
+ public void testUpdateSystemSetting()
+ {
+ systemSettingStore.save( settingA );
+
+ settingA = systemSettingStore.getByName( "Setting1" );
+
+ assertEquals( "Value1", (String) settingA.getValue() );
+
+ settingA.setValue( new String( "Value2" ) );
+
+ systemSettingStore.update( settingA );
+
+ settingA = systemSettingStore.getByName( "Setting1" );
+
+ assertEquals( "Value2", (String) settingA.getValue() );
+ }
+
+ @Test
+ public void testDeleteSystemSetting()
+ {
+ systemSettingStore.save( settingA );
+ systemSettingStore.save( settingB );
+ systemSettingStore.save( settingC );
+
+ systemSettingStore.delete( systemSettingStore.getByName( settingA.getName() ) );
+
+ assertNull( systemSettingStore.getByName( settingA.getName() ) );
+ assertEquals( 2, systemSettingStore.getAll().size() );
+ }
+
+ @Test
+ public void testGetSystemSetting()
+ {
+ systemSettingStore.save( settingA );
+ systemSettingStore.save( settingB );
+
+ SystemSetting s = systemSettingStore.getByName( "Setting1" );
+ assertNotNull( s );
+ assertEquals( "Setting1", s.getName() );
+ assertEquals( "Value1", s.getValue() );
+
+ s = systemSettingStore.getByName( "Setting3" );
+ assertNull( s );
+ }
+
+ @Test
+ public void testGetAllSystemSettings()
+ {
+ Collection<SystemSetting> m = systemSettingStore.getAll();
+ assertNotNull( m );
+ assertEquals( 0, m.size() );
+
+ systemSettingStore.save( settingA );
+ systemSettingStore.save( settingB );
+
+ m = systemSettingStore.getAll();
+ assertNotNull( m );
+ assertEquals( 2, m.size() );
+ }
+}
=== removed directory 'dhis-2/dhis-services/dhis-service-options/src/main/java/org/hisp/dhis/options/setting'
=== removed file 'dhis-2/dhis-services/dhis-service-options/src/main/java/org/hisp/dhis/options/setting/DefaultSystemSettingManager.java'
--- dhis-2/dhis-services/dhis-service-options/src/main/java/org/hisp/dhis/options/setting/DefaultSystemSettingManager.java 2011-09-30 13:18:24 +0000
+++ dhis-2/dhis-services/dhis-service-options/src/main/java/org/hisp/dhis/options/setting/DefaultSystemSettingManager.java 1970-01-01 00:00:00 +0000
@@ -1,147 +0,0 @@
-package org.hisp.dhis.options.setting;
-
-/*
- * Copyright (c) 2004-2010, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import java.io.Serializable;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-import org.hisp.dhis.common.GenericIdentifiableObjectStore;
-import org.hisp.dhis.options.SystemSetting;
-import org.hisp.dhis.options.SystemSettingManager;
-import org.springframework.transaction.annotation.Transactional;
-
-/**
- * @author Stian Strandli
- * @author Lars Helge Overland
- */
-@Transactional
-public class DefaultSystemSettingManager
- implements SystemSettingManager
-{
- // -------------------------------------------------------------------------
- // Dependencies
- // -------------------------------------------------------------------------
-
- private GenericIdentifiableObjectStore<SystemSetting> systemSettingStore;
-
- public void setSystemSettingStore( GenericIdentifiableObjectStore<SystemSetting> systemSettingStore )
- {
- this.systemSettingStore = systemSettingStore;
- }
-
- private List<String> flags;
-
- public void setFlags( List<String> flags )
- {
- this.flags = flags;
- }
-
- // -------------------------------------------------------------------------
- // SystemSettingManager implementation
- // -------------------------------------------------------------------------
-
- public void saveSystemSetting( String name, Serializable value )
- {
- SystemSetting setting = systemSettingStore.getByName( name );
-
- if ( setting == null )
- {
- setting = new SystemSetting();
-
- setting.setName( name );
- setting.setValue( value );
-
- systemSettingStore.save( setting );
- }
- else
- {
- setting.setValue( value );
-
- systemSettingStore.update( setting );
- }
- }
-
- public Serializable getSystemSetting( String name )
- {
- SystemSetting setting = systemSettingStore.getByName( name );
-
- return setting != null && setting.hasValue() ? setting.getValue() : null;
- }
-
- public Serializable getSystemSetting( String name, Serializable defaultValue )
- {
- SystemSetting setting = systemSettingStore.getByName( name );
-
- return setting != null && setting.hasValue() ? setting.getValue() : defaultValue;
- }
-
- public Collection<SystemSetting> getAllSystemSettings()
- {
- return systemSettingStore.getAll();
- }
-
- public void deleteSystemSetting( String name )
- {
- SystemSetting setting = systemSettingStore.getByName( name );
-
- if ( setting != null )
- {
- systemSettingStore.delete( setting );
- }
- }
-
- // -------------------------------------------------------------------------
- // Specific methods
- // -------------------------------------------------------------------------
-
- public List<String> getFlags()
- {
- Collections.sort( flags );
- return flags;
- }
-
- public List<String> getAggregationStrategies()
- {
- return Arrays.asList( AGGREGATION_STRATEGY_REAL_TIME, AGGREGATION_STRATEGY_BATCH );
- }
-
- public String getSystemIdentifier()
- {
- return (String) getSystemSetting( KEY_SYSTEM_IDENTIFIER );
- }
-
- public String getFlagImage()
- {
- String flag = (String) getSystemSetting( KEY_FLAG );
-
- return flag != null ? flag + ".png" : null;
- }
-}
=== modified file 'dhis-2/dhis-services/dhis-service-options/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-options/src/main/resources/META-INF/dhis/beans.xml 2011-09-30 13:18:24 +0000
+++ dhis-2/dhis-services/dhis-service-options/src/main/resources/META-INF/dhis/beans.xml 2011-09-30 13:48:31 +0000
@@ -12,62 +12,6 @@
<property name="userSettingService" ref="org.hisp.dhis.user.UserSettingService" />
</bean>
- <bean id="org.hisp.dhis.options.SystemSettingStore" class="org.hisp.dhis.hibernate.HibernateGenericStore">
- <property name="clazz" value="org.hisp.dhis.options.SystemSetting" />
- <property name="sessionFactory" ref="sessionFactory" />
- <property name="cacheable" value="true" />
- </bean>
-
- <bean id="org.hisp.dhis.options.SystemSettingManager" class="org.hisp.dhis.options.setting.DefaultSystemSettingManager">
- <property name="systemSettingStore" ref="org.hisp.dhis.options.SystemSettingStore" />
- <property name="flags">
- <list>
- <value>armenia</value>
- <value>bangladesh</value>
- <value>benin</value>
- <value>botswana</value>
- <value>burkina_faso</value>
- <value>cambodia</value>
- <value>ethiopia</value>
- <value>gambia</value>
- <value>ghana</value>
- <value>guinea</value>
- <value>guinea_bissau</value>
- <value>india</value>
- <value>indonesia</value>
- <value>irc</value>
- <value>ivory_coast</value>
- <value>kenya</value>
- <value>lesotho</value>
- <value>liberia</value>
- <value>malawi</value>
- <value>mali</value>
- <value>mozambique</value>
- <value>namibia</value>
- <value>nigeria</value>
- <value>norway</value>
- <value>philippines</value>
- <value>rwanda</value>
- <value>senegal</value>
- <value>sierra_leone</value>
- <value>sierra_leone_coat_of_arms</value>
- <value>south_africa</value>
- <value>south_africa_department_of_health</value>
- <value>sri_lanka</value>
- <value>swaziland</value>
- <value>tajikistan</value>
- <value>tanzania</value>
- <value>togo</value>
- <value>uganda</value>
- <value>vietnam</value>
- <value>zambia</value>
- <value>zanzibar</value>
- <value>zimbabwe</value>
- <value>who</value>
- </list>
- </property>
- </bean>
-
<bean id="org.hisp.dhis.options.style.StyleManager" class="org.hisp.dhis.options.style.DefaultStyleManager">
<property name="systemSettingManager" ref="org.hisp.dhis.options.SystemSettingManager" />
<property name="userSettingService" ref="org.hisp.dhis.user.UserSettingService" />
=== removed directory 'dhis-2/dhis-services/dhis-service-options/src/main/resources/org'
=== removed directory 'dhis-2/dhis-services/dhis-service-options/src/main/resources/org/hisp'
=== removed directory 'dhis-2/dhis-services/dhis-service-options/src/main/resources/org/hisp/dhis'
=== removed directory 'dhis-2/dhis-services/dhis-service-options/src/main/resources/org/hisp/dhis/option'
=== removed directory 'dhis-2/dhis-services/dhis-service-options/src/main/resources/org/hisp/dhis/option/setting'
=== removed directory 'dhis-2/dhis-services/dhis-service-options/src/main/resources/org/hisp/dhis/option/setting/hibernate'
=== removed file 'dhis-2/dhis-services/dhis-service-options/src/main/resources/org/hisp/dhis/option/setting/hibernate/SystemSetting.hbm.xml'
--- dhis-2/dhis-services/dhis-service-options/src/main/resources/org/hisp/dhis/option/setting/hibernate/SystemSetting.hbm.xml 2011-05-28 21:25:46 +0000
+++ dhis-2/dhis-services/dhis-service-options/src/main/resources/org/hisp/dhis/option/setting/hibernate/SystemSetting.hbm.xml 1970-01-01 00:00:00 +0000
@@ -1,22 +0,0 @@
-<?xml version="1.0"?>
-<!DOCTYPE hibernate-mapping PUBLIC
- "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
- "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
-
-<hibernate-mapping>
- <class name="org.hisp.dhis.options.SystemSetting" table="systemsetting">
-
- <cache usage="read-write" />
-
- <id name="id" column="systemsettingid">
- <generator class="native" />
- </id>
-
- <property name="name">
- <column name="name" not-null="true" unique="true" />
- </property>
-
- <property name="value" type="serializable" length="65535" />
-
- </class>
-</hibernate-mapping>
=== removed file 'dhis-2/dhis-services/dhis-service-options/src/test/java/org/hisp/dhis/options/SystemSettingManagerTest.java'
--- dhis-2/dhis-services/dhis-service-options/src/test/java/org/hisp/dhis/options/SystemSettingManagerTest.java 2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-services/dhis-service-options/src/test/java/org/hisp/dhis/options/SystemSettingManagerTest.java 1970-01-01 00:00:00 +0000
@@ -1,84 +0,0 @@
-package org.hisp.dhis.options;
-
-/*
- * Copyright (c) 2004-2010, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertNotNull;
-
-import java.util.Collection;
-
-import org.hisp.dhis.DhisSpringTest;
-import org.junit.Test;
-
-/**
- * @author Stian Strandli
- * @author Lars Helge Overland
- * @version $Id: SystemSettingManagerTest.java 4866 2008-04-11 10:40:35Z larshelg $
- */
-public class SystemSettingManagerTest
- extends DhisSpringTest
-{
- private SystemSettingManager systemSettingManager;
-
- @Override
- public void setUpTest()
- throws Exception
- {
- systemSettingManager = (SystemSettingManager) getBean( SystemSettingManager.ID );
- }
-
- @Test
- public void testSaveGetSystemSetting()
- {
- systemSettingManager.saveSystemSetting( "settingA", new String( "valueA" ) );
- systemSettingManager.saveSystemSetting( "settingB", new String( "valueB" ) );
-
- assertEquals( new String( "valueA" ), systemSettingManager.getSystemSetting( "settingA" ) );
- assertEquals( new String( "valueB" ), systemSettingManager.getSystemSetting( "settingB" ) );
- }
-
- @Test
- public void testGetDefaultSystemSetting()
- {
- assertEquals( new String( "valueA" ), systemSettingManager.getSystemSetting( "settingA", new String( "valueA" ) ) );
- assertEquals( new String( "valueB" ), systemSettingManager.getSystemSetting( "settingB", new String( "valueB" ) ) );
- }
-
- @Test
- public void testGetAllSystemSettings()
- {
- systemSettingManager.saveSystemSetting( "settingA", new String( "valueA" ) );
- systemSettingManager.saveSystemSetting( "settingB", new String( "valueB" ) );
- systemSettingManager.saveSystemSetting( "settingC", new String( "valueC" ) );
-
- Collection<SystemSetting> settings = systemSettingManager.getAllSystemSettings();
-
- assertNotNull( settings );
- assertEquals( 3, settings.size() );
- }
-}
=== removed file 'dhis-2/dhis-services/dhis-service-options/src/test/java/org/hisp/dhis/options/SystemSettingStoreTest.java'
--- dhis-2/dhis-services/dhis-service-options/src/test/java/org/hisp/dhis/options/SystemSettingStoreTest.java 2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-services/dhis-service-options/src/test/java/org/hisp/dhis/options/SystemSettingStoreTest.java 1970-01-01 00:00:00 +0000
@@ -1,154 +0,0 @@
-package org.hisp.dhis.options;
-
-/*
- * Copyright (c) 2004-2010, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertNotNull;
-import static junit.framework.Assert.assertNull;
-
-import java.util.Collection;
-
-import org.hisp.dhis.DhisSpringTest;
-import org.hisp.dhis.common.GenericIdentifiableObjectStore;
-import org.junit.Test;
-
-/**
- * @author Stian Strandli
- * @version $Id: SystemSettingStoreTest.java 4866 2008-04-11 10:40:35Z larshelg $
- */
-@SuppressWarnings( "unchecked" )
-public class SystemSettingStoreTest
- extends DhisSpringTest
-{
- private GenericIdentifiableObjectStore<SystemSetting> systemSettingStore;
-
- private SystemSetting settingA;
- private SystemSetting settingB;
- private SystemSetting settingC;
-
- @Override
- public void setUpTest()
- throws Exception
- {
- systemSettingStore = (GenericIdentifiableObjectStore<SystemSetting>) getBean( "org.hisp.dhis.options.SystemSettingStore" );
-
- settingA = new SystemSetting();
- settingA.setName( "Setting1" );
- settingA.setValue( new String( "Value1" ) );
-
- settingB = new SystemSetting();
- settingB.setName( "Setting2" );
- settingB.setValue( new String( "Value2" ) );
-
- settingC = new SystemSetting();
- settingC.setName( "Setting3" );
- settingC.setValue( new String( "Value3" ) );
- }
-
- @Test
- public void testAddSystemSetting()
- {
- systemSettingStore.save( settingA );
- systemSettingStore.save( settingB );
- systemSettingStore.save( settingC );
-
- SystemSetting s = systemSettingStore.getByName( settingA.getName() );
- assertNotNull( s );
- assertEquals( "Setting1", s.getName() );
- assertEquals( "Value1", s.getValue() );
-
- settingA.setValue( new String( "Value1.1" ) );
- systemSettingStore.save( settingA );
-
- s = systemSettingStore.getByName( settingA.getName() );
- assertNotNull( s );
- assertEquals( "Setting1", s.getName() );
- assertEquals( "Value1.1", s.getValue() );
- }
-
- @Test
- public void testUpdateSystemSetting()
- {
- systemSettingStore.save( settingA );
-
- settingA = systemSettingStore.getByName( "Setting1" );
-
- assertEquals( "Value1", (String) settingA.getValue() );
-
- settingA.setValue( new String( "Value2" ) );
-
- systemSettingStore.update( settingA );
-
- settingA = systemSettingStore.getByName( "Setting1" );
-
- assertEquals( "Value2", (String) settingA.getValue() );
- }
-
- @Test
- public void testDeleteSystemSetting()
- {
- systemSettingStore.save( settingA );
- systemSettingStore.save( settingB );
- systemSettingStore.save( settingC );
-
- systemSettingStore.delete( systemSettingStore.getByName( settingA.getName() ) );
-
- assertNull( systemSettingStore.getByName( settingA.getName() ) );
- assertEquals( 2, systemSettingStore.getAll().size() );
- }
-
- @Test
- public void testGetSystemSetting()
- {
- systemSettingStore.save( settingA );
- systemSettingStore.save( settingB );
-
- SystemSetting s = systemSettingStore.getByName( "Setting1" );
- assertNotNull( s );
- assertEquals( "Setting1", s.getName() );
- assertEquals( "Value1", s.getValue() );
-
- s = systemSettingStore.getByName( "Setting3" );
- assertNull( s );
- }
-
- @Test
- public void testGetAllSystemSettings()
- {
- Collection<SystemSetting> m = systemSettingStore.getAll();
- assertNotNull( m );
- assertEquals( 0, m.size() );
-
- systemSettingStore.save( settingA );
- systemSettingStore.save( settingB );
-
- m = systemSettingStore.getAll();
- assertNotNull( m );
- assertEquals( 2, m.size() );
- }
-}