dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #11131
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3129: Moved exportdatamart actions to standard dhis-web-reporting namespace. Implemented quarterly data...
------------------------------------------------------------
revno: 3129
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-03-22 18:29:14 +0100
message:
Moved exportdatamart actions to standard dhis-web-reporting namespace. Implemented quarterly datavalue/indicatorvalue exports.
modified:
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/synchronous/ExportPivotViewService.java
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/resources/struts.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-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<Period> periods = getPeriods( requestPeriodType, startDate, endDate );
+ Collection<Period> 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<Period> periods = getPeriods( requestPeriodType, startDate, endDate );
+ Collection<Period> 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<Period> 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<Period> periods )
+ private void processIndicatorValues( Writer writer, OrganisationUnit rootOrgUnit, OrganisationUnitLevel orgUnitLevel, Collection<Period> periods )
throws IOException
{
StoreIterator<AggregatedIndicatorValue> 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<Period> getPeriods( RequestPeriodType requestPeriodType, Date startDate, Date endDate )
+ private Collection<Period> getPeriods( PeriodType periodType, Date startDate, Date endDate )
{
- Collection<Period> 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 @@
<param name="requiredAuthorities">F_SCHEDULING_ADMIN</param>
</action>
- </package>
-
- <package name="dhis-web-exportdatamart" extends="dhis-web-commons" namespace="/dhis-web-exportdatamart">
-
+ <!-- Export -->
+
<action name="monthlyDataValues" class="org.hisp.dhis.reporting.exp.ExportDataMartAction">
<result name="success" type="outputStreamResult" />
<result name="client-error" type="httpheader" />
<param name="requestType">DATAVALUE</param>
- <param name="periodType">MONTHLY</param>
+ <param name="periodType">Monthly</param>
+ </action>
+
+ <action name="quarterlyDataValues" class="org.hisp.dhis.reporting.exp.ExportDataMartAction">
+ <result name="success" type="outputStreamResult" />
+ <result name="client-error" type="httpheader" />
+ <param name="requestType">DATAVALUE</param>
+ <param name="periodType">Quarterly</param>
</action>
<action name="yearlyDataValues" class="org.hisp.dhis.reporting.exp.ExportDataMartAction">
<result name="success" type="outputStreamResult" />
<result name="client-error" type="httpheader" />
<param name="requestType">DATAVALUE</param>
- <param name="periodType">YEARLY</param>
+ <param name="periodType">Yearly</param>
</action>
<action name="monthlyIndicatorValues" class="org.hisp.dhis.reporting.exp.ExportDataMartAction">
<result name="success" type="outputStreamResult" />
<result name="client-error" type="httpheader" />
<param name="requestType">INDICATORVALUE</param>
- <param name="periodType">MONTHLY</param>
+ <param name="periodType">Monthly</param>
+ </action>
+
+ <action name="quarterlyIndicatorValues" class="org.hisp.dhis.reporting.exp.ExportDataMartAction">
+ <result name="success" type="outputStreamResult" />
+ <result name="client-error" type="httpheader" />
+ <param name="requestType">INDICATORVALUE</param>
+ <param name="periodType">Quarterly</param>
</action>
<action name="yearlyIndicatorValues" class="org.hisp.dhis.reporting.exp.ExportDataMartAction">
<result name="success" type="outputStreamResult" />
<result name="client-error" type="httpheader" />
<param name="requestType">INDICATORVALUE</param>
- <param name="periodType">YEARLY</param>
+ <param name="periodType">Yearly</param>
</action>
</package>