dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #14441
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4907: Improved performance in ExportPivotViewService
------------------------------------------------------------
revno: 4907
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-10-12 12:32:57 +0200
message:
Improved performance in ExportPivotViewService
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.java
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/synchronous/ExportPivotViewService.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/period/Period.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.java 2011-09-23 22:39:54 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.java 2011-10-12 10:32:57 +0000
@@ -109,7 +109,7 @@
*/
public String getIsoDate()
{
- return periodType.getIsoDate(this);
+ return periodType.getIsoDate( this );
}
/**
=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/synchronous/ExportPivotViewService.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/synchronous/ExportPivotViewService.java 2011-10-12 09:59:23 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/synchronous/ExportPivotViewService.java 2011-10-12 10:32:57 +0000
@@ -34,6 +34,8 @@
import java.io.Writer;
import java.util.Collection;
import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -186,11 +188,13 @@
private void processDataValues( Writer writer, OrganisationUnit rootOrgUnit, OrganisationUnitLevel orgUnitLevel, Collection<Period> periods )
throws IOException
{
- StoreIterator<AggregatedDataValue> Iterator = aggregatedDataValueService.getAggregateDataValuesAtLevel( rootOrgUnit, orgUnitLevel, periods );
+ Map<Integer, String> periodIdIsoMap = getPeriodIdIsoMap( periods );
+
+ StoreIterator<AggregatedDataValue> iterator = aggregatedDataValueService.getAggregateDataValuesAtLevel( rootOrgUnit, orgUnitLevel, periods );
try
{
- AggregatedDataValue adv = Iterator.next();
+ AggregatedDataValue adv = iterator.next();
writer.write( "# period, orgunit, dataelement, catoptcombo, value\n" );
@@ -198,10 +202,7 @@
while ( adv != null )
{
- int periodId = adv.getPeriodId();
- String period = periodService.getPeriod( periodId ).getIsoDate();
-
- writer.write( "'" + period + "'," );
+ writer.write( "'" + periodIdIsoMap.get( adv.getPeriodId() ) + "'," );
writer.write( adv.getOrganisationUnitId() + "," );
writer.write( adv.getDataElementId() + "," );
writer.write( adv.getCategoryOptionComboId() + "," );
@@ -215,12 +216,12 @@
writer.flush();
}
- adv = Iterator.next();
+ adv = iterator.next();
}
- } catch ( IOException ex )
+ }
+ catch ( IOException ex )
{
- // whatever happens release the store iterator
- Iterator.close();
+ iterator.close();
throw ( ex );
}
@@ -230,11 +231,13 @@
private void processIndicatorValues( Writer writer, OrganisationUnit rootOrgUnit, OrganisationUnitLevel orgUnitLevel, Collection<Period> periods )
throws IOException
{
- StoreIterator<AggregatedIndicatorValue> Iterator = aggregatedDataValueService.getAggregateIndicatorValuesAtLevel( rootOrgUnit, orgUnitLevel, periods );
+ Map<Integer, String> periodIdIsoMap = getPeriodIdIsoMap( periods );
+
+ StoreIterator<AggregatedIndicatorValue> iterator = aggregatedDataValueService.getAggregateIndicatorValuesAtLevel( rootOrgUnit, orgUnitLevel, periods );
try
{
- AggregatedIndicatorValue aiv = Iterator.next();
+ AggregatedIndicatorValue aiv = iterator.next();
writer.write( "# period, orgunit, indicator, factor, numerator, denominator\n" );
@@ -242,10 +245,7 @@
while ( aiv != null )
{
- int periodId = aiv.getPeriodId();
- String period = periodService.getPeriod( periodId ).getIsoDate();
-
- writer.write( "'" + period + "'," );
+ writer.write( "'" + periodIdIsoMap.get( aiv.getPeriodId() ) + "'," );
writer.write( aiv.getOrganisationUnitId() + "," );
writer.write( aiv.getIndicatorId() + "," );
writer.write( MathUtils.roundToString( aiv.getFactor(), PRECISION ) + "," );
@@ -260,16 +260,15 @@
writer.flush();
}
- aiv = Iterator.next();
+ aiv = iterator.next();
}
- } catch ( IOException ex )
+ }
+ catch ( IOException ex )
{
- // whatever happens release the store iterator
- Iterator.close();
+ iterator.close();
throw (ex);
}
-
writer.flush();
}
@@ -278,4 +277,16 @@
periodType = periodType != null ? periodType : new MonthlyPeriodType(); // Fall back to monthly
return periodService.getIntersectingPeriodsByPeriodType( periodType, startDate, endDate );
}
+
+ private Map<Integer, String> getPeriodIdIsoMap( Collection<Period> periods )
+ {
+ Map<Integer, String> map = new HashMap<Integer, String>();
+
+ for ( Period period : periods )
+ {
+ map.put( period.getId(), period.getIsoDate() );
+ }
+
+ return map;
+ }
}