=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapgeneration/MapGenerationService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapgeneration/MapGenerationService.java 2011-12-26 10:07:59 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapgeneration/MapGenerationService.java 2012-02-07 16:03:05 +0000 @@ -51,7 +51,7 @@ * Generate an image that represents this map. * * @param mapView the map view that will be rendered - * @return the rendered map image + * @return the rendered map image or null if there is no data for the map view. */ public BufferedImage generateMapImage( MapView mapView ); } === modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMapGenerationService.java' --- dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMapGenerationService.java 2011-12-26 10:07:59 +0000 +++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMapGenerationService.java 2012-02-07 16:03:05 +0000 @@ -87,6 +87,11 @@ // Build internal map layer representation InternalMapLayer mapLayer = buildSingleInternalMapLayer( mapView ); + if ( mapLayer == null ) + { + return null; + } + // Build internal representation of a map using GeoTools, then render it // to an image GeoToolsMap gtMap = new GeoToolsMap( mapLayer ); @@ -127,6 +132,24 @@ boolean isIndicator = MappingService.MAP_VALUE_TYPE_INDICATOR.equals( mapView.getMapValueType() ); + Collection mapValues; + + if ( isIndicator ) + { + mapValues = mappingService.getIndicatorMapValues( mapView.getIndicator().getId(), mapView.getPeriod() + .getId(), mapView.getParentOrganisationUnit().getId(), mapView.getOrganisationUnitLevel().getLevel() ); + } + else + { + mapValues = mappingService.getDataElementMapValues( mapView.getDataElement().getId(), mapView.getPeriod() + .getId(), mapView.getParentOrganisationUnit().getId(), mapView.getOrganisationUnitLevel().getLevel() ); + } + + if ( !( mapValues != null && mapValues.size() > 0 ) ) + { + return null; + } + // Get the name from the external layer String name = mapView.getName(); @@ -165,25 +188,6 @@ mapLayer.setStrokeColor( strokeColor ); mapLayer.setStrokeWidth( strokeWidth ); - // Get the aggregated map values - // TODO Might make version of getIndicatorMapValues that takes Indicator - // and parent OrganisationUnit *directly*, i.e. not from ID-s, since we have - // them - // NOTE There is no need to provide startDate and endDate as period is - // set - Collection mapValues; - - if ( isIndicator ) - { - mapValues = mappingService.getIndicatorMapValues( mapView.getIndicator().getId(), mapView.getPeriod() - .getId(), mapView.getParentOrganisationUnit().getId(), mapView.getOrganisationUnitLevel().getLevel() ); - } - else - { - mapValues = mappingService.getDataElementMapValues( mapView.getDataElement().getId(), mapView.getPeriod() - .getId(), mapView.getParentOrganisationUnit().getId(), mapView.getOrganisationUnitLevel().getLevel() ); - } - // Build and set the internal GeoTools map objects for the layer buildGeoToolsMapObjectsForMapLayer( mapLayer, mapValues ); === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MapController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MapController.java 2012-01-24 14:43:36 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MapController.java 2012-02-07 16:03:05 +0000 @@ -191,7 +191,15 @@ throws Exception { BufferedImage image = mapGenerationService.generateMapImage( mapView ); - response.setContentType( ContextUtils.CONTENT_TYPE_PNG ); - ImageIO.write( image, "PNG", response.getOutputStream() ); + + if ( image != null ) + { + response.setContentType( ContextUtils.CONTENT_TYPE_PNG ); + ImageIO.write( image, "PNG", response.getOutputStream() ); + } + else + { + response.setStatus( HttpServletResponse.SC_NO_CONTENT ); + } } }