dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #13666
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4441: Fixed bug in data set reports, statement interceptor was not intercepting calls to the service layer
Merge authors:
Lars Helge Øverland (larshelge)
------------------------------------------------------------
revno: 4441 [merge]
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-08-25 11:18:44 +0200
message:
Fixed bug in data set reports, statement interceptor was not intercepting calls to the service layer
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/datasetreport/DataSetReportService.java
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/impl/DefaultDataSetReportService.java
dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml
--
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/datasetreport/DataSetReportService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/datasetreport/DataSetReportService.java 2011-05-30 19:32:17 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/datasetreport/DataSetReportService.java 2011-08-25 08:52:40 +0000
@@ -28,10 +28,8 @@
*/
import java.util.List;
-import java.util.Map;
import org.hisp.dhis.common.Grid;
-import org.hisp.dhis.dataentryform.DataEntryForm;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.i18n.I18n;
import org.hisp.dhis.i18n.I18nFormat;
@@ -45,41 +43,6 @@
public interface DataSetReportService
{
/**
- * Generates a map with aggregated data values or regular data values (depending
- * on the selectedUnitOnly argument) mapped to a DataElemenet operand identifier.
- *
- * @param dataSet the DataSet.
- * @param unit the OrganisationUnit.
- * @param period the Period.
- * @param selectedUnitOnly whether to include aggregated or regular data in the map.
- * @param format the I18nFormat.
- * @return a map.
- */
- Map<String, String> getAggregatedValueMap( DataSet dataSet, OrganisationUnit unit, Period period, boolean selectedUnitOnly, I18nFormat format );
-
- /**
- * Generates a map with aggregated indicator values mapped to an Indicator identifier.
- *
- * @param dataSet the DataSet.
- * @param unit the OrganisationUnit.
- * @param period the Period.
- * @param format the I18nFormat.
- * @return a map.
- */
- Map<Integer, String> getAggregatedIndicatorValueMap( DataSet dataSet, OrganisationUnit unit, Period period, I18nFormat format );
-
- /**
- * Puts in aggregated datavalues in the custom dataentry form and returns
- * whole report text.
- *
- * @param dataEntryForm the data entry form.
- * @param a map with aggregated data values mapped to data element operands.
- * @return data entry form HTML code populated with aggregated data in the
- * input fields.
- */
- String prepareReportContent( DataEntryForm dataEntryForm, Map<String, String> dataValues, Map<Integer, String> indicatorValues );
-
- /**
* Generates html code for a custom data set report.
*
* @param dataSet the data set.
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/impl/DefaultDataSetReportService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/impl/DefaultDataSetReportService.java 2011-06-14 15:00:55 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/impl/DefaultDataSetReportService.java 2011-08-25 08:52:40 +0000
@@ -127,122 +127,6 @@
// DataSetReportService implementation
// -------------------------------------------------------------------------
- public Map<String, String> getAggregatedValueMap( DataSet dataSet, OrganisationUnit unit, Period period, boolean selectedUnitOnly, I18nFormat format )
- {
- String aggregationStrategy = (String) systemSettingManager.getSystemSetting( KEY_AGGREGATION_STRATEGY, DEFAULT_AGGREGATION_STRATEGY );
-
- Collection<DataElement> dataElements = new ArrayList<DataElement>( dataSet.getDataElements());
-
- FilterUtils.filter( dataElements, new AggregatableDataElementFilter() );
-
- Map<String, String> map = new TreeMap<String, String>();
-
- for ( DataElement dataElement : dataElements )
- {
- for ( DataElementCategoryOptionCombo categoryOptionCombo : dataElement.getCategoryCombo().getOptionCombos() )
- {
- String value;
-
- if ( selectedUnitOnly )
- {
- DataValue dataValue = dataValueService.getDataValue( unit, dataElement, period, categoryOptionCombo );
- value = ( dataValue != null ) ? dataValue.getValue() : null;
- }
- else
- {
- Double aggregatedValue = aggregationStrategy.equals( AGGREGATION_STRATEGY_REAL_TIME ) ?
- aggregationService.getAggregatedDataValue( dataElement, categoryOptionCombo, period.getStartDate(), period.getEndDate(), unit ) :
- aggregatedDataValueService.getAggregatedValue( dataElement, categoryOptionCombo, period, unit );
-
- value = format.formatValue( aggregatedValue );
- }
-
- if ( value != null )
- {
- map.put( dataElement.getId() + SEPARATOR + categoryOptionCombo.getId(), value );
- }
- }
- }
-
- return map;
- }
-
- public Map<Integer, String> getAggregatedIndicatorValueMap( DataSet dataSet, OrganisationUnit unit, Period period, I18nFormat format )
- {
- String aggregationStrategy = (String) systemSettingManager.getSystemSetting( KEY_AGGREGATION_STRATEGY, DEFAULT_AGGREGATION_STRATEGY );
-
- Map<Integer, String> map = new TreeMap<Integer, String>();
-
- for ( Indicator indicator : dataSet.getIndicators() )
- {
- Double aggregatedValue = aggregationStrategy.equals( AGGREGATION_STRATEGY_REAL_TIME ) ?
- aggregationService.getAggregatedIndicatorValue( indicator, period.getStartDate(), period.getEndDate(), unit ) :
- aggregatedDataValueService.getAggregatedValue( indicator, period, unit );
-
- String value = format.formatValue( aggregatedValue );
-
- if ( value != null )
- {
- map.put( indicator.getId(), value );
- }
- }
-
- return map;
- }
-
- public String prepareReportContent( DataEntryForm dataEntryForm, Map<String, String> dataValues, Map<Integer, String> indicatorValues )
- {
- StringBuffer buffer = new StringBuffer();
-
- Matcher inputMatcher = INPUT_PATTERN.matcher( dataEntryForm.getHtmlCode() );
-
- // ---------------------------------------------------------------------
- // Iterate through all matching data element fields.
- // ---------------------------------------------------------------------
-
- while ( inputMatcher.find() )
- {
- // -----------------------------------------------------------------
- // Get input HTML code
- // -----------------------------------------------------------------
-
- String inputHtml = inputMatcher.group( 1 );
-
- Matcher identifierMatcher = IDENTIFIER_PATTERN.matcher( inputHtml );
- Matcher indicatorMatcher = INDICATOR_PATTERN.matcher( inputHtml );
-
- // -----------------------------------------------------------------
- // Find existing data or indicator value and replace input tag
- // -----------------------------------------------------------------
-
- if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 )
- {
- Integer dataElementId = Integer.parseInt( identifierMatcher.group( 1 ) );
- Integer optionComboId = Integer.parseInt( identifierMatcher.group( 2 ) );
-
- String dataValue = dataValues.get( dataElementId + SEPARATOR + optionComboId );
-
- dataValue = dataValue != null ? dataValue : NULL_REPLACEMENT;
-
- inputMatcher.appendReplacement( buffer, dataValue );
- }
- else if ( indicatorMatcher.find() && indicatorMatcher.groupCount() > 0 )
- {
- Integer indicatorId = Integer.parseInt( indicatorMatcher.group( 1 ) );
-
- String indicatorValue = indicatorValues.get( indicatorId );
-
- indicatorValue = indicatorValue != null ? indicatorValue : NULL_REPLACEMENT;
-
- inputMatcher.appendReplacement( buffer, indicatorValue );
- }
- }
-
- inputMatcher.appendTail( buffer );
-
- return buffer.toString();
- }
-
public String getCustomDataSetReport( DataSet dataSet, OrganisationUnit unit, Period period, boolean selectedUnitOnly, I18nFormat format )
{
Map<String, String> aggregatedDataValueMap = getAggregatedValueMap( dataSet, unit, period, selectedUnitOnly, format );
@@ -434,4 +318,153 @@
return grid;
}
+
+ // -------------------------------------------------------------------------
+ // Supportive methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * Generates a map with aggregated data values or regular data values (depending
+ * on the selectedUnitOnly argument) mapped to a DataElemenet operand identifier.
+ *
+ * @param dataSet the DataSet.
+ * @param unit the OrganisationUnit.
+ * @param period the Period.
+ * @param selectedUnitOnly whether to include aggregated or regular data in the map.
+ * @param format the I18nFormat.
+ * @return a map.
+ */
+ private Map<String, String> getAggregatedValueMap( DataSet dataSet, OrganisationUnit unit, Period period, boolean selectedUnitOnly, I18nFormat format )
+ {
+ String aggregationStrategy = (String) systemSettingManager.getSystemSetting( KEY_AGGREGATION_STRATEGY, DEFAULT_AGGREGATION_STRATEGY );
+
+ Collection<DataElement> dataElements = new ArrayList<DataElement>( dataSet.getDataElements());
+
+ FilterUtils.filter( dataElements, new AggregatableDataElementFilter() );
+
+ Map<String, String> map = new TreeMap<String, String>();
+
+ for ( DataElement dataElement : dataElements )
+ {
+ for ( DataElementCategoryOptionCombo categoryOptionCombo : dataElement.getCategoryCombo().getOptionCombos() )
+ {
+ String value;
+
+ if ( selectedUnitOnly )
+ {
+ DataValue dataValue = dataValueService.getDataValue( unit, dataElement, period, categoryOptionCombo );
+ value = ( dataValue != null ) ? dataValue.getValue() : null;
+ }
+ else
+ {
+ Double aggregatedValue = aggregationStrategy.equals( AGGREGATION_STRATEGY_REAL_TIME ) ?
+ aggregationService.getAggregatedDataValue( dataElement, categoryOptionCombo, period.getStartDate(), period.getEndDate(), unit ) :
+ aggregatedDataValueService.getAggregatedValue( dataElement, categoryOptionCombo, period, unit );
+
+ value = format.formatValue( aggregatedValue );
+ }
+
+ if ( value != null )
+ {
+ map.put( dataElement.getId() + SEPARATOR + categoryOptionCombo.getId(), value );
+ }
+ }
+ }
+
+ return map;
+ }
+
+ /**
+ * Generates a map with aggregated indicator values mapped to an Indicator identifier.
+ *
+ * @param dataSet the DataSet.
+ * @param unit the OrganisationUnit.
+ * @param period the Period.
+ * @param format the I18nFormat.
+ * @return a map.
+ */
+ private Map<Integer, String> getAggregatedIndicatorValueMap( DataSet dataSet, OrganisationUnit unit, Period period, I18nFormat format )
+ {
+ String aggregationStrategy = (String) systemSettingManager.getSystemSetting( KEY_AGGREGATION_STRATEGY, DEFAULT_AGGREGATION_STRATEGY );
+
+ Map<Integer, String> map = new TreeMap<Integer, String>();
+
+ for ( Indicator indicator : dataSet.getIndicators() )
+ {
+ Double aggregatedValue = aggregationStrategy.equals( AGGREGATION_STRATEGY_REAL_TIME ) ?
+ aggregationService.getAggregatedIndicatorValue( indicator, period.getStartDate(), period.getEndDate(), unit ) :
+ aggregatedDataValueService.getAggregatedValue( indicator, period, unit );
+
+ String value = format.formatValue( aggregatedValue );
+
+ if ( value != null )
+ {
+ map.put( indicator.getId(), value );
+ }
+ }
+
+ return map;
+ }
+
+ /**
+ * Puts in aggregated datavalues in the custom dataentry form and returns
+ * whole report text.
+ *
+ * @param dataEntryForm the data entry form.
+ * @param a map with aggregated data values mapped to data element operands.
+ * @return data entry form HTML code populated with aggregated data in the
+ * input fields.
+ */
+ private String prepareReportContent( DataEntryForm dataEntryForm, Map<String, String> dataValues, Map<Integer, String> indicatorValues )
+ {
+ StringBuffer buffer = new StringBuffer();
+
+ Matcher inputMatcher = INPUT_PATTERN.matcher( dataEntryForm.getHtmlCode() );
+
+ // ---------------------------------------------------------------------
+ // Iterate through all matching data element fields.
+ // ---------------------------------------------------------------------
+
+ while ( inputMatcher.find() )
+ {
+ // -----------------------------------------------------------------
+ // Get input HTML code
+ // -----------------------------------------------------------------
+
+ String inputHtml = inputMatcher.group( 1 );
+
+ Matcher identifierMatcher = IDENTIFIER_PATTERN.matcher( inputHtml );
+ Matcher indicatorMatcher = INDICATOR_PATTERN.matcher( inputHtml );
+
+ // -----------------------------------------------------------------
+ // Find existing data or indicator value and replace input tag
+ // -----------------------------------------------------------------
+
+ if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 )
+ {
+ Integer dataElementId = Integer.parseInt( identifierMatcher.group( 1 ) );
+ Integer optionComboId = Integer.parseInt( identifierMatcher.group( 2 ) );
+
+ String dataValue = dataValues.get( dataElementId + SEPARATOR + optionComboId );
+
+ dataValue = dataValue != null ? dataValue : NULL_REPLACEMENT;
+
+ inputMatcher.appendReplacement( buffer, dataValue );
+ }
+ else if ( indicatorMatcher.find() && indicatorMatcher.groupCount() > 0 )
+ {
+ Integer indicatorId = Integer.parseInt( indicatorMatcher.group( 1 ) );
+
+ String indicatorValue = indicatorValues.get( indicatorId );
+
+ indicatorValue = indicatorValue != null ? indicatorValue : NULL_REPLACEMENT;
+
+ inputMatcher.appendReplacement( buffer, indicatorValue );
+ }
+ }
+
+ inputMatcher.appendTail( buffer );
+
+ return buffer.toString();
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml 2011-07-21 03:29:35 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml 2011-08-25 08:52:40 +0000
@@ -337,13 +337,12 @@
</aop:aspect>
<aop:aspect ref="statementInterceptor">
- <aop:around pointcut="execution( * org.hisp.dhis.completeness.DataSetCompletenessService.exportDataSetCompleteness(..) )"
- method="intercept" />
- <aop:around pointcut="execution( * org.hisp.dhis.completeness.DataSetCompletenessService.getDataSetCompleteness(..) )"
- method="intercept" />
+ <aop:around pointcut="execution( * org.hisp.dhis.completeness.DataSetCompletenessService.exportDataSetCompleteness(..) )" method="intercept" />
+ <aop:around pointcut="execution( * org.hisp.dhis.completeness.DataSetCompletenessService.getDataSetCompleteness(..) )" method="intercept" />
<aop:around pointcut="execution( * org.hisp.dhis.chart.ChartService.getJFreeChart*(..) )" method="intercept" />
- <aop:around pointcut="execution( * org.hisp.dhis.datasetreport.DataSetReportService.getAggregatedValueMap(..) )"
- method="intercept" />
+ <aop:around pointcut="execution( * org.hisp.dhis.datasetreport.DataSetReportService.getCustomDataSetReport(..) )" method="intercept" />
+ <aop:around pointcut="execution( * org.hisp.dhis.datasetreport.DataSetReportService.getSectionDataSetReport(..) )" method="intercept" />
+ <aop:around pointcut="execution( * org.hisp.dhis.datasetreport.DataSetReportService.getDefaultDataSetReport(..) )" method="intercept" />
</aop:aspect>
</aop:config>