dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #02983
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 989: Introduced method DimensionSet.getDimensionOptionElements.
------------------------------------------------------------
revno: 989
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Fri 2009-11-06 12:58:30 +0100
message:
Introduced method DimensionSet.getDimensionOptionElements.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryCombo.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dimension/DimensionService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dimension/DimensionSet.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/Indicator.java
dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataelement/DimensionTest.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dimension/DefaultDimensionService.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/DataElement.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java 2009-11-06 10:50:01 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java 2009-11-06 11:58:30 +0000
@@ -237,7 +237,17 @@
public List<? extends DimensionOptionElement> getDimensionOptionElements()
{
- return null;
+ List<DimensionOptionElement> dimensionOptionElements = new ArrayList<DimensionOptionElement>();
+
+ for ( Dimension dimension : getDimensions() )
+ {
+ for ( DimensionOption dimensionOption : dimension.getDimensionOptions() )
+ {
+ dimensionOptionElements.addAll( dimensionOption.getDimensionOptionElements() );
+ }
+ }
+
+ return dimensionOptionElements;
}
public List<? extends DimensionOption> getDimensionOptions()
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryCombo.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryCombo.java 2009-11-05 19:04:58 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryCombo.java 2009-11-06 11:58:30 +0000
@@ -34,6 +34,7 @@
import java.util.Set;
import org.hisp.dhis.dimension.Dimension;
+import org.hisp.dhis.dimension.DimensionOptionElement;
import org.hisp.dhis.dimension.DimensionSet;
/**
@@ -74,6 +75,11 @@
return categories;
}
+ public List<? extends DimensionOptionElement> getDimensionOptionElements()
+ {
+ return new ArrayList<DimensionOptionElement>( optionCombos );
+ }
+
// -------------------------------------------------------------------------
// Constructors
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dimension/DimensionService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dimension/DimensionService.java 2009-11-03 11:34:31 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dimension/DimensionService.java 2009-11-06 11:58:30 +0000
@@ -38,7 +38,11 @@
Collection<DimensionSet> getAllDimensionSets();
- Collection<Dimension> getAllDimensions();
-
- Collection<DimensionOption> getAllDimensionOptions();
+ Collection<DimensionSet> getDataElementDimensionSets();
+
+ DimensionSet getDataElementDimensionSetByName( String name );
+
+ Collection<DimensionSet> getIndicatorDimensionSets();
+
+ DimensionSet getIndicatorDimensionSetByName( String name );
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dimension/DimensionSet.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dimension/DimensionSet.java 2009-10-27 18:39:55 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dimension/DimensionSet.java 2009-11-06 11:58:30 +0000
@@ -37,4 +37,6 @@
String getName();
List<? extends Dimension> getDimensions();
+
+ List<? extends DimensionOptionElement> getDimensionOptionElements();
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/Indicator.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/Indicator.java 2009-11-06 10:21:54 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/Indicator.java 2009-11-06 11:58:30 +0000
@@ -115,6 +115,21 @@
{
return new ArrayList<DimensionOption>( groups );
}
+
+ public List<? extends DimensionOptionElement> getDimensionOptionElements()
+ {
+ List<DimensionOptionElement> dimensionOptionElements = new ArrayList<DimensionOptionElement>();
+
+ for ( Dimension dimension : getDimensions() )
+ {
+ for ( DimensionOption dimensionOption : dimension.getDimensionOptions() )
+ {
+ dimensionOptionElements.addAll( dimensionOption.getDimensionOptionElements() );
+ }
+ }
+
+ return dimensionOptionElements;
+ }
public boolean isDimensionSet()
{
=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataelement/DimensionTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataelement/DimensionTest.java 2009-10-27 18:39:55 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataelement/DimensionTest.java 2009-11-06 11:58:30 +0000
@@ -27,10 +27,12 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.List;
import java.util.Map;
import org.hisp.dhis.dimension.Dimension;
import org.hisp.dhis.dimension.DimensionOption;
+import org.hisp.dhis.dimension.DimensionOptionElement;
import org.hisp.dhis.datavalue.DataValue;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.period.MonthlyPeriodType;
@@ -78,6 +80,8 @@
Map<Dimension, DimensionOption> dimensions = dataValue.getDimensions( diseaseByType );
+ // Test Measure.getDimensions
+
assertEquals( 4, dimensions.size() );
assertTrue( dimensions.keySet().contains( diseaseType ) );
@@ -105,5 +109,23 @@
assertTrue( dimensions.values().contains( diabetes ) );
assertTrue( dimensions.values().contains( period ) );
assertTrue( dimensions.values().contains( source ) );
+
+ // Test Dimension.getDimensionOption
+
+ assertEquals( communicable, diseaseType.getDimensionOption( hivAids ) );
+ assertEquals( communicable, diseaseType.getDimensionOption( malaria ) );
+ assertEquals( nonCommunicable, diseaseType.getDimensionOption( diabetes ) );
+ assertEquals( nonCommunicable, diseaseType.getDimensionOption( cancer ) );
+
+ // Test DimensionSet.getDimensionOptionElements
+
+ List<? extends DimensionOptionElement> dimensionOptionElements = diseaseByType.getDimensionOptionElements();
+
+ assertEquals( 4, dimensionOptionElements.size() );
+
+ assertTrue( dimensionOptionElements.contains( hivAids ) );
+ assertTrue( dimensionOptionElements.contains( malaria ) );
+ assertTrue( dimensionOptionElements.contains( diabetes ) );
+ assertTrue( dimensionOptionElements.contains( cancer ) );
}
}
=== 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-10-27 18:39:55 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dimension/DefaultDimensionService.java 2009-11-06 11:58:30 +0000
@@ -30,9 +30,6 @@
import java.util.ArrayList;
import java.util.Collection;
-import org.hisp.dhis.dimension.Dimension;
-import org.hisp.dhis.dimension.DimensionOption;
-import org.hisp.dhis.dimension.DimensionSet;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementCategoryService;
import org.hisp.dhis.dataelement.DataElementService;
@@ -74,18 +71,70 @@
// -------------------------------------------------------------------------
// DimensionService implementation
// -------------------------------------------------------------------------
+
+ public Collection<DimensionSet> getDataElementDimensionSets()
+ {
+ Collection<DimensionSet> dimensionSets = new ArrayList<DimensionSet>();
+
+ for ( DataElement dataElement : dataElementService.getAllDataElements() )
+ {
+ if ( dataElement.isDimensionSet() )
+ {
+ dimensionSets.add( dataElement );
+ }
+ }
+
+ dimensionSets.addAll( categoryService.getAllDataElementCategoryCombos() );
+
+ return dimensionSets;
+ }
+
+ public DimensionSet getDataElementDimensionSetByName( String name )
+ {
+ for ( DimensionSet dimensionSet : getDataElementDimensionSets() )
+ {
+ if ( dimensionSet.getName().equals( name ) )
+ {
+ return dimensionSet;
+ }
+ }
+
+ return null;
+ }
+
+ public Collection<DimensionSet> getIndicatorDimensionSets()
+ {
+ Collection<DimensionSet> dimensionSets = new ArrayList<DimensionSet>();
+
+ for ( DataElement dataElement : dataElementService.getAllDataElements() )
+ {
+ if ( dataElement.isDimensionSet() )
+ {
+ dimensionSets.add( dataElement );
+ }
+ }
+
+ dimensionSets.addAll( categoryService.getAllDataElementCategoryCombos() );
+
+ return dimensionSets;
+ }
+
+ public DimensionSet getIndicatorDimensionSetByName( String name )
+ {
+ for ( DimensionSet dimensionSet : getIndicatorDimensionSets() )
+ {
+ if ( dimensionSet.getName().equals( name ) )
+ {
+ return dimensionSet;
+ }
+ }
+
+ return null;
+ }
public Collection<DimensionSet> getAllDimensionSets()
{
- Collection<DimensionSet> dimensionSets = new ArrayList<DimensionSet>();
-
- for ( DataElement dataElement : dataElementService.getAllDataElements() )
- {
- if ( dataElement.isDimensionSet() )
- {
- dimensionSets.add( dataElement );
- }
- }
+ Collection<DimensionSet> dimensionSets = getDataElementDimensionSets();
for ( Indicator indicator : indicatorService.getAllIndicators() )
{
@@ -95,30 +144,6 @@
}
}
- dimensionSets.addAll( categoryService.getAllDataElementCategoryCombos() );
-
return dimensionSets;
}
-
- public Collection<Dimension> getAllDimensions()
- {
- Collection<Dimension> dimensions = new ArrayList<Dimension>();
-
- dimensions.addAll( dataElementService.getAllDataElementGroupSets() );
- dimensions.addAll( indicatorService.getAllIndicatorGroupSets() );
- dimensions.addAll( categoryService.getAllDataElementCategories() );
-
- return dimensions;
- }
-
- public Collection<DimensionOption> getAllDimensionOptions()
- {
- Collection<DimensionOption> dimensionOptions = new ArrayList<DimensionOption>();
-
- dimensionOptions.addAll( dataElementService.getAllDataElementGroups() );
- dimensionOptions.addAll( indicatorService.getAllIndicatorGroups() );
- dimensionOptions.addAll( categoryService.getAllDataElementCategoryOptions() );
-
- return dimensionOptions;
- }
}