← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3824: Implemented configuration service. Configuration object designed for associations to other object...

 

------------------------------------------------------------
revno: 3824
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-06-01 17:28:59 +0200
message:
  Implemented configuration service. Configuration object designed for associations to other objects, ie to maintain referential integrity. This service complements the system/user settings.
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/configuration/
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/configuration/Configuration.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/configuration/ConfigurationService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/configuration/
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/configuration/DefaultConfigurationService.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/configuration/
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/configuration/hibernate/
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/configuration/hibernate/Configuration.hbm.xml
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/cofiguration/
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/cofiguration/ConfigurationServiceTest.java
modified:
  dhis-2/dhis-services/dhis-service-core/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-api/src/main/java/org/hisp/dhis/configuration'
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/configuration/Configuration.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/configuration/Configuration.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/configuration/Configuration.java	2011-06-01 15:28:59 +0000
@@ -0,0 +1,72 @@
+package org.hisp.dhis.configuration;
+
+/*
+ * 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 org.hisp.dhis.user.UserGroup;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class Configuration
+    implements Serializable
+{
+    /**
+     * Determines if a de-serialized file is compatible with this class.
+     */
+    private static final long serialVersionUID = 936186436040704261L;
+    
+    private int id;
+    
+    private UserGroup messageRecipients;
+
+    public Configuration()
+    {
+    }
+    
+    public int getId()
+    {
+        return id;
+    }
+
+    public void setId( int id )
+    {
+        this.id = id;
+    }
+
+    public UserGroup getMessageRecipients()
+    {
+        return messageRecipients;
+    }
+
+    public void setMessageRecipients( UserGroup messageRecipients )
+    {
+        this.messageRecipients = messageRecipients;
+    }
+}

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/configuration/ConfigurationService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/configuration/ConfigurationService.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/configuration/ConfigurationService.java	2011-06-01 15:28:59 +0000
@@ -0,0 +1,40 @@
+package org.hisp.dhis.configuration;
+
+/*
+ * 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.
+ */
+
+/**
+ * @author Lars Helge Overland
+ */
+public interface ConfigurationService
+{
+    final String ID = ConfigurationService.class.getName();
+    
+    void setConfiguration( Configuration configuration );
+    
+    Configuration getConfiguration();
+}

