dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #06619
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1835: Added two new methods for retrieving map values (which are using aggregation service)
------------------------------------------------------------
revno: 1835
committer: Lars <larshelg@larshelg-laptop>
branch nick: trunk
timestamp: Sat 2010-07-10 17:37:10 +0200
message:
Added two new methods for retrieving map values (which are using aggregation service)
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/aggregation/AggregationService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java
dhis-2/dhis-services/dhis-service-mapping/pom.xml
dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java
dhis-2/dhis-services/dhis-service-mapping/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-services/dhis-service-mapping/src/test/java/org/hisp/dhis/mapping/MappingServiceTest.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/aggregation/AggregationService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/aggregation/AggregationService.java 2010-07-10 14:50:48 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/aggregation/AggregationService.java 2010-07-10 15:37:10 +0000
@@ -50,7 +50,7 @@
* @param startDate the start date of the aggregation period.
* @param endDate the end date of the aggregation period.
* @param organisationUnit the OrganisationUnit to aggregate over.
- * @return the aggregated value.
+ * @return the aggregated value or null if no values are found.
* @throws AggregationStoreException
*/
Double getAggregatedDataValue( DataElement dataElement, DataElementCategoryOptionCombo optionCombo, Date startDate, Date endDate,
@@ -63,7 +63,7 @@
* @param startDate the start date of the aggregation period.
* @param endDate the end date of the aggregation period.
* @param organisationUnit the OrganisationUnit to aggregate over.
- * @return the aggregated value.
+ * @return the aggregated value or null if no values are found.
* @throws AggregationStoreException
*/
Double getAggregatedIndicatorValue( Indicator indicator, Date startDate, Date endDate,
@@ -76,7 +76,7 @@
* @param startDate the start date of the aggregation period.
* @param endDate the end date of the aggregation period.
* @param organisationUnit the OrganisationUnit to aggregate over.
- * @return the aggregated value.
+ * @return the aggregated value or null if no values are found.
* @throws AggregationStoreException
*/
Double getAggregatedNumeratorValue( Indicator indicator, Date startDate, Date endDate,
@@ -90,7 +90,7 @@
* @param startDate the start date of the aggregation period.
* @param endDate the end date of the aggregation period.
* @param organisationUnit the OrganisationUnit to aggregate over.
- * @return the aggregated value.
+ * @return the aggregated value or null if no values are found.
* @throws AggregationStoreException
*/
Double getAggregatedDenominatorValue( Indicator indicator, Date startDate, Date endDate,
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java 2010-05-31 22:32:45 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java 2010-07-10 15:37:10 +0000
@@ -62,6 +62,8 @@
Collection<AggregatedMapValue> getAggregatedDataMapValues( int dataElementId, int periodId, int level );
+ Collection<AggregatedMapValue> getDataElementMapValues( int dataElementId, int periodId, int parentOrganisationUnitId );
+
// -------------------------------------------------------------------------
// IndicatorMapValue
// -------------------------------------------------------------------------
@@ -73,6 +75,8 @@
Collection<AggregatedMapValue> getAggregatedIndicatorMapValues( int indicatorId, int periodId, int level );
+ Collection<AggregatedMapValue> getIndicatorMapValues( int indicatorId, int periodId, int parentOrganisationUnitId );
+
// -------------------------------------------------------------------------
// Map
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-mapping/pom.xml'
--- dhis-2/dhis-services/dhis-service-mapping/pom.xml 2010-04-21 19:45:12 +0000
+++ dhis-2/dhis-services/dhis-service-mapping/pom.xml 2010-07-10 15:37:10 +0000
@@ -29,6 +29,10 @@
<groupId>org.hisp.dhis</groupId>
<artifactId>dhis-service-datamart-default</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.hisp.dhis</groupId>
+ <artifactId>dhis-service-aggregationengine-default</artifactId>
+ </dependency>
<!-- Other -->
=== modified file 'dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java'
--- dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java 2010-06-01 15:46:07 +0000
+++ dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java 2010-07-10 15:37:10 +0000
@@ -39,6 +39,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.aggregation.AggregatedMapValue;
+import org.hisp.dhis.aggregation.AggregationService;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementGroup;
import org.hisp.dhis.dataelement.DataElementService;
@@ -121,6 +122,13 @@
{
this.dataMartStore = dataMartStore;
}
+
+ private AggregationService aggregationService;
+
+ public void setAggregationService( AggregationService aggregationService )
+ {
+ this.aggregationService = aggregationService;
+ }
// -------------------------------------------------------------------------
// MappingService implementation
@@ -143,6 +151,33 @@
return dataMartStore.getAggregatedDataMapValues( dataElementId, periodId, level );
}
+ public Collection<AggregatedMapValue> getDataElementMapValues( int dataElementId, int periodId, int parentOrganisationUnitId )
+ {
+ Collection<AggregatedMapValue> values = new HashSet<AggregatedMapValue>();
+
+ OrganisationUnit parent = organisationUnitService.getOrganisationUnit( parentOrganisationUnitId );
+ DataElement dataElement = dataElementService.getDataElement( dataElementId );
+ Period period = periodService.getPeriod( periodId );
+
+ for ( OrganisationUnit organisationUnit : parent.getChildren() )
+ {
+ Double value = aggregationService.getAggregatedDataValue( dataElement, null, period.getStartDate(), period.getEndDate(), organisationUnit );
+
+ if ( value != null )
+ {
+ AggregatedMapValue mapValue = new AggregatedMapValue();
+ mapValue.setOrganisationUnitId( organisationUnit.getId() );
+ mapValue.setOrganisationUnitName( organisationUnit.getName() );
+ mapValue.setPeriodId( period.getId() );
+ mapValue.setValue( value );
+
+ values.add( mapValue );
+ }
+ }
+
+ return values;
+ }
+
// -------------------------------------------------------------------------
// IndicatorMapValues
// -------------------------------------------------------------------------
@@ -168,15 +203,6 @@
organisationUnitId );
}
- // java.util.Map<Integer, String> relations =
- // getOrganisationUnitFeatureMap( getMapOrganisationUnitRelationsByMap(
- // map ) );
-
- // for ( AggregatedMapValue value : mapValues )
- // {
- // value.setFeatureId( relations.get( value.getOrganisationUnitId() ) );
- // }
-
return mapValues;
}
@@ -193,21 +219,33 @@
return dataMartStore.getAggregatedIndicatorMapValues( indicatorId, periodId, level );
}
- /**
- * Returns a map for the given MapOrganisationUnitRelations where the key is
- * the OrganisationUnit identifier and the value is the feature identifier.
- */
- /*
- * private java.util.Map<Integer, String> getOrganisationUnitFeatureMap(
- * Collection<MapOrganisationUnitRelation> relations ) {
- * java.util.Map<Integer, String> map = new HashMap<Integer, String>();
- *
- * for ( MapOrganisationUnitRelation relation : relations ) { map.put(
- * relation.getOrganisationUnit().getId(), relation.getFeatureId() ); }
- *
- * return map; }
- */
-
+ public Collection<AggregatedMapValue> getIndicatorMapValues( int indicatorId, int periodId, int parentOrganisationUnitId )
+ {
+ Collection<AggregatedMapValue> values = new HashSet<AggregatedMapValue>();
+
+ OrganisationUnit parent = organisationUnitService.getOrganisationUnit( parentOrganisationUnitId );
+ Indicator indicator = indicatorService.getIndicator( indicatorId );
+ Period period = periodService.getPeriod( periodId );
+
+ for ( OrganisationUnit organisationUnit : parent.getChildren() )
+ {
+ Double value = aggregationService.getAggregatedIndicatorValue( indicator, period.getStartDate(), period.getEndDate(), organisationUnit );
+
+ if ( value != null )
+ {
+ AggregatedMapValue mapValue = new AggregatedMapValue();
+ mapValue.setOrganisationUnitId( organisationUnit.getId() );
+ mapValue.setOrganisationUnitName( organisationUnit.getName() );
+ mapValue.setPeriodId( period.getId() );
+ mapValue.setValue( value );
+
+ values.add( mapValue );
+ }
+ }
+
+ return values;
+ }
+
// -------------------------------------------------------------------------
// Map
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-mapping/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-mapping/src/main/resources/META-INF/dhis/beans.xml 2010-06-01 15:46:07 +0000
+++ dhis-2/dhis-services/dhis-service-mapping/src/main/resources/META-INF/dhis/beans.xml 2010-07-10 15:37:10 +0000
@@ -24,6 +24,8 @@
ref="org.hisp.dhis.user.UserSettingService"/>
<property name="dataMartStore"
ref="org.hisp.dhis.datamart.DataMartStore"/>
+ <property name="aggregationService"
+ ref="org.hisp.dhis.aggregation.AggregationService"/>
</bean>
<!-- Store definitions -->
@@ -86,6 +88,11 @@
<aop:before pointcut="execution( * org.hisp.dhis.mapping.MappingService.deleteMapView(..) )" method="intercept"/>
</aop:aspect>
+ <aop:aspect ref="statementInterceptor">
+ <aop:around pointcut="execution( * org.hisp.dhis.mapping.MappingService.getDataElementMapValues(..) )" method="intercept"/>
+ <aop:around pointcut="execution( * org.hisp.dhis.mapping.MappingService.getIndicatorMapValues(..) )" method="intercept"/>
+ </aop:aspect>
+
</aop:config>
</beans>
=== modified file 'dhis-2/dhis-services/dhis-service-mapping/src/test/java/org/hisp/dhis/mapping/MappingServiceTest.java'
--- dhis-2/dhis-services/dhis-service-mapping/src/test/java/org/hisp/dhis/mapping/MappingServiceTest.java 2010-05-31 22:32:45 +0000
+++ dhis-2/dhis-services/dhis-service-mapping/src/test/java/org/hisp/dhis/mapping/MappingServiceTest.java 2010-07-10 15:37:10 +0000
@@ -34,6 +34,7 @@
import org.hisp.dhis.DhisSpringTest;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementGroup;
+import org.hisp.dhis.dataelement.DataElementService;
import org.hisp.dhis.indicator.Indicator;
import org.hisp.dhis.indicator.IndicatorGroup;
import org.hisp.dhis.indicator.IndicatorService;
@@ -66,6 +67,8 @@
private Indicator indicator;
+ private DataElement dataElement;
+
private PeriodType periodType;
private Period period;
@@ -93,6 +96,8 @@
indicatorService = (IndicatorService) getBean( IndicatorService.ID );
+ dataElementService = (DataElementService) getBean( DataElementService.ID );
+
periodService = (PeriodService) getBean( PeriodService.ID );
organisationUnit = createOrganisationUnit( 'A' );
@@ -116,6 +121,9 @@
indicator = createIndicator( 'A', indicatorType );
indicatorService.addIndicator( indicator );
+ dataElement = createDataElement( 'A' );
+ dataElementService.addDataElement( dataElement );
+
periodType = periodService.getPeriodTypeByName( MonthlyPeriodType.NAME );
period = createPeriod( periodType, getDate( 2000, 1, 1 ), getDate( 2000, 2, 1 ) );
periodService.addPeriod( period );
@@ -222,4 +230,16 @@
assertEquals( periodType, mappingService.getMapView( idA ).getPeriodType() );
assertEquals( period, mappingService.getMapView( idA ).getPeriod() );
}
+
+ // -------------------------------------------------------------------------
+ // MapValue tests
+ // -------------------------------------------------------------------------
+
+ @Test
+ public void testMapValues()
+ {
+ mappingService.getDataElementMapValues( dataElement.getId(), period.getId(), organisationUnit.getId() );
+ mappingService.getIndicatorMapValues( indicator.getId(), period.getId(), organisationUnit.getId() );
+ }
+
}