dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #03032
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1021: Work in progress on DimensionService.
------------------------------------------------------------
revno: 1021
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Tue 2009-11-10 16:53:07 +0100
message:
Work in progress on DimensionService.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.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/java/org/hisp/dhis/dimension/DefaultDimensionService.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementServiceTest.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-11-07 14:09:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java 2009-11-10 15:53:07 +0000
@@ -29,6 +29,7 @@
import java.util.Collection;
import java.util.Map;
+import java.util.Set;
import org.hisp.dhis.hierarchy.HierarchyViolationException;
@@ -229,6 +230,14 @@
*/
Collection<DataElement> getDataElementsWithGroupSets();
+ /**
+ * Returns all DataElements which are associated with the given set of DataElementGroupSets.
+ *
+ * @param groupSets the set of DataElementGroupSets.
+ * @return all DataElements which are associated with the given set of DataElementGroupSets.
+ */
+ Collection<DataElement> getDataElementsByGroupSets( Set<DataElementGroupSet> groupSets );
+
// -------------------------------------------------------------------------
// Calculated Data Elements
// -------------------------------------------------------------------------
=== 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-11-07 14:09:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java 2009-11-10 15:53:07 +0000
@@ -31,8 +31,10 @@
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
+import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -264,6 +266,21 @@
return dataElementStore.getDataElementsWithGroupSets();
}
+ public Collection<DataElement> getDataElementsByGroupSets( Set<DataElementGroupSet> groupSets )
+ {
+ Collection<DataElement> dataElements = new HashSet<DataElement>();
+
+ for ( DataElement dataElement : getDataElementsWithGroupSets() )
+ {
+ if ( dataElement.getGroupSets() != null && new HashSet<DataElementGroupSet>( dataElement.getGroupSets() ).equals( groupSets ) )
+ {
+ dataElements.add( dataElement );
+ }
+ }
+
+ return dataElements;
+ }
+
// -------------------------------------------------------------------------
// CalculatedDataElement
// -------------------------------------------------------------------------
=== modified 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 2009-11-10 15:17:51 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dimension/DefaultDimensionService.java 2009-11-10 15:53:07 +0000
@@ -119,7 +119,7 @@
{
Set<DataElementGroupSet> dimensionSet = getDataElementDimensionSet( getDimensionSetIdentifiers( identifier ) );
- // TODO return dataElementService.getDataElementsByDimensionSet( dimensionSet );
+ return dataElementService.getDataElementsByGroupSets( dimensionSet );
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementServiceTest.java 2009-11-10 11:45:58 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementServiceTest.java 2009-11-10 15:53:07 +0000
@@ -452,6 +452,41 @@
assertEquals( 3, dataElementService.getDataElementsByType( DataElement.VALUE_TYPE_BOOL ).size() );
}
+ @Test
+ public void testGetDataElementsByGroupSets()
+ {
+ DataElementGroupSet groupSetA = createDataElementGroupSet( 'A' );
+ DataElementGroupSet groupSetB = createDataElementGroupSet( 'B' );
+
+ dataElementService.addDataElementGroupSet( groupSetA );
+ dataElementService.addDataElementGroupSet( groupSetB );
+
+ DataElement dataElementA = createDataElement( 'A' );
+ DataElement dataElementB = createDataElement( 'B' );
+ DataElement dataElementC = createDataElement( 'C' );
+ DataElement dataElementD = createDataElement( 'D' );
+
+ dataElementB.getGroupSets().add( groupSetA );
+ dataElementB.getGroupSets().add( groupSetB );
+ dataElementD.getGroupSets().add( groupSetA );
+ dataElementD.getGroupSets().add( groupSetB );
+
+ dataElementService.addDataElement( dataElementA );
+ dataElementService.addDataElement( dataElementB );
+ dataElementService.addDataElement( dataElementC );
+ dataElementService.addDataElement( dataElementD );
+
+ Set<DataElementGroupSet> groupSets = new HashSet<DataElementGroupSet>();
+ groupSets.add( groupSetA );
+ groupSets.add( groupSetB );
+
+ Collection<DataElement> dataElements = dataElementService.getDataElementsByGroupSets( groupSets );
+
+ assertEquals( 2, dataElements.size() );
+ assertTrue( dataElements.contains( dataElementB ) );
+ assertTrue( dataElements.contains( dataElementD ) );
+ }
+
// -------------------------------------------------------------------------
// CalculatedDataElements
// -------------------------------------------------------------------------