dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #02754
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 909: Implemented persistence for DataElementGroupSet.
------------------------------------------------------------
revno: 909
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Tue 2009-10-27 17:24:02 +0100
message:
Implemented persistence for DataElementGroupSet.
added:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dimension/
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dimension/DefaultDimensionService.java
dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementGroupSet.hbm.xml
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementGroupSetStoreTest.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementGroupStoreTest.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java
dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/datadictionary/DataDictionaryStoreTest.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementStoreTest.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/validation/ValidationRuleGroupStoreTest.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/validation/ValidationRuleStoreTest.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/dataelement/DataElementService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java 2009-06-10 22:25:07 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java 2009-10-27 16:24:02 +0000
@@ -353,4 +353,20 @@
* @return a collection of all DataElementGroups that contain the given DataElement.
*/
Collection<DataElementGroup> getGroupsContainingDataElement( DataElement dataElement );
+
+ // -------------------------------------------------------------------------
+ // DataElementGroupSet
+ // -------------------------------------------------------------------------
+
+ int addDataElementGroupSet( DataElementGroupSet groupSet );
+
+ void updateDataElementGroupSet( DataElementGroupSet groupSet );
+
+ void deleteDataElementGroupSet( DataElementGroupSet groupSet );
+
+ DataElementGroupSet getDataElementGroupSet( int id );
+
+ DataElementGroupSet getDataElementGroupSetByName( String name );
+
+ Collection<DataElementGroupSet> getAllDataElementGroupSets();
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.java 2009-04-16 14:18:39 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.java 2009-10-27 16:24:02 +0000
@@ -201,62 +201,4 @@
* if there are no CalculcatedDataELements
*/
Collection<CalculatedDataElement> getAllCalculatedDataElements();
-
- // -------------------------------------------------------------------------
- // DataElementGroup
- // -------------------------------------------------------------------------
-
- /**
- * Adds a DataElementGroup.
- *
- * @param dataElementGroup the DataElementGroup to add.
- * @return a generated unique id of the added DataElementGroup.
- */
- int addDataElementGroup( DataElementGroup dataElementGroup );
-
- /**
- * Updates a DataElementGroup.
- *
- * @param dataElementGroup the DataElementGroup to update.
- */
- void updateDataElementGroup( DataElementGroup dataElementGroup );
-
- /**
- * Deletes a DataElementGroup.
- *
- * @param dataElementGroup the DataElementGroup to delete.
- */
- void deleteDataElementGroup( DataElementGroup dataElementGroup );
-
- /**
- * Returns a DataElementGroup.
- *
- * @param id the id of the DataElementGroup to return.
- * @return the DataElementGroup with the given id, or null if no match.
- */
- DataElementGroup getDataElementGroup( int id );
-
- /**
- * Returns the DataElementGroup with the given UUID.
- *
- * @param id the UUID.
- * @return the DataElementGroup with the given uuid, or null if no match.
- */
- DataElementGroup getDataElementGroup( String uuid );
-
- /**
- * Returns a DataElementGroup with a given name.
- *
- * @param name the name of the DataElementGroup to return.
- * @return the DataElementGroup with the given name, or null if no match.
- */
- DataElementGroup getDataElementGroupByName( String name );
-
- /**
- * Returns all DataElementGroups.
- *
- * @return a collection of all DataElementGroups, or an empty collection if
- * no DataElementGroups exist.
- */
- Collection<DataElementGroup> getAllDataElementGroups();
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java 2009-06-10 22:25:07 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java 2009-10-27 16:24:02 +0000
@@ -35,6 +35,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.hisp.dhis.common.GenericIdentifiableObjectStore;
import org.hisp.dhis.hierarchy.HierarchyViolationException;
import org.hisp.dhis.i18n.I18nService;
import org.hisp.dhis.system.util.UUIdUtils;
@@ -60,6 +61,20 @@
this.dataElementStore = dataElementStore;
}
+ private GenericIdentifiableObjectStore<DataElementGroup> dataElementGroupStore;
+
+ public void setDataElementGroupStore( GenericIdentifiableObjectStore<DataElementGroup> dataElementGroupStore )
+ {
+ this.dataElementGroupStore = dataElementGroupStore;
+ }
+
+ private GenericIdentifiableObjectStore<DataElementGroupSet> dataElementGroupSetStore;
+
+ public void setDataElementGroupSetStore( GenericIdentifiableObjectStore<DataElementGroupSet> dataElementGroupSetStore )
+ {
+ this.dataElementGroupSetStore = dataElementGroupSetStore;
+ }
+
private I18nService i18nService;
public void setI18nService( I18nService service )
@@ -357,7 +372,7 @@
dataElementGroup.setUuid( UUIdUtils.getUUId() );
}
- int id = dataElementStore.addDataElementGroup( dataElementGroup );
+ int id = dataElementGroupStore.save( dataElementGroup );
i18nService.addObject( dataElementGroup );
@@ -366,7 +381,7 @@
public void updateDataElementGroup( DataElementGroup dataElementGroup )
{
- dataElementStore.updateDataElementGroup( dataElementGroup );
+ dataElementGroupStore.update( dataElementGroup );
i18nService.verify( dataElementGroup );
}
@@ -375,12 +390,12 @@
{
i18nService.removeObject( dataElementGroup );
- dataElementStore.deleteDataElementGroup( dataElementGroup );
+ dataElementGroupStore.delete( dataElementGroup );
}
public DataElementGroup getDataElementGroup( int id )
{
- return dataElementStore.getDataElementGroup( id );
+ return dataElementGroupStore.get( id );
}
public Collection<DataElementGroup> getDataElementGroups( Collection<Integer> identifiers )
@@ -402,17 +417,17 @@
public DataElementGroup getDataElementGroup( String uuid )
{
- return dataElementStore.getDataElementGroup( uuid );
+ return dataElementGroupStore.getByUuid( uuid );
}
public Collection<DataElementGroup> getAllDataElementGroups()
{
- return dataElementStore.getAllDataElementGroups();
+ return dataElementGroupStore.getAll();
}
public DataElementGroup getDataElementGroupByName( String name )
{
- return dataElementStore.getDataElementGroupByName( name );
+ return dataElementGroupStore.getByName( name );
}
public Collection<DataElementGroup> getGroupsContainingDataElement( DataElement dataElement )
@@ -431,4 +446,38 @@
return groups;
}
+
+ // -------------------------------------------------------------------------
+ // DataElementGroupSet
+ // -------------------------------------------------------------------------
+
+ public int addDataElementGroupSet( DataElementGroupSet groupSet )
+ {
+ return dataElementGroupSetStore.save( groupSet );
+ }
+
+ public void updateDataElementGroupSet( DataElementGroupSet groupSet )
+ {
+ dataElementGroupSetStore.update( groupSet );
+ }
+
+ public void deleteDataElementGroupSet( DataElementGroupSet groupSet )
+ {
+ dataElementGroupSetStore.delete( groupSet );
+ }
+
+ public DataElementGroupSet getDataElementGroupSet( int id )
+ {
+ return dataElementGroupSetStore.get( id );
+ }
+
+ public DataElementGroupSet getDataElementGroupSetByName( String name )
+ {
+ return dataElementGroupSetStore.getByName( name );
+ }
+
+ public Collection<DataElementGroupSet> getAllDataElementGroupSets()
+ {
+ return dataElementGroupSetStore.getAll();
+ }
}
=== added directory 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dimension'
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dimension/DefaultDimensionService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dimension/DefaultDimensionService.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dimension/DefaultDimensionService.java 2009-10-27 16:24:02 +0000
@@ -0,0 +1,6 @@
+package org.hisp.dhis.dimension;
+
+public class DefaultDimensionService
+{
+
+}
=== 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 2009-10-20 10:51:16 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2009-10-27 16:24:02 +0000
@@ -19,6 +19,18 @@
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
+ <bean id="org.hisp.dhis.dataelement.DataElementGroupStore"
+ class="org.hisp.dhis.hibernate.HibernateGenericStore">
+ <property name="clazz" value="org.hisp.dhis.dataelement.DataElementGroup"/>
+ <property name="sessionFactory" ref="sessionFactory"/>
+ </bean>
+
+ <bean id="org.hisp.dhis.dataelement.DataElementGroupSetStore"
+ class="org.hisp.dhis.hibernate.HibernateGenericStore">
+ <property name="clazz" value="org.hisp.dhis.dataelement.DataElementGroupSet"/>
+ <property name="sessionFactory" ref="sessionFactory"/>
+ </bean>
+
<bean id="org.hisp.dhis.datadictionary.DataDictionaryStore"
class="org.hisp.dhis.hibernate.HibernateGenericStore">
<property name="clazz" value="org.hisp.dhis.datadictionary.DataDictionary"/>
@@ -138,6 +150,10 @@
class="org.hisp.dhis.dataelement.DefaultDataElementService">
<property name="dataElementStore"
ref="org.hisp.dhis.dataelement.DataElementStore"/>
+ <property name="dataElementGroupStore"
+ ref="org.hisp.dhis.dataelement.DataElementGroupStore"/>
+ <property name="dataElementGroupSetStore"
+ ref="org.hisp.dhis.dataelement.DataElementGroupSetStore"/>
<property name="i18nService"
ref="org.hisp.dhis.i18n.I18nService"/>
</bean>
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementGroupSet.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementGroupSet.hbm.xml 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementGroupSet.hbm.xml 2009-10-27 16:24:02 +0000
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping>
+
+ <class name="org.hisp.dhis.dataelement.DataElementGroupSet" table="dataelementgroupset">
+
+ <id name="id" column="dataelementgroupsetid">
+ <generator class="native"/>
+ </id>
+
+ <property name="uuid">
+ <column name="uuid" length="40"/>
+ </property>
+
+ <property name="name">
+ <column name="name" not-null="true" unique="true" length="230"/>
+ </property>
+
+ <list name="members" table="dataelementgroupsetmembers">
+ <key column="dataelementgroupsetid"/>
+ <list-index column="sort_order" base="1"/>
+ <many-to-many class="org.hisp.dhis.dataelement.DataElementGroup"
+ column="dataelementgroupid" foreign-key="fk_dataelementgroupset_dataelementgroupid"/>
+ </list>
+
+ </class>
+</hibernate-mapping>
\ No newline at end of file
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/datadictionary/DataDictionaryStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/datadictionary/DataDictionaryStoreTest.java 2009-06-20 14:26:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/datadictionary/DataDictionaryStoreTest.java 2009-10-27 16:24:02 +0000
@@ -35,7 +35,7 @@
import java.util.Collection;
import org.hisp.dhis.DhisSpringTest;
-import org.hisp.dhis.common.GenericNameStore;
+import org.hisp.dhis.common.GenericIdentifiableObjectStore;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementService;
import org.hisp.dhis.indicator.Indicator;
@@ -51,7 +51,7 @@
public class DataDictionaryStoreTest
extends DhisSpringTest
{
- private GenericNameStore<DataDictionary> dataDictionaryStore;
+ private GenericIdentifiableObjectStore<DataDictionary> dataDictionaryStore;
private DataElement dataElementA;
private DataElement dataElementB;
@@ -72,7 +72,7 @@
public void setUpTest()
throws Exception
{
- dataDictionaryStore = (GenericNameStore<DataDictionary>) getBean( "org.hisp.dhis.datadictionary.DataDictionaryStore" );
+ dataDictionaryStore = (GenericIdentifiableObjectStore<DataDictionary>) getBean( "org.hisp.dhis.datadictionary.DataDictionaryStore" );
dataElementService = (DataElementService) getBean( DataElementService.ID );
=== added file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementGroupSetStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementGroupSetStoreTest.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementGroupSetStoreTest.java 2009-10-27 16:24:02 +0000
@@ -0,0 +1,94 @@
+package org.hisp.dhis.dataelement;
+
+/*
+ * Copyright (c) 2004-2007, 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 org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.common.GenericIdentifiableObjectStore;
+import org.junit.Test;
+
+/**
+ * @author Lars Helge Overland
+ * @version $Id$
+ */
+@SuppressWarnings( "unchecked" )
+public class DataElementGroupSetStoreTest
+ extends DhisSpringTest
+{
+ private DataElementService dataElementService;
+
+ private GenericIdentifiableObjectStore<DataElementGroupSet> dataElementGroupSetStore;
+
+ private DataElementGroup groupA;
+ private DataElementGroup groupB;
+ private DataElementGroup groupC;
+ private DataElementGroup groupD;
+
+ private DataElementGroupSet groupSetA;
+ private DataElementGroupSet groupSetB;
+
+ @Override
+ public void setUpTest()
+ {
+ dataElementService = (DataElementService) getBean( DataElementService.ID );
+
+ dataElementGroupSetStore = (GenericIdentifiableObjectStore<DataElementGroupSet>) getBean( "org.hisp.dhis.dataelement.DataElementGroupSetStore" );
+
+ groupA = createDataElementGroup( 'A' );
+ groupB = createDataElementGroup( 'B' );
+ groupC = createDataElementGroup( 'C' );
+ groupD = createDataElementGroup( 'D' );
+
+ dataElementService.addDataElementGroup( groupA );
+ dataElementService.addDataElementGroup( groupB );
+ dataElementService.addDataElementGroup( groupC );
+ dataElementService.addDataElementGroup( groupD );
+
+ groupSetA = new DataElementGroupSet( "GroupSetA" );
+ groupSetB = new DataElementGroupSet( "GroupSetB" );
+
+ groupSetA.getMembers().add( groupA );
+ groupSetA.getMembers().add( groupB );
+ groupSetB.getMembers().add( groupC );
+ groupSetB.getMembers().add( groupD );
+ }
+
+ @Test
+ public void addGet()
+ {
+ int idA = dataElementGroupSetStore.save( groupSetA );
+ int idB = dataElementGroupSetStore.save( groupSetB );
+
+ assertEquals( groupSetA, dataElementGroupSetStore.get( idA ) );
+ assertEquals( groupSetB, dataElementGroupSetStore.get( idB ) );
+
+ assertEquals( groupSetA.getMembers(), dataElementGroupSetStore.get( idA ).getMembers() );
+ assertEquals( groupSetB.getMembers(), dataElementGroupSetStore.get( idB ).getMembers() );
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementGroupStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementGroupStoreTest.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementGroupStoreTest.java 2009-10-27 16:24:02 +0000
@@ -0,0 +1,232 @@
+package org.hisp.dhis.dataelement;
+
+/*
+ * Copyright (c) 2004-2007, 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 static junit.framework.Assert.assertTrue;
+import static junit.framework.Assert.fail;
+
+import java.util.Collection;
+
+import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.common.GenericIdentifiableObjectStore;
+import org.hisp.dhis.system.util.UUIdUtils;
+import org.junit.Test;
+
+/**
+ * @author Lars Helge Overland
+ * @version $Id$
+ */
+@SuppressWarnings( "unchecked" )
+public class DataElementGroupStoreTest
+ extends DhisSpringTest
+{
+ private GenericIdentifiableObjectStore<DataElementGroup> dataElementGroupStore;
+
+ @Override
+ public void setUpTest()
+ {
+ dataElementGroupStore = (GenericIdentifiableObjectStore<DataElementGroup>) getBean( "org.hisp.dhis.dataelement.DataElementGroupStore" );
+ }
+
+ @Test
+ public void testAddDataElementGroup()
+ {
+ DataElementGroup dataElementGroupA = new DataElementGroup( "DataElementGroupA" );
+ DataElementGroup dataElementGroupB = new DataElementGroup( "DataElementGroupB" );
+ DataElementGroup dataElementGroupC = new DataElementGroup( "DataElementGroupC" );
+ DataElementGroup dataElementGroupD = new DataElementGroup( "DataElementGroupA" );
+
+ int idA = dataElementGroupStore.save( dataElementGroupA );
+ int idB = dataElementGroupStore.save( dataElementGroupB );
+ int idC = dataElementGroupStore.save( dataElementGroupC );
+
+ try
+ {
+ // Should give unique constraint violation
+ dataElementGroupStore.save( dataElementGroupD );
+ fail();
+ }
+ catch ( Exception e )
+ {
+ // Expected
+ }
+
+ dataElementGroupA = dataElementGroupStore.get( idA );
+ assertNotNull( dataElementGroupA );
+ assertEquals( idA, dataElementGroupA.getId() );
+ assertEquals( "DataElementGroupA", dataElementGroupA.getName() );
+
+ dataElementGroupB = dataElementGroupStore.get( idB );
+ assertNotNull( dataElementGroupB );
+ assertEquals( idB, dataElementGroupB.getId() );
+ assertEquals( "DataElementGroupB", dataElementGroupB.getName() );
+
+ dataElementGroupC = dataElementGroupStore.get( idC );
+ assertNotNull( dataElementGroupC );
+ assertEquals( idC, dataElementGroupC.getId() );
+ assertEquals( "DataElementGroupC", dataElementGroupC.getName() );
+ }
+
+ @Test
+ public void testUpdateDataElementGroup()
+ {
+ DataElementGroup dataElementGroupA = new DataElementGroup( "DataElementGroupA" );
+ DataElementGroup dataElementGroupB = new DataElementGroup( "DataElementGroupB" );
+ DataElementGroup dataElementGroupC = new DataElementGroup( "DataElementGroupC" );
+
+ int idA = dataElementGroupStore.save( dataElementGroupA );
+ int idB = dataElementGroupStore.save( dataElementGroupB );
+ int idC = dataElementGroupStore.save( dataElementGroupC );
+
+ dataElementGroupA = dataElementGroupStore.get( idA );
+ assertNotNull( dataElementGroupA );
+ assertEquals( idA, dataElementGroupA.getId() );
+ assertEquals( "DataElementGroupA", dataElementGroupA.getName() );
+
+ dataElementGroupA.setName( "DataElementGroupAA" );
+ dataElementGroupStore.update( dataElementGroupA );
+
+ dataElementGroupA = dataElementGroupStore.get( idA );
+ assertNotNull( dataElementGroupA );
+ assertEquals( idA, dataElementGroupA.getId() );
+ assertEquals( "DataElementGroupAA", dataElementGroupA.getName() );
+
+ dataElementGroupB = dataElementGroupStore.get( idB );
+ assertNotNull( dataElementGroupB );
+ assertEquals( idB, dataElementGroupB.getId() );
+ assertEquals( "DataElementGroupB", dataElementGroupB.getName() );
+
+ dataElementGroupC = dataElementGroupStore.get( idC );
+ assertNotNull( dataElementGroupC );
+ assertEquals( idC, dataElementGroupC.getId() );
+ assertEquals( "DataElementGroupC", dataElementGroupC.getName() );
+ }
+
+ @Test
+ public void testDeleteAndGetDataElementGroup()
+ {
+ DataElementGroup dataElementGroupA = new DataElementGroup( "DataElementGroupA" );
+ DataElementGroup dataElementGroupB = new DataElementGroup( "DataElementGroupB" );
+ DataElementGroup dataElementGroupC = new DataElementGroup( "DataElementGroupC" );
+ DataElementGroup dataElementGroupD = new DataElementGroup( "DataElementGroupD" );
+
+ int idA = dataElementGroupStore.save( dataElementGroupA );
+ int idB = dataElementGroupStore.save( dataElementGroupB );
+ int idC = dataElementGroupStore.save( dataElementGroupC );
+ int idD = dataElementGroupStore.save( dataElementGroupD );
+
+ assertNotNull( dataElementGroupStore.get( idA ) );
+ assertNotNull( dataElementGroupStore.get( idB ) );
+ assertNotNull( dataElementGroupStore.get( idC ) );
+ assertNotNull( dataElementGroupStore.get( idD ) );
+
+ dataElementGroupStore.delete( dataElementGroupA );
+ assertNull( dataElementGroupStore.get( idA ) );
+ assertNotNull( dataElementGroupStore.get( idB ) );
+ assertNotNull( dataElementGroupStore.get( idC ) );
+ assertNotNull( dataElementGroupStore.get( idD ) );
+
+ dataElementGroupStore.delete( dataElementGroupB );
+ assertNull( dataElementGroupStore.get( idA ) );
+ assertNull( dataElementGroupStore.get( idB ) );
+ assertNotNull( dataElementGroupStore.get( idC ) );
+ assertNotNull( dataElementGroupStore.get( idD ) );
+
+ dataElementGroupStore.delete( dataElementGroupC );
+ assertNull( dataElementGroupStore.get( idA ) );
+ assertNull( dataElementGroupStore.get( idB ) );
+ assertNull( dataElementGroupStore.get( idC ) );
+ assertNotNull( dataElementGroupStore.get( idD ) );
+
+ dataElementGroupStore.delete( dataElementGroupD );
+ assertNull( dataElementGroupStore.get( idA ) );
+ assertNull( dataElementGroupStore.get( idB ) );
+ assertNull( dataElementGroupStore.get( idC ) );
+ assertNull( dataElementGroupStore.get( idD ) );
+ }
+
+ @Test
+ public void testgetByUUID()
+ {
+ String uuid = UUIdUtils.getUUId();
+
+ DataElementGroup groupA = new DataElementGroup( "groupA" );
+ groupA.setUuid( uuid );
+
+ dataElementGroupStore.save( groupA );
+
+ groupA = dataElementGroupStore.getByUuid( uuid );
+
+ assertNotNull( groupA );
+ assertEquals( groupA.getUuid(), uuid );
+ }
+
+ @Test
+ public void testgetByName()
+ {
+ DataElementGroup dataElementGroupA = new DataElementGroup( "DataElementGroupA" );
+ DataElementGroup dataElementGroupB = new DataElementGroup( "DataElementGroupB" );
+ int idA = dataElementGroupStore.save( dataElementGroupA );
+ int idB = dataElementGroupStore.save( dataElementGroupB );
+
+ assertNotNull( dataElementGroupStore.get( idA ) );
+ assertNotNull( dataElementGroupStore.get( idB ) );
+
+ dataElementGroupA = dataElementGroupStore.getByName( "DataElementGroupA" );
+ assertNotNull( dataElementGroupA );
+ assertEquals( idA, dataElementGroupA.getId() );
+ assertEquals( "DataElementGroupA", dataElementGroupA.getName() );
+
+ dataElementGroupB = dataElementGroupStore.getByName( "DataElementGroupB" );
+ assertNotNull( dataElementGroupB );
+ assertEquals( idB, dataElementGroupB.getId() );
+ assertEquals( "DataElementGroupB", dataElementGroupB.getName() );
+
+ DataElementGroup dataElementGroupC = dataElementGroupStore.getByName( "DataElementGroupC" );
+ assertNull( dataElementGroupC );
+ }
+
+ @Test
+ public void testGetAllDataElementGroups()
+ throws Exception
+ {
+ DataElementGroup dataElementGroupA = new DataElementGroup( "DataElementGroupA" );
+ DataElementGroup dataElementGroupB = new DataElementGroup( "DataElementGroupB" );
+ dataElementGroupStore.save( dataElementGroupA );
+ dataElementGroupStore.save( dataElementGroupB );
+
+ Collection<DataElementGroup> groups = dataElementGroupStore.getAll();
+
+ assertTrue( groups.size() == 2 );
+ assertTrue( groups.contains( dataElementGroupA ) );
+ assertTrue( groups.contains( dataElementGroupB ) );
+ }
+}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementStoreTest.java 2009-06-10 22:25:07 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementStoreTest.java 2009-10-27 16:24:02 +0000
@@ -529,182 +529,4 @@
cdes = dataElementStore.getCalculatedDataElementsByDataElements( dataElements );
assertEquals( 2, cdes.size() );
}
-
- // -------------------------------------------------------------------------
- // DataElementGroup
- // -------------------------------------------------------------------------
-
- @Test
- public void testAddDataElementGroup()
- {
- DataElementGroup dataElementGroupA = new DataElementGroup( "DataElementGroupA" );
- DataElementGroup dataElementGroupB = new DataElementGroup( "DataElementGroupB" );
- DataElementGroup dataElementGroupC = new DataElementGroup( "DataElementGroupC" );
- DataElementGroup dataElementGroupD = new DataElementGroup( "DataElementGroupA" );
-
- int idA = dataElementStore.addDataElementGroup( dataElementGroupA );
- int idB = dataElementStore.addDataElementGroup( dataElementGroupB );
- int idC = dataElementStore.addDataElementGroup( dataElementGroupC );
-
- try
- {
- // Should give unique constraint violation
- dataElementStore.addDataElementGroup( dataElementGroupD );
- fail();
- }
- catch ( Exception e )
- {
- // Expected
- }
-
- dataElementGroupA = dataElementStore.getDataElementGroup( idA );
- assertNotNull( dataElementGroupA );
- assertEquals( idA, dataElementGroupA.getId() );
- assertEquals( "DataElementGroupA", dataElementGroupA.getName() );
-
- dataElementGroupB = dataElementStore.getDataElementGroup( idB );
- assertNotNull( dataElementGroupB );
- assertEquals( idB, dataElementGroupB.getId() );
- assertEquals( "DataElementGroupB", dataElementGroupB.getName() );
-
- dataElementGroupC = dataElementStore.getDataElementGroup( idC );
- assertNotNull( dataElementGroupC );
- assertEquals( idC, dataElementGroupC.getId() );
- assertEquals( "DataElementGroupC", dataElementGroupC.getName() );
- }
-
- @Test
- public void testUpdateDataElementGroup()
- {
- DataElementGroup dataElementGroupA = new DataElementGroup( "DataElementGroupA" );
- DataElementGroup dataElementGroupB = new DataElementGroup( "DataElementGroupB" );
- DataElementGroup dataElementGroupC = new DataElementGroup( "DataElementGroupC" );
-
- int idA = dataElementStore.addDataElementGroup( dataElementGroupA );
- int idB = dataElementStore.addDataElementGroup( dataElementGroupB );
- int idC = dataElementStore.addDataElementGroup( dataElementGroupC );
-
- dataElementGroupA = dataElementStore.getDataElementGroup( idA );
- assertNotNull( dataElementGroupA );
- assertEquals( idA, dataElementGroupA.getId() );
- assertEquals( "DataElementGroupA", dataElementGroupA.getName() );
-
- dataElementGroupA.setName( "DataElementGroupAA" );
- dataElementStore.updateDataElementGroup( dataElementGroupA );
-
- dataElementGroupA = dataElementStore.getDataElementGroup( idA );
- assertNotNull( dataElementGroupA );
- assertEquals( idA, dataElementGroupA.getId() );
- assertEquals( "DataElementGroupAA", dataElementGroupA.getName() );
-
- dataElementGroupB = dataElementStore.getDataElementGroup( idB );
- assertNotNull( dataElementGroupB );
- assertEquals( idB, dataElementGroupB.getId() );
- assertEquals( "DataElementGroupB", dataElementGroupB.getName() );
-
- dataElementGroupC = dataElementStore.getDataElementGroup( idC );
- assertNotNull( dataElementGroupC );
- assertEquals( idC, dataElementGroupC.getId() );
- assertEquals( "DataElementGroupC", dataElementGroupC.getName() );
- }
-
- @Test
- public void testDeleteAndGetDataElementGroup()
- {
- DataElementGroup dataElementGroupA = new DataElementGroup( "DataElementGroupA" );
- DataElementGroup dataElementGroupB = new DataElementGroup( "DataElementGroupB" );
- DataElementGroup dataElementGroupC = new DataElementGroup( "DataElementGroupC" );
- DataElementGroup dataElementGroupD = new DataElementGroup( "DataElementGroupD" );
-
- int idA = dataElementStore.addDataElementGroup( dataElementGroupA );
- int idB = dataElementStore.addDataElementGroup( dataElementGroupB );
- int idC = dataElementStore.addDataElementGroup( dataElementGroupC );
- int idD = dataElementStore.addDataElementGroup( dataElementGroupD );
-
- assertNotNull( dataElementStore.getDataElementGroup( idA ) );
- assertNotNull( dataElementStore.getDataElementGroup( idB ) );
- assertNotNull( dataElementStore.getDataElementGroup( idC ) );
- assertNotNull( dataElementStore.getDataElementGroup( idD ) );
-
- dataElementStore.deleteDataElementGroup( dataElementGroupA );
- assertNull( dataElementStore.getDataElementGroup( idA ) );
- assertNotNull( dataElementStore.getDataElementGroup( idB ) );
- assertNotNull( dataElementStore.getDataElementGroup( idC ) );
- assertNotNull( dataElementStore.getDataElementGroup( idD ) );
-
- dataElementStore.deleteDataElementGroup( dataElementGroupB );
- assertNull( dataElementStore.getDataElementGroup( idA ) );
- assertNull( dataElementStore.getDataElementGroup( idB ) );
- assertNotNull( dataElementStore.getDataElementGroup( idC ) );
- assertNotNull( dataElementStore.getDataElementGroup( idD ) );
-
- dataElementStore.deleteDataElementGroup( dataElementGroupC );
- assertNull( dataElementStore.getDataElementGroup( idA ) );
- assertNull( dataElementStore.getDataElementGroup( idB ) );
- assertNull( dataElementStore.getDataElementGroup( idC ) );
- assertNotNull( dataElementStore.getDataElementGroup( idD ) );
-
- dataElementStore.deleteDataElementGroup( dataElementGroupD );
- assertNull( dataElementStore.getDataElementGroup( idA ) );
- assertNull( dataElementStore.getDataElementGroup( idB ) );
- assertNull( dataElementStore.getDataElementGroup( idC ) );
- assertNull( dataElementStore.getDataElementGroup( idD ) );
- }
-
- @Test
- public void testGetDataElementGroupByUUID()
- {
- String uuid = UUIdUtils.getUUId();
-
- DataElementGroup groupA = new DataElementGroup( "groupA" );
- groupA.setUuid( uuid );
-
- dataElementStore.addDataElementGroup( groupA );
-
- groupA = dataElementStore.getDataElementGroup( uuid );
-
- assertNotNull( groupA );
- assertEquals( groupA.getUuid(), uuid );
- }
-
- @Test
- public void testGetDataElementGroupByName()
- {
- DataElementGroup dataElementGroupA = new DataElementGroup( "DataElementGroupA" );
- DataElementGroup dataElementGroupB = new DataElementGroup( "DataElementGroupB" );
- int idA = dataElementStore.addDataElementGroup( dataElementGroupA );
- int idB = dataElementStore.addDataElementGroup( dataElementGroupB );
-
- assertNotNull( dataElementStore.getDataElementGroup( idA ) );
- assertNotNull( dataElementStore.getDataElementGroup( idB ) );
-
- dataElementGroupA = dataElementStore.getDataElementGroupByName( "DataElementGroupA" );
- assertNotNull( dataElementGroupA );
- assertEquals( idA, dataElementGroupA.getId() );
- assertEquals( "DataElementGroupA", dataElementGroupA.getName() );
-
- dataElementGroupB = dataElementStore.getDataElementGroupByName( "DataElementGroupB" );
- assertNotNull( dataElementGroupB );
- assertEquals( idB, dataElementGroupB.getId() );
- assertEquals( "DataElementGroupB", dataElementGroupB.getName() );
-
- DataElementGroup dataElementGroupC = dataElementStore.getDataElementGroupByName( "DataElementGroupC" );
- assertNull( dataElementGroupC );
- }
-
- @Test
- public void testGetAllDataElementGroups()
- throws Exception
- {
- DataElementGroup dataElementGroupA = new DataElementGroup( "DataElementGroupA" );
- DataElementGroup dataElementGroupB = new DataElementGroup( "DataElementGroupB" );
- dataElementStore.addDataElementGroup( dataElementGroupA );
- dataElementStore.addDataElementGroup( dataElementGroupB );
-
- Collection<DataElementGroup> groups = dataElementStore.getAllDataElementGroups();
-
- assertTrue( groups.size() == 2 );
- assertTrue( groups.contains( dataElementGroupA ) );
- assertTrue( groups.contains( dataElementGroupB ) );
- }
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/validation/ValidationRuleGroupStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/validation/ValidationRuleGroupStoreTest.java 2009-06-20 14:26:19 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/validation/ValidationRuleGroupStoreTest.java 2009-10-27 16:24:02 +0000
@@ -37,7 +37,7 @@
import java.util.Set;
import org.hisp.dhis.DhisSpringTest;
-import org.hisp.dhis.common.GenericNameStore;
+import org.hisp.dhis.common.GenericIdentifiableObjectStore;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementService;
import org.hisp.dhis.expression.Expression;
@@ -52,9 +52,9 @@
public class ValidationRuleGroupStoreTest
extends DhisSpringTest
{
- private GenericNameStore<ValidationRule> validationRuleStore;
+ private GenericIdentifiableObjectStore<ValidationRule> validationRuleStore;
- private GenericNameStore<ValidationRuleGroup> validationRuleGroupStore;
+ private GenericIdentifiableObjectStore<ValidationRuleGroup> validationRuleGroupStore;
private ExpressionService expressionService;
@@ -76,9 +76,9 @@
public void setUpTest()
throws Exception
{
- validationRuleStore = (GenericNameStore<ValidationRule>) getBean( "org.hisp.dhis.validation.ValidationRuleStore" );
+ validationRuleStore = (GenericIdentifiableObjectStore<ValidationRule>) getBean( "org.hisp.dhis.validation.ValidationRuleStore" );
- validationRuleGroupStore = (GenericNameStore<ValidationRuleGroup>) getBean( "org.hisp.dhis.validation.ValidationRuleGroupStore" );
+ validationRuleGroupStore = (GenericIdentifiableObjectStore<ValidationRuleGroup>) getBean( "org.hisp.dhis.validation.ValidationRuleGroupStore" );
dataElementService = (DataElementService) getBean( DataElementService.ID );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/validation/ValidationRuleStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/validation/ValidationRuleStoreTest.java 2009-09-25 21:45:01 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/validation/ValidationRuleStoreTest.java 2009-10-27 16:24:02 +0000
@@ -37,7 +37,7 @@
import java.util.Set;
import org.hisp.dhis.DhisTest;
-import org.hisp.dhis.common.GenericNameStore;
+import org.hisp.dhis.common.GenericIdentifiableObjectStore;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementService;
import org.hisp.dhis.expression.Expression;
@@ -52,7 +52,7 @@
public class ValidationRuleStoreTest
extends DhisTest
{
- private GenericNameStore<ValidationRule> validationRuleStore;
+ private GenericIdentifiableObjectStore<ValidationRule> validationRuleStore;
private ExpressionService expressionService;
@@ -74,7 +74,7 @@
public void setUpTest()
throws Exception
{
- validationRuleStore = (GenericNameStore<ValidationRule>) getBean( "org.hisp.dhis.validation.ValidationRuleStore" );
+ validationRuleStore = (GenericIdentifiableObjectStore<ValidationRule>) getBean( "org.hisp.dhis.validation.ValidationRuleStore" );
dataElementService = (DataElementService) getBean( DataElementService.ID );