=== 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-01-19 11:57:37 +0000 +++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/synchronous/ExportPivotViewService.java 2011-03-22 17:29:14 +0000 @@ -48,7 +48,6 @@ import org.hisp.dhis.period.Period; import org.hisp.dhis.period.PeriodService; import org.hisp.dhis.period.PeriodType; -import org.hisp.dhis.period.YearlyPeriodType; import org.hisp.dhis.system.util.MathUtils; /** @@ -60,29 +59,21 @@ */ public class ExportPivotViewService { - private static final Log log = LogFactory.getLog( ExportPivotViewService.class ); // service can export either aggregated datavalues or aggregated indicator values public enum RequestType { - DATAVALUE, INDICATORVALUE }; - // service can export either monthly or yearly periods - public enum RequestPeriodType - { - - MONTHLY, YEARLY - }; - // precision to use when formatting double values public static int PRECISION = 5; // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- + private AggregatedDataValueService aggregatedDataValueService; public void setAggregatedDataValueService( AggregatedDataValueService aggregatedDataValueService ) @@ -104,13 +95,13 @@ this.periodService = periodService; } - public void execute( OutputStream out, RequestType requestType, RequestPeriodType requestPeriodType, + public void execute( OutputStream out, RequestType requestType, PeriodType periodType, Date startDate, Date endDate, int level, int root ) throws IOException { Writer writer = new BufferedWriter( new OutputStreamWriter( out ) ); - Collection periods = getPeriods( requestPeriodType, startDate, endDate ); + Collection periods = getPeriods( periodType, startDate, endDate ); if ( periods.isEmpty() ) { @@ -141,17 +132,17 @@ if ( requestType == RequestType.DATAVALUE ) { processDataValues( writer, rootOrgUnit, orgUnitLevel, periods ); - } else + } + else { processIndicatorValues( writer, rootOrgUnit, orgUnitLevel, periods ); } - } - public int count( RequestType requestType, RequestPeriodType requestPeriodType, + public int count( RequestType requestType, PeriodType periodType, Date startDate, Date endDate, int level, int root ) { - Collection periods = getPeriods( requestPeriodType, startDate, endDate ); + Collection periods = getPeriods( periodType, startDate, endDate ); if ( periods.isEmpty() ) { @@ -184,8 +175,6 @@ { return aggregatedDataValueService.countIndicatorValuesAtLevel( rootOrgUnit, orgUnitLevel, periods ); } - - } private void processDataValues( Writer writer, OrganisationUnit rootOrgUnit, OrganisationUnitLevel orgUnitLevel, Collection periods ) @@ -198,7 +187,6 @@ writer.write( "# period, orgunit, dataelement, catoptcombo, value\n" ); while ( adv != null ) { - // process adv .. int periodId = adv.getPeriodId(); String period = periodService.getPeriod( periodId ).getIsoDate(); @@ -212,10 +200,9 @@ } writer.flush(); - } - void processIndicatorValues( Writer writer, OrganisationUnit rootOrgUnit, OrganisationUnitLevel orgUnitLevel, Collection periods ) + private void processIndicatorValues( Writer writer, OrganisationUnit rootOrgUnit, OrganisationUnitLevel orgUnitLevel, Collection periods ) throws IOException { StoreIterator Iterator = aggregatedDataValueService.getAggregateIndicatorValuesAtLevel( rootOrgUnit, orgUnitLevel, periods ); @@ -223,9 +210,9 @@ AggregatedIndicatorValue aiv = Iterator.next(); writer.write( "# period, orgunit, indicator, factor, numerator, denominator\n" ); + while ( aiv != null ) { - // process adv .. int periodId = aiv.getPeriodId(); String period = periodService.getPeriod( periodId ).getIsoDate(); @@ -240,31 +227,11 @@ } writer.flush(); - } - private Collection getPeriods( RequestPeriodType requestPeriodType, Date startDate, Date endDate ) + private Collection getPeriods( PeriodType periodType, Date startDate, Date endDate ) { - Collection periods; - PeriodType periodType; - - switch ( requestPeriodType ) - { - case MONTHLY: - periodType = new MonthlyPeriodType(); - break; - case YEARLY: - periodType = new YearlyPeriodType(); - break; - default: - // shouldn't happen - log and quietly default to monthly - log.warn( "Unsupported period type: " + requestPeriodType ); - periodType = new MonthlyPeriodType(); - } - - periods = periodService.getIntersectingPeriodsByPeriodType( periodType, startDate, endDate ); - - return periods; + periodType = periodType != null ? periodType : new MonthlyPeriodType(); // Fall back to monthly + return periodService.getIntersectingPeriodsByPeriodType( periodType, startDate, endDate ); } - } === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/exp/ExportDataMartAction.java' --- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/exp/ExportDataMartAction.java 2011-03-22 13:57:39 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/exp/ExportDataMartAction.java 2011-03-22 17:29:14 +0000 @@ -44,12 +44,12 @@ import org.apache.struts2.ServletActionContext; import org.hisp.dhis.importexport.synchronous.ExportPivotViewService; import org.hisp.dhis.importexport.synchronous.ExportPivotViewService.RequestType; +import org.hisp.dhis.period.PeriodType; import org.hisp.dhis.system.util.DateUtils; import org.hisp.dhis.system.util.StreamUtils; import org.hisp.dhis.user.CurrentUserService; import com.opensymphony.xwork2.Action; -import org.hisp.dhis.importexport.synchronous.ExportPivotViewService.RequestPeriodType; /** * @author Bob Jolliffe @@ -145,11 +145,11 @@ this.requestType = requestType; } - private RequestPeriodType periodType; + private String periodType; - public void setPeriodType( RequestPeriodType requestType ) + public void setPeriodType( String periodType ) { - this.periodType = requestType; + this.periodType = periodType; } // ------------------------------------------------------------------------- @@ -228,11 +228,13 @@ SimpleDateFormat format = new SimpleDateFormat( "_yyyy_MM_dd_HHmm_ss" ); String fileName = requestType + format.format(Calendar.getInstance().getTime()) + ".csv.gz"; + PeriodType pType = PeriodType.getPeriodTypeByName( periodType ); + // prepare to write output OutputStream out = null; // how many rows do we expect - int count = exportPivotViewService.count( requestType, periodType, start, end, + int count = exportPivotViewService.count( requestType, pType, start, end, dataSourceLevel, dataSourceRoot); response.setContentType( "application/gzip"); @@ -245,7 +247,7 @@ try { out = new GZIPOutputStream(response.getOutputStream(), GZIPBUFFER); - exportPivotViewService.execute(out, requestType, periodType, start, end, + exportPivotViewService.execute(out, requestType, pType, start, end, dataSourceLevel, dataSourceRoot); } finally === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml' --- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml 2011-03-22 13:57:39 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml 2011-03-22 17:29:14 +0000 @@ -382,36 +382,48 @@ F_SCHEDULING_ADMIN - - - - + + DATAVALUE - MONTHLY + Monthly + + + + + + DATAVALUE + Quarterly DATAVALUE - YEARLY + Yearly INDICATORVALUE - MONTHLY + Monthly + + + + + + INDICATORVALUE + Quarterly INDICATORVALUE - YEARLY + Yearly