=== 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 configurationStore; + + public void setConfigurationStore( GenericStore configurationStore ) + { + this.configurationStore = configurationStore; + } + + @Override + public void setConfiguration( Configuration configuration ) + { + configurationStore.saveOrUpdate( configuration ); + } + + @Override + public Configuration getConfiguration() + { + Iterator 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 @@ + + + + + + + + + + - - - - - - - - - - - + + + + + + + + === 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 @@ + + + + + + + + + + + + + + === 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() ); + } +}