← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5876: Map generation, returning 204 No Content instead of assert exception when there is no data for cu...

 

------------------------------------------------------------
revno: 5876
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-02-07 17:03:05 +0100
message:
  Map generation, returning 204 No Content instead of assert exception when there is no data for current map
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapgeneration/MapGenerationService.java
  dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMapGenerationService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MapController.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/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<AggregatedMapValue> 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<AggregatedMapValue> 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 );
+        }
     }
 }