=== added directory 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/configuration'
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/configuration/DefaultConfigurationService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/configuration/DefaultConfigurationService.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/configuration/DefaultConfigurationService.java	2011-06-01 15:28:59 +0000
@@ -0,0 +1,60 @@
+package org.hisp.dhis.configuration;
+
+/*
+ * 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.util.Iterator;
+
+import org.hisp.dhis.common.GenericStore;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class DefaultConfigurationService
+    implements ConfigurationService
+{
+    private GenericStore<Configuration> configurationStore;
+
+    public void setConfigurationStore( GenericStore<Configuration> configurationStore )
+    {
+        this.configurationStore = configurationStore;
+    }
+    
+    @Override
+    public void setConfiguration( Configuration configuration )
+    {
+        configurationStore.saveOrUpdate( configuration );
+    }
+    
+    @Override
+    public Configuration getConfiguration()
+    {
+        Iterator<Configuration> iterator = configurationStore.getAll().iterator();
+        
+        return iterator.hasNext() ? iterator.next() : new Configuration();
+    }
+}

=== 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-05-28 18:05:39 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2011-06-01 15:28:59 +0000
@@ -235,11 +235,22 @@
 		<property name="cacheable" value="true"/>
 	</bean>
 	
+	<bean id="org.hisp.dhis.concept.ConceptStore"
+		class="org.hisp.dhis.hibernate.HibernateGenericStore">
+		<property name="clazz" value="org.hisp.dhis.concept.Concept"/>
+		<property name="sessionFactory" ref="sessionFactory"/>
+	</bean>
+	
 	<bean id="org.hisp.dhis.sequence.SequenceStore" class="org.hisp.dhis.hibernate.HibernateGenericStore">
 		<property name="sessionFactory" ref="sessionFactory"/>
 		<property name="clazz" value="org.hisp.dhis.sequence.Sequence"/>
 	</bean>
 	
+	<bean id="org.hisp.dhis.configuration.ConfigurationStore" class="org.hisp.dhis.hibernate.HibernateGenericStore">
+		<property name="sessionFactory" ref="sessionFactory"/>
+		<property name="clazz" value="org.hisp.dhis.configuration.Configuration"/>
+	</bean>
+	
 	<!-- Service definitions -->
 
 	<bean id="org.hisp.dhis.dataelement.DataElementOperandService"
@@ -458,23 +469,19 @@
 		<property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService"/>
 	</bean>
 	
-	<bean id="org.hisp.dhis.sequence.SequenceGenerator" class="org.hisp.dhis.sequence.DefaultSequenceGenerator">
-		<property name="sequenceStore" ref="org.hisp.dhis.sequence.SequenceStore"/>
-	</bean>
-	
-	<!-- Concept Name -->
-	
-	<bean id="org.hisp.dhis.concept.ConceptStore"
-		class="org.hisp.dhis.hibernate.HibernateGenericStore">
-		<property name="clazz" value="org.hisp.dhis.concept.Concept"/>
-		<property name="sessionFactory" ref="sessionFactory"/>
-	</bean>
-	
 	<bean id="org.hisp.dhis.concept.ConceptService" 
 		class="org.hisp.dhis.concept.DefaultConceptService">
 		<property name="conceptStore" ref="org.hisp.dhis.concept.ConceptStore" />
 	</bean>
 	
+	<bean id="org.hisp.dhis.sequence.SequenceGenerator" class="org.hisp.dhis.sequence.DefaultSequenceGenerator">
+		<property name="sequenceStore" ref="org.hisp.dhis.sequence.SequenceStore"/>
+	</bean>
+	
+	<bean id="org.hisp.dhis.configuration.ConfigurationService" class="org.hisp.dhis.configuration.DefaultConfigurationService">
+		<property name="configurationStore" ref="org.hisp.dhis.configuration.ConfigurationStore"/>
+	</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/configuration'
=== added directory 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/configuration/hibernate'
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/configuration/hibernate/Configuration.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/configuration/hibernate/Configuration.hbm.xml	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/configuration/hibernate/Configuration.hbm.xml	2011-06-01 15:28:59 +0000
@@ -0,0 +1,16 @@
+<?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.configuration.Configuration" table="configuration">
+
+    <id name="id" column="configurationid">
+      <generator class="native" />
+    </id>
+
+	<one-to-one name="messageRecipients" class="org.hisp.dhis.user.UserGroup"/>
+
+  </class>
+</hibernate-mapping>

=== added directory 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/cofiguration'
=== added file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/cofiguration/ConfigurationServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/cofiguration/ConfigurationServiceTest.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/cofiguration/ConfigurationServiceTest.java	2011-06-01 15:28:59 +0000
@@ -0,0 +1,90 @@
+package org.hisp.dhis.cofiguration;
+
+/*
+ * 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 org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.configuration.Configuration;
+import org.hisp.dhis.configuration.ConfigurationService;
+import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserGroup;
+import org.hisp.dhis.user.UserGroupService;
+import org.hisp.dhis.user.UserService;
+import org.junit.Test;
+
+import static junit.framework.Assert.*;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class ConfigurationServiceTest
+    extends DhisSpringTest
+{
+    private UserService userService;
+    
+    private UserGroupService userGroupService;
+    
+    private ConfigurationService configurationService;
+    
+    @Override
+    public void setUpTest()
+    {
+        userService = (UserService) getBean( UserService.ID );
+        
+        userGroupService = (UserGroupService) getBean( UserGroupService.ID );
+        
+        configurationService = (ConfigurationService) getBean( ConfigurationService.ID );
+    }
+    
+    @Test
+    public void testConfiguration()
+    {
+        User userA = createUser( 'A' );
+        User userB = createUser( 'B' );
+        
+        UserGroup group = new UserGroup( "UserGroupA" );
+        group.getMembers().add( userA );
+        group.getMembers().add(  userB );
+        
+        userService.addUser( userA );
+        userService.addUser( userB );
+        userGroupService.addUserGroup( group );
+        
+        Configuration config = configurationService.getConfiguration();
+        
+        assertNull( config.getMessageRecipients() );
+        
+        config.setMessageRecipients( group );
+        
+        configurationService.setConfiguration( config );
+        
+        config = configurationService.getConfiguration();
+        
+        assertNotNull( config.getMessageRecipients() );
+        assertEquals( group, config.getMessageRecipients() );
+    }
+}