← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5428: minor refactor in defaultchartservice

 

------------------------------------------------------------
revno: 5428
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-12-15 11:32:22 +0100
message:
  minor refactor in defaultchartservice
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/ChartService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.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/chart/ChartService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/ChartService.java	2011-12-06 17:41:41 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/ChartService.java	2011-12-15 10:32:22 +0000
@@ -27,10 +27,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
 import org.hisp.dhis.dataset.DataSet;
@@ -42,6 +38,10 @@
 import org.jfree.chart.axis.CategoryLabelPositions;
 import org.jfree.chart.plot.PlotOrientation;
 
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
 /**
  * @author Lars Helge Overland
  */
@@ -54,19 +54,19 @@
     JFreeChart getJFreeChart( int id, I18nFormat format );
 
     JFreeChart getJFreeChart( Chart chart, I18nFormat format );
-    
+
     JFreeChart getJFreePeriodChart( Indicator indicator, OrganisationUnit unit, boolean title, I18nFormat format );
 
     JFreeChart getJFreeOrganisationUnitChart( Indicator indicator, OrganisationUnit parent, boolean title, I18nFormat format );
 
     JFreeChart getJFreeChart( List<Indicator> indicators, List<DataElement> dataElements, List<DataSet> dataSets, List<Period> periods,
-        List<OrganisationUnit> organisationUnits, String dimension, boolean regression, I18nFormat format );
+                              List<OrganisationUnit> organisationUnits, String dimension, boolean regression, I18nFormat format );
 
     JFreeChart getJFreeChart( String name, PlotOrientation orientation, CategoryLabelPositions labelPositions,
-        Map<String, Double> categoryValues );
+                              Map<String, Double> categoryValues );
 
     JFreeChart getJFreeChartHistory( DataElement dataElement, DataElementCategoryOptionCombo categoryOptionCombo,
-        Period lastPeriod, OrganisationUnit organisationUnit, int historyLength, I18nFormat format );
+                                     Period lastPeriod, OrganisationUnit organisationUnit, int historyLength, I18nFormat format );
 
     int saveChart( Chart chart );
 

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java	2011-12-09 20:04:48 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java	2011-12-15 10:32:22 +0000
@@ -27,40 +27,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.hisp.dhis.chart.Chart.DIMENSION_COMPLETENESS_PERIOD;
-import static org.hisp.dhis.chart.Chart.DIMENSION_DATAELEMENT_PERIOD;
-import static org.hisp.dhis.chart.Chart.DIMENSION_INDICATOR_PERIOD;
-import static org.hisp.dhis.chart.Chart.DIMENSION_ORGANISATIONUNIT_COMPLETENESS;
-import static org.hisp.dhis.chart.Chart.DIMENSION_ORGANISATIONUNIT_DATAELEMENT;
-import static org.hisp.dhis.chart.Chart.DIMENSION_ORGANISATIONUNIT_INDICATOR;
-import static org.hisp.dhis.chart.Chart.DIMENSION_PERIOD_COMPLETENESS;
-import static org.hisp.dhis.chart.Chart.DIMENSION_PERIOD_DATAELEMENT;
-import static org.hisp.dhis.chart.Chart.DIMENSION_PERIOD_INDICATOR;
-import static org.hisp.dhis.chart.Chart.SIZE_NORMAL;
-import static org.hisp.dhis.chart.Chart.TYPE_BAR;
-import static org.hisp.dhis.chart.Chart.TYPE_BAR3D;
-import static org.hisp.dhis.chart.Chart.TYPE_LINE;
-import static org.hisp.dhis.chart.Chart.TYPE_LINE3D;
-import static org.hisp.dhis.chart.Chart.TYPE_PIE;
-import static org.hisp.dhis.chart.Chart.TYPE_PIE3D;
-import static org.hisp.dhis.chart.Chart.TYPE_STACKED_BAR;
-import static org.hisp.dhis.chart.Chart.TYPE_STACKED_BAR3D;
-import static org.hisp.dhis.options.SystemSettingManager.AGGREGATION_STRATEGY_REAL_TIME;
-import static org.hisp.dhis.options.SystemSettingManager.DEFAULT_AGGREGATION_STRATEGY;
-import static org.hisp.dhis.options.SystemSettingManager.KEY_AGGREGATION_STRATEGY;
-import static org.hisp.dhis.system.util.ConversionUtils.getArray;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Font;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
 import org.apache.commons.math.MathException;
 import org.apache.commons.math.analysis.SplineInterpolator;
 import org.apache.commons.math.analysis.UnivariateRealFunction;
