← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15724: PNG maps, fixed bug, setting only height query param caused exception

 

------------------------------------------------------------
revno: 15724
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-06-17 14:51:39 +0200
message:
  PNG maps, fixed bug, setting only height query param caused exception
modified:
  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/MapUtils.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/mapping/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-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	2014-03-26 22:18:35 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMapGenerationService.java	2014-06-17 12:51:39 +0000
@@ -161,7 +161,7 @@
             // Build the legend set, then render it to an image            
             LegendSet legendSet = new LegendSet( dataLayer );
             
-            BufferedImage titleImage = MapUtils.renderTitle( map.getName(), width );
+            BufferedImage titleImage = MapUtils.renderTitle( map.getName(), width, height );
             
             BufferedImage legendImage = legendSet.render( i18nManager.getI18nFormat() );
     

=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/MapUtils.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/MapUtils.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/MapUtils.java	2014-06-17 12:51:39 +0000
@@ -199,9 +199,9 @@
         return image;
     }
 
-    public static BufferedImage renderTitle( String title, int maxWidth )
-    {
-        int[] widthHeight = getWidthHeight( maxWidth, null, 0, 0, 1 );
+    public static BufferedImage renderTitle( String title, Integer maxWidth, Integer maxHeight )
+    {        
+        int[] widthHeight = getWidthHeight( maxWidth, maxHeight, 0, 0, 1 );
 
         BufferedImage image = new BufferedImage( widthHeight[0], TITLE_HEIGHT, BufferedImage.TYPE_INT_ARGB );
         Graphics2D g = (Graphics2D) image.getGraphics();
@@ -215,7 +215,7 @@
     }
 
     /**
-     * Calcuates the width and height of an two-dimensional area. If width is not
+     * Calculates the width and height of an two-dimensional area. If width is not
      * null, the width will be used and the height will be calculated. If the height 
      * is not null, the height will be used and the width will be calculated. If 
      * both width and height are not null, the width or height will be adjusted 
@@ -223,7 +223,7 @@
      * height.
      * 
      * @param maxWidth the maximum width.
-     * @param maxHeight the maxium height.
+     * @param maxHeight the maximum height.
      * @param subtractWidth the value to subtract from final width
      * @param subtractHeight the value to subtract from final height 
      * @param widthFactor the width to height factor.

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/mapping/MapController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/mapping/MapController.java	2014-05-27 13:18:27 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/mapping/MapController.java	2014-06-17 12:51:39 +0000
@@ -79,6 +79,9 @@
 public class MapController
     extends AbstractCrudController<Map>
 {
+    private static final int MAP_MIN_WIDTH = 140;
+    private static final int MAP_MIN_HEIGHT = 25;
+    
     @Autowired
     private MappingService mappingService;
 
@@ -220,9 +223,21 @@
             ContextUtils.notFoundResponse( response, "Map does not exist: " + uid );
             return;
         }
+        
+        if ( width != null && width < MAP_MIN_WIDTH )
+        {
+            ContextUtils.conflictResponse( response, "Min map width is " + MAP_MIN_WIDTH + ": " + width );
+            return;
+        }
+        
+        if ( height != null && height < MAP_MIN_HEIGHT )
+        {
+            ContextUtils.conflictResponse( response, "Min map height is " + MAP_MIN_HEIGHT + ": " + height );
+            return;            
+        }
 
         OrganisationUnit unit = ou != null ? organisationUnitService.getOrganisationUnit( ou ) : null;
-
+        
         renderMapViewPng( map, date, unit, width, height, response );
     }