=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Grid.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Grid.java 2013-02-19 16:12:47 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Grid.java 2013-03-04 10:30:59 +0000 @@ -77,12 +77,12 @@ /** * Returns map of meta-data. */ - Map getMetaData(); + Map getMetaData(); /** * Sets map of meta-data. */ - void setMetaData( Map metaData ); + void setMetaData( Map metaData ); /** * Adds a key-value pair to meta-data. @@ -244,6 +244,12 @@ Grid addCumulativeColumn( int columnIndex, boolean addHeader ); /** + * Substitutes the values in the meta columns with the mapped value in the + * meta-data map. + */ + Grid substituteMetaData(); + + /** * Adds a set of headers based on the column names of the given SQL result set. * * @param rs the result set. === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/organisationunit/hibernate/OrganisationUnit.hbm.xml' --- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/organisationunit/hibernate/OrganisationUnit.hbm.xml 2013-02-07 10:25:34 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/organisationunit/hibernate/OrganisationUnit.hbm.xml 2013-03-04 10:30:59 +0000 @@ -30,7 +30,6 @@ - === modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java' --- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java 2013-02-19 16:12:47 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java 2013-03-04 10:30:59 +0000 @@ -79,7 +79,7 @@ /** * A Map which can hold arbitrary meta-data. */ - private Map metaData; + private Map metaData; /** * A two dimensional List which simulates a grid where the first list @@ -108,7 +108,7 @@ public ListGrid() { headers = new ArrayList(); - metaData = new HashMap(); + metaData = new HashMap(); grid = new ArrayList>(); } @@ -219,12 +219,12 @@ @JsonProperty @JsonView( { DetailedView.class } ) - public Map getMetaData() + public Map getMetaData() { return metaData; } - public void setMetaData( Map metaData ) + public void setMetaData( Map metaData ) { this.metaData = metaData; } @@ -340,7 +340,7 @@ return grid.get( rowIndex ).get( columnIndex ); } - + public Grid addColumn( List columnValues ) { verifyGridState(); @@ -530,6 +530,36 @@ return this; } + + public Grid substituteMetaData() + { + if ( metaData == null || headers == null || headers.isEmpty() ) + { + return this; + } + + for ( int colIndex = 0; colIndex < headers.size(); colIndex++ ) + { + if ( headers.get( colIndex ).isMeta() ) + { + List col = getColumn( colIndex ); + + for ( int rowIndex = 0; rowIndex < col.size(); rowIndex++ ) + { + Object object = col.get( rowIndex ); + + Object meta = metaData.get( object ); + + if ( meta != null ) + { + grid.get( rowIndex ).set( colIndex, meta ); + } + } + } + } + + return this; + } // ------------------------------------------------------------------------- // JRDataSource implementation === modified file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/grid/GridTest.java' --- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/grid/GridTest.java 2012-12-21 12:59:39 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/grid/GridTest.java 2013-03-04 10:30:59 +0000 @@ -34,7 +34,9 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.hisp.dhis.common.Grid; import org.hisp.dhis.common.GridHeader; @@ -58,8 +60,8 @@ { grid = new ListGrid(); - headerA = new GridHeader( "ColA", "colA", String.class.getName(), false, false ); - headerB = new GridHeader( "ColB", "colB", String.class.getName(), false, false ); + headerA = new GridHeader( "ColA", "colA", String.class.getName(), false, true ); + headerB = new GridHeader( "ColB", "colB", String.class.getName(), false, true ); headerC = new GridHeader( "ColC", "colC", String.class.getName(), true, false ); grid.addHeader( headerA ); @@ -88,6 +90,30 @@ } @Test + public void testSubstituteMetaData() + { + Map metaData = new HashMap(); + metaData.put( 11, "Eleven" ); + metaData.put( 12, "Twelve" ); + metaData.put( 21, "TwentyOne" ); + metaData.put( 22, "TwentyTwo" ); + + grid.setMetaData( metaData ); + + assertEquals( 11, grid.getValue( 0, 0 ) ); + assertEquals( 12, grid.getValue( 0, 1 ) ); + assertEquals( 21, grid.getValue( 1, 0 ) ); + assertEquals( 22, grid.getValue( 1, 1 ) ); + + grid.substituteMetaData(); + + assertEquals( "Eleven", grid.getValue( 0, 0 ) ); + assertEquals( "Twelve", grid.getValue( 0, 1 ) ); + assertEquals( "TwentyOne", grid.getValue( 1, 0 ) ); + assertEquals( "TwentyTwo", grid.getValue( 1, 1 ) ); + } + + @Test public void testGetHeight() { assertEquals( 4, grid.getHeight() ); === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AnalyticsController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AnalyticsController.java 2013-02-05 08:50:26 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AnalyticsController.java 2013-03-04 10:30:59 +0000 @@ -114,7 +114,7 @@ contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_CSV, CacheStrategy.RESPECT_SYSTEM_SETTING ); Grid grid = analyticsService.getAggregatedDataValues( params ); - GridUtils.toCsv( grid, response.getOutputStream() ); + GridUtils.toCsv( grid.substituteMetaData(), response.getOutputStream() ); } @RequestMapping( value = RESOURCE_PATH + ".html", method = RequestMethod.GET ) @@ -130,7 +130,23 @@ contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_HTML, CacheStrategy.RESPECT_SYSTEM_SETTING ); Grid grid = analyticsService.getAggregatedDataValues( params ); - GridUtils.toHtml( grid, response.getWriter() ); + GridUtils.toHtml( grid.substituteMetaData(), response.getWriter() ); + } + + @RequestMapping( value = RESOURCE_PATH + ".xls", method = RequestMethod.GET ) + public void getXls( + @RequestParam Set dimension, + @RequestParam(required = false) Set filter, + @RequestParam(required = false) AggregationType aggregationType, + @RequestParam(required = false) String measureCriteria, + Model model, + HttpServletResponse response ) throws Exception + { + DataQueryParams params = analyticsService.getFromUrl( dimension, filter, aggregationType, measureCriteria, i18nManager.getI18nFormat() ); + + contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_EXCEL, CacheStrategy.RESPECT_SYSTEM_SETTING ); + Grid grid = analyticsService.getAggregatedDataValues( params ); + GridUtils.toXls( grid.substituteMetaData(), response.getOutputStream() ); } // -------------------------------------------------------------------------