@@ -101,18 +67,8 @@
 import org.jfree.chart.axis.NumberAxis;
 import org.jfree.chart.axis.ValueAxis;
 import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
-import org.jfree.chart.plot.CategoryPlot;
-import org.jfree.chart.plot.DatasetRenderingOrder;
-import org.jfree.chart.plot.Marker;
-import org.jfree.chart.plot.MultiplePiePlot;
-import org.jfree.chart.plot.PiePlot;
-import org.jfree.chart.plot.PlotOrientation;
-import org.jfree.chart.plot.ValueMarker;
-import org.jfree.chart.renderer.category.BarRenderer;
-import org.jfree.chart.renderer.category.BarRenderer3D;
-import org.jfree.chart.renderer.category.CategoryItemRenderer;
-import org.jfree.chart.renderer.category.LineAndShapeRenderer;
-import org.jfree.chart.renderer.category.LineRenderer3D;
+import org.jfree.chart.plot.*;
+import org.jfree.chart.renderer.category.*;
 import org.jfree.chart.title.TextTitle;
 import org.jfree.data.category.CategoryDataset;
 import org.jfree.data.category.DefaultCategoryDataset;
@@ -120,6 +76,15 @@
 import org.jfree.util.TableOrder;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.awt.*;
+import java.util.*;
+import java.util.List;
+import java.util.Map.Entry;
+
+import static org.hisp.dhis.chart.Chart.*;
+import static org.hisp.dhis.options.SystemSettingManager.*;
+import static org.hisp.dhis.system.util.ConversionUtils.getArray;
+
 /**
  * @author Lars Helge Overland
  * @version $Id$
@@ -830,13 +795,44 @@
         return multiplePieChart;
     }
 
+    private boolean isIndicatorChart( Chart chart )
+    {
+        return chart.isDimension( DIMENSION_INDICATOR_PERIOD )
+            || chart.isDimension( DIMENSION_ORGANISATIONUNIT_INDICATOR )
+            || chart.isDimension( DIMENSION_PERIOD_INDICATOR );
+    }
+
+    private boolean isDataElementChart( Chart chart )
+    {
+        return chart.isDimension( DIMENSION_DATAELEMENT_PERIOD )
+            || chart.isDimension( DIMENSION_ORGANISATIONUNIT_DATAELEMENT )
+            || chart.isDimension( DIMENSION_PERIOD_DATAELEMENT );
+    }
+
+    private boolean isCompletenessChart( Chart chart )
+    {
+        return chart.isDimension( DIMENSION_COMPLETENESS_PERIOD )
+            || chart.isDimension( DIMENSION_ORGANISATIONUNIT_COMPLETENESS )
+            || chart.isDimension( DIMENSION_PERIOD_COMPLETENESS );
+    }
+
+    private boolean hasPeriodDimension( Chart chart )
+    {
+        return chart.isDimension( DIMENSION_PERIOD_INDICATOR )
+            || chart.isDimension( DIMENSION_INDICATOR_PERIOD )
+            || chart.isDimension( DIMENSION_PERIOD_DATAELEMENT )
+            || chart.isDimension( DIMENSION_DATAELEMENT_PERIOD )
+            || chart.isDimension( DIMENSION_PERIOD_COMPLETENESS )
+            || chart.isDimension( DIMENSION_COMPLETENESS_PERIOD );
+    }
+
     /**
      * Returns a DefaultCategoryDataSet based on aggregated data for the chart.
      */
     private CategoryDataset[] getCategoryDataSet( Chart chart )
     {
-        String aggregationStrategy = (String) systemSettingManager.getSystemSetting( KEY_AGGREGATION_STRATEGY,
-            DEFAULT_AGGREGATION_STRATEGY );
+        boolean realTimeAggregation = systemSettingManager.getSystemSetting( KEY_AGGREGATION_STRATEGY,
+            DEFAULT_AGGREGATION_STRATEGY ).equals( AGGREGATION_STRATEGY_REAL_TIME );
 
         final DefaultCategoryDataset regularDataSet = new DefaultCategoryDataset();
         final DefaultCategoryDataset regressionDataSet = new DefaultCategoryDataset();
@@ -850,25 +846,17 @@
             List<DataElement> dataElements = chart.getDataElements();
             List<DataSet> dataSets = chart.getDataSets();
 
-            boolean isIndicatorChart = chart.isDimension( DIMENSION_INDICATOR_PERIOD )
-                || chart.isDimension( DIMENSION_ORGANISATIONUNIT_INDICATOR )
-                || chart.isDimension( DIMENSION_PERIOD_INDICATOR );
-
-            boolean isDataElementChart = chart.isDimension( DIMENSION_DATAELEMENT_PERIOD )
-                || chart.isDimension( DIMENSION_ORGANISATIONUNIT_DATAELEMENT )
-                || chart.isDimension( DIMENSION_PERIOD_DATAELEMENT );
-
-            boolean isCompletenessChart = chart.isDimension( DIMENSION_COMPLETENESS_PERIOD )
-                || chart.isDimension( DIMENSION_ORGANISATIONUNIT_COMPLETENESS )
-                || chart.isDimension( DIMENSION_PERIOD_COMPLETENESS );
+            boolean indicatorChart = isIndicatorChart( chart );
+            boolean dataElementChart = isDataElementChart( chart );
+            boolean completenessChart = isCompletenessChart( chart );
 
             int loopSize = indicators.size();
 
-            if ( isDataElementChart )
+            if ( dataElementChart )
             {
                 loopSize = dataElements.size();
             }
-            else if ( isCompletenessChart )
+            else if ( completenessChart )
             {
                 loopSize = dataSets.size();
             }
@@ -881,25 +869,20 @@
 
                 String shortName = null;
 
-                if ( isIndicatorChart )
+                if ( indicatorChart )
                 {
                     shortName = indicators.get( i ).getShortName();
                 }
-                else if ( isDataElementChart )
+                else if ( dataElementChart )
                 {
                     shortName = dataElements.get( i ).getShortName();
                 }
-                else if ( isCompletenessChart )
+                else if ( completenessChart )
                 {
                     shortName = dataSets.get( i ).getShortName();
                 }
 
-                if ( chart.isDimension( DIMENSION_PERIOD_INDICATOR )
-                    || chart.isDimension( DIMENSION_INDICATOR_PERIOD )
-                    || chart.isDimension( DIMENSION_PERIOD_DATAELEMENT )
-                    || chart.isDimension( DIMENSION_DATAELEMENT_PERIOD )
-                    || chart.isDimension( DIMENSION_PERIOD_COMPLETENESS )
-                    || chart.isDimension( DIMENSION_COMPLETENESS_PERIOD ) )
+                if ( hasPeriodDimension( chart ) )
                 {
                     // ---------------------------------------------------------
                     // Regular dataset
@@ -909,21 +892,19 @@
                     {
                         Double value = null;
 
-                        if ( isIndicatorChart )
-                        {
-                            value = aggregationStrategy.equals( AGGREGATION_STRATEGY_REAL_TIME ) ? aggregationService
-                                .getAggregatedIndicatorValue( indicators.get( i ), period.getStartDate(),
-                                    period.getEndDate(), selectedOrganisationUnit ) : aggregatedDataValueService
-                                .getAggregatedValue( indicators.get( i ), period, selectedOrganisationUnit );
-                        }
-                        else if ( isDataElementChart )
-                        {
-                            value = aggregationStrategy.equals( AGGREGATION_STRATEGY_REAL_TIME ) ? aggregationService
-                                .getAggregatedDataValue( dataElements.get( i ), null, period.getStartDate(),
-                                    period.getEndDate(), selectedOrganisationUnit ) : aggregatedDataValueService
-                                .getAggregatedValue( dataElements.get( i ), period, selectedOrganisationUnit );
-                        }
-                        else if ( isCompletenessChart )
+                        if ( indicatorChart )
+                        {
+                            value = realTimeAggregation ?
+                                aggregationService.getAggregatedIndicatorValue( indicators.get( i ), period.getStartDate(), period.getEndDate(), selectedOrganisationUnit ) :
+                                aggregatedDataValueService.getAggregatedValue( indicators.get( i ), period, selectedOrganisationUnit );
+                        }
+                        else if ( dataElementChart )
+                        {
+                            value = realTimeAggregation ?
+                                aggregationService.getAggregatedDataValue( dataElements.get( i ), null, period.getStartDate(), period.getEndDate(), selectedOrganisationUnit ) :
+                                aggregatedDataValueService.getAggregatedValue( dataElements.get( i ), period, selectedOrganisationUnit );
+                        }
+                        else if ( completenessChart )
                         {
                             List<DataSetCompletenessResult> dataSetCompleteness = new ArrayList<DataSetCompletenessResult>(
                                 dataSetCompletenessService.getDataSetCompleteness( period.getId(),
@@ -998,21 +979,19 @@
                     {
                         Double value = null;
 
-                        if ( isIndicatorChart )
-                        {
-                            value = aggregationStrategy.equals( AGGREGATION_STRATEGY_REAL_TIME ) ? aggregationService
-                                .getAggregatedIndicatorValue( indicators.get( i ), selectedPeriod.getStartDate(),
-                                    selectedPeriod.getEndDate(), unit ) : aggregatedDataValueService
-                                .getAggregatedValue( indicators.get( i ), selectedPeriod, unit );
-                        }
-                        else if ( isDataElementChart )
-                        {
-                            value = aggregationStrategy.equals( AGGREGATION_STRATEGY_REAL_TIME ) ? aggregationService
-                                .getAggregatedDataValue( dataElements.get( i ), null, selectedPeriod.getStartDate(),
-                                    selectedPeriod.getEndDate(), unit ) : aggregatedDataValueService
-                                .getAggregatedValue( dataElements.get( i ), selectedPeriod, unit );
-                        }
-                        else if ( isCompletenessChart )
+                        if ( indicatorChart )
+                        {
+                            value = realTimeAggregation ?
+                                aggregationService.getAggregatedIndicatorValue( indicators.get( i ), selectedPeriod.getStartDate(), selectedPeriod.getEndDate(), unit ) :
+                                aggregatedDataValueService.getAggregatedValue( indicators.get( i ), selectedPeriod, unit );
+                        }
+                        else if ( dataElementChart )
+                        {
+                            value = realTimeAggregation ?
+                                aggregationService.getAggregatedDataValue( dataElements.get( i ), null, selectedPeriod.getStartDate(), selectedPeriod.getEndDate(), unit ) :
+                                aggregatedDataValueService.getAggregatedValue( dataElements.get( i ), selectedPeriod, unit );
+                        }
+                        else if ( completenessChart )
                         {
                             List<DataSetCompletenessResult> dataSetCompleteness = new ArrayList<DataSetCompletenessResult>(
                                 dataSetCompletenessService.getDataSetCompleteness( selectedPeriod.getId(),

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartController.java	2011-12-13 16:47:13 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartController.java	2011-12-15 10:32:22 +0000
@@ -27,16 +27,23 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.aggregation.AggregatedDataValueService;
+import org.hisp.dhis.aggregation.AggregationService;
 import org.hisp.dhis.api.utils.IdentifiableObjectParams;
 import org.hisp.dhis.api.utils.WebLinkPopulator;
 import org.hisp.dhis.chart.Chart;
 import org.hisp.dhis.chart.ChartService;
 import org.hisp.dhis.chart.Charts;
+import org.hisp.dhis.completeness.DataSetCompletenessService;
+import org.hisp.dhis.datavalue.DataValueService;
 import org.hisp.dhis.i18n.I18nManager;
 import org.hisp.dhis.i18n.I18nManagerException;
+import org.hisp.dhis.options.SystemSettingManager;
+import org.hisp.dhis.period.PeriodService;
 import org.jfree.chart.ChartUtilities;
 import org.jfree.chart.JFreeChart;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.http.HttpStatus;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
@@ -62,6 +69,25 @@
     private ChartService chartService;
 
     @Autowired
+    private AggregatedDataValueService aggregatedDataValueService;
+
+    @Autowired
+    private AggregationService aggregationService;
+
+    @Autowired
+    private DataValueService dataValueService;
+
+    @Autowired
+    private PeriodService periodService;
+
+    @Autowired
+    @Qualifier( "registrationDataCompletenessService" )
+    private DataSetCompletenessService dataSetCompletenessService;
+
+    @Autowired
+    private SystemSettingManager systemSettingManager;
+
+    @Autowired
     private I18nManager i18nManager;
 
     //-------------------------------------------------------------------------------------------------------
@@ -101,8 +127,15 @@
         return "chart";
     }
 
-    @RequestMapping( value = "/{uid}.png", method = RequestMethod.GET )
-    public void getChartPNG( @PathVariable( "uid" ) String uid, @RequestParam( value = "width", defaultValue = "700", required = false ) int width,
+    @RequestMapping( value = "/{uid}/data", method = RequestMethod.GET )
+    public void getChartData( @PathVariable( "uid" ) String uid, HttpServletResponse response ) throws IOException, I18nManagerException
+    {
+        Chart chart = chartService.getChart( uid );
+    }
+
+    @RequestMapping( value = "/{uid}/data.png", method = RequestMethod.GET )
+    public void getChartPng( @PathVariable( "uid" ) String uid,
+                             @RequestParam( value = "width", defaultValue = "700", required = false ) int width,
                              @RequestParam( value = "height", defaultValue = "500", required = false ) int height,
                              HttpServletResponse response ) throws IOException, I18nManagerException
     {
@@ -112,8 +145,9 @@
         ChartUtilities.writeChartAsPNG( response.getOutputStream(), chart, width, height );
     }
 
-    @RequestMapping( value = "/{uid}.jpg", method = RequestMethod.GET )
-    public void getChartJPG( @PathVariable( "uid" ) String uid, @RequestParam( value = "width", defaultValue = "700", required = false ) int width,
+    @RequestMapping( value = "/{uid}/data.jpg", method = RequestMethod.GET )
+    public void getChartJpg( @PathVariable( "uid" ) String uid,
+                             @RequestParam( value = "width", defaultValue = "700", required = false ) int width,
                              @RequestParam( value = "height", defaultValue = "500", required = false ) int height,
                              HttpServletResponse response ) throws IOException, I18nManagerException
     {

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportController.java	2011-12-14 16:53:56 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportController.java	2011-12-15 10:32:22 +0000
@@ -27,12 +27,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.ArrayList;
-import java.util.Date;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
 import org.hisp.dhis.api.utils.IdentifiableObjectParams;
 import org.hisp.dhis.api.utils.WebLinkPopulator;
 import org.hisp.dhis.i18n.I18nManager;
@@ -51,6 +45,11 @@
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.ArrayList;
+import java.util.Date;
+
 @Controller
 @RequestMapping( value = ReportController.RESOURCE_PATH )
 public class ReportController
@@ -97,7 +96,7 @@
 
     @RequestMapping( value = "/{uid}", method = RequestMethod.GET )
     public String getReport( @PathVariable( "uid" ) String uid, IdentifiableObjectParams params, Model model,
-        HttpServletRequest request )
+                             HttpServletRequest request )
     {
         Report report = reportService.getReport( uid );
 
@@ -112,10 +111,10 @@
         return "report";
     }
 
-    @RequestMapping( value = {"/{uid}/data","/{uid}/data.pdf"}, method = RequestMethod.GET )
+    @RequestMapping( value = {"/{uid}/data", "/{uid}/data.pdf"}, method = RequestMethod.GET )
     public void getReportAsPdf( @PathVariable( "uid" ) String uid,
-        @RequestParam( value = "organisationUnit", required = false ) String organisationUnitUid,
-        @RequestParam( value = "period", required = false ) String period, HttpServletResponse response )
+                                @RequestParam( value = "organisationUnit", required = false ) String organisationUnitUid,
+                                @RequestParam( value = "period", required = false ) String period, HttpServletResponse response )
         throws Exception
     {
         getReport( uid, organisationUnitUid, period, response, "pdf", ContextUtils.CONTENT_TYPE_PDF, false );
@@ -123,8 +122,8 @@
 
     @RequestMapping( value = "/{uid}/data.xls", method = RequestMethod.GET )
     public void getReportAsXls( @PathVariable( "uid" ) String uid,
-        @RequestParam( value = "organisationUnit", required = false ) String organisationUnitUid,
-        @RequestParam( value = "period", required = false ) String period, HttpServletResponse response )
+                                @RequestParam( value = "organisationUnit", required = false ) String organisationUnitUid,
+                                @RequestParam( value = "period", required = false ) String period, HttpServletResponse response )
         throws Exception
     {
         getReport( uid, organisationUnitUid, period, response, "xls", ContextUtils.CONTENT_TYPE_EXCEL, true );
@@ -134,8 +133,8 @@
     // Supportive methods
     // -------------------------------------------------------------------------------------------------------
 
-    private void getReport( String uid, String organisationUnitUid, String period, 
-        HttpServletResponse response, String type, String contentType, boolean attachment ) throws Exception
+    private void getReport( String uid, String organisationUnitUid, String period,
+                            HttpServletResponse response, String type, String contentType, boolean attachment ) throws Exception
     {
         Report report = reportService.getReport( uid );
 
@@ -149,7 +148,7 @@
 
         reportService.renderReport( response.getOutputStream(), uid, date, organisationUnitUid, type,
             i18nManager.getI18nFormat() );
-        
+
         String filename = CodecUtils.filenameEncode( report.getName() ) + "." + type;
         ContextUtils.configureResponse( response, contentType, true, filename, attachment );
     }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.java	2011-12-14 16:53:56 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.java	2011-12-15 10:32:22 +0000
@@ -27,15 +27,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.hisp.dhis.system.util.CodecUtils.filenameEncode;
-
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Date;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
 import org.hisp.dhis.api.utils.IdentifiableObjectParams;
 import org.hisp.dhis.api.utils.WebLinkPopulator;
 import org.hisp.dhis.common.Grid;
@@ -52,11 +43,15 @@
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
 import org.springframework.web.HttpRequestMethodNotSupportedException;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Date;
+
+import static org.hisp.dhis.system.util.CodecUtils.filenameEncode;
 
 @Controller
 @RequestMapping( value = ReportTableController.RESOURCE_PATH )
@@ -125,7 +120,7 @@
                                       HttpServletResponse response ) throws Exception
     {
         ReportTable reportTable = reportTableService.getReportTable( uid );
-        
+
         if ( organisationUnitUid == null && reportTable.hasReportParams() && reportTable.getReportParams().isOrganisationUnitSet() )
         {
             organisationUnitUid = organisationUnitService.getRootOrganisationUnits().iterator().next().getUid();
@@ -147,14 +142,14 @@
                                    HttpServletResponse response ) throws Exception
     {
         ReportTable reportTable = reportTableService.getReportTable( uid );
-        
+
         if ( organisationUnitUid == null && reportTable.hasReportParams() && reportTable.getReportParams().isOrganisationUnitSet() )
         {
             organisationUnitUid = organisationUnitService.getRootOrganisationUnits().iterator().next().getUid();
         }
 
         Date date = period != null ? DateUtils.getMediumDate( period ) : new Date();
-        
+
         Grid grid = reportTableService.getReportTableGrid( uid, i18nManager.getI18nFormat(), date, organisationUnitUid );
 
         String filename = filenameEncode( grid.getTitle() ) + ".pdf";
@@ -170,7 +165,7 @@
                                    HttpServletResponse response ) throws Exception
     {
         ReportTable reportTable = reportTableService.getReportTable( uid );
-        
+
         if ( organisationUnitUid == null && reportTable.hasReportParams() && reportTable.getReportParams().isOrganisationUnitSet() )
         {
             organisationUnitUid = organisationUnitService.getRootOrganisationUnits().iterator().next().getUid();
@@ -193,7 +188,7 @@
                                    HttpServletResponse response ) throws Exception
     {
         ReportTable reportTable = reportTableService.getReportTable( uid );
-        
+
         if ( organisationUnitUid == null && reportTable.hasReportParams() && reportTable.getReportParams().isOrganisationUnitSet() )
         {
             organisationUnitUid = organisationUnitService.getRootOrganisationUnits().iterator().next().getUid();