← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8717: Added separate MapViewController so that the PNG maps will continue to work

 

------------------------------------------------------------
revno: 8717
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-10-25 19:18:52 +0200
message:
  Added separate MapViewController so that the PNG maps will continue to work
added:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/mapping/MapViewController.java
  dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/mapView.xsl
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/mapping/MapController.java
  dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/list.xsl
  dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/map.xsl
  dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/model2html.xsl


--
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/mapping/MapView.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java	2012-10-25 16:59:25 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java	2012-10-25 17:18:52 +0000
@@ -147,6 +147,12 @@
     // Getters and setters
     // -------------------------------------------------------------------------
 
+    @Override
+    public String getName()
+    {
+        return uid;
+    }
+    
     @JsonProperty
     @JsonView( {DetailedView.class, ExportView.class} )
     @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/mapping/MapController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/mapping/MapController.java	2012-10-25 16:59:25 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/mapping/MapController.java	2012-10-25 17:18:52 +0000
@@ -29,25 +29,20 @@
 
 import static org.hisp.dhis.period.PeriodType.getPeriodFromIsoString;
 
-import java.awt.image.BufferedImage;
 import java.io.InputStream;
 import java.util.Iterator;
 
-import javax.imageio.ImageIO;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.hisp.dhis.api.controller.AbstractCrudController;
 import org.hisp.dhis.api.utils.ContextUtils;
-import org.hisp.dhis.api.utils.ContextUtils.CacheStrategy;
 import org.hisp.dhis.dataelement.DataElementService;
 import org.hisp.dhis.dxf2.utils.JacksonUtils;
 import org.hisp.dhis.indicator.IndicatorService;
-import org.hisp.dhis.mapgeneration.MapGenerationService;
 import org.hisp.dhis.mapping.Map;
 import org.hisp.dhis.mapping.MapView;
 import org.hisp.dhis.mapping.MappingService;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.period.PeriodService;
@@ -56,11 +51,9 @@
 import org.springframework.http.HttpStatus;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.stereotype.Controller;
-import org.springframework.ui.Model;
 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;
 
 /**
@@ -94,13 +87,7 @@
     
     @Autowired
     private PeriodService periodService;
-        
-    @Autowired
-    private MapGenerationService mapGenerationService;
-
-    @Autowired
-    private ContextUtils contextUtils;
-
+    
     //--------------------------------------------------------------------------
     // CRUD
     //--------------------------------------------------------------------------
@@ -189,58 +176,9 @@
     }
 
     //--------------------------------------------------------------------------
-    // Data
-    //--------------------------------------------------------------------------
-
-    @RequestMapping( value = { "/{uid}/data", "/{uid}/data.png" }, method = RequestMethod.GET )
-    public void getMap( @PathVariable String uid, HttpServletResponse response ) throws Exception
-    {
-        MapView mapView = mappingService.getMapView( uid );
-
-        renderMapViewPng( mapView, response );
-    }
-
-    @RequestMapping( value = { "/data", "/data.png" }, method = RequestMethod.GET )
-    public void getMap( Model model,
-        @RequestParam( value = "in" ) String indicatorUid,
-        @RequestParam( value = "ou" ) String organisationUnitUid,
-        @RequestParam( value = "level", required = false ) Integer level,
-        HttpServletResponse response ) throws Exception
-    {
-        if ( level == null )
-        {
-            OrganisationUnit unit = organisationUnitService.getOrganisationUnit( organisationUnitUid );
-
-            level = organisationUnitService.getLevelOfOrganisationUnit( unit.getId() );
-            level++;
-        }
-
-        MapView mapView = mappingService.getIndicatorLastYearMapView( indicatorUid, organisationUnitUid, level );
-
-        renderMapViewPng( mapView, response );
-    }
-
-    //--------------------------------------------------------------------------
     // Supportive methods
     //--------------------------------------------------------------------------
 
-    private void renderMapViewPng( MapView mapView, HttpServletResponse response )
-        throws Exception
-    {
-        BufferedImage image = mapGenerationService.generateMapImage( mapView );
-
-        if ( image != null )
-        {
-            contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_PNG, CacheStrategy.RESPECT_SYSTEM_SETTING, "mapview.png", false );
-
-            ImageIO.write( image, "PNG", response.getOutputStream() );
-        }
-        else
-        {
-            response.setStatus( HttpServletResponse.SC_NO_CONTENT );
-        }
-    }
-    
     // TODO use the import service instead
     
     private void mergeMap( Map map )

=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/mapping/MapViewController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/mapping/MapViewController.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/mapping/MapViewController.java	2012-10-25 17:18:52 +0000
@@ -0,0 +1,121 @@
+package org.hisp.dhis.api.controller.mapping;
+
+/*
+ * Copyright (c) 2011, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.awt.image.BufferedImage;
+
+import javax.imageio.ImageIO;
+import javax.servlet.http.HttpServletResponse;
+
+import org.hisp.dhis.api.controller.AbstractCrudController;
+import org.hisp.dhis.api.utils.ContextUtils;
+import org.hisp.dhis.api.utils.ContextUtils.CacheStrategy;
+import org.hisp.dhis.mapgeneration.MapGenerationService;
+import org.hisp.dhis.mapping.MapView;
+import org.hisp.dhis.mapping.MappingService;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+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;
+
+/**
+ * @author Lars Helge Overland
+ */
+@Controller
+@RequestMapping( value = MapViewController.RESOURCE_PATH )
+public class MapViewController
+    extends AbstractCrudController<MapView>
+{
+    public static final String RESOURCE_PATH = "/mapViews";
+
+    @Autowired
+    private MappingService mappingService;
+
+    @Autowired
+    private OrganisationUnitService organisationUnitService;
+
+    @Autowired
+    private ContextUtils contextUtils;
+
+    @Autowired
+    private MapGenerationService mapGenerationService;
+
+    @RequestMapping( value = { "/{uid}/data", "/{uid}/data.png" }, method = RequestMethod.GET )
+    public void getMap( @PathVariable String uid, HttpServletResponse response ) throws Exception
+    {
+        MapView mapView = mappingService.getMapView( uid );
+
+        renderMapViewPng( mapView, response );
+    }
+
+    @RequestMapping( value = { "/data", "/data.png" }, method = RequestMethod.GET )
+    public void getMap( Model model,
+        @RequestParam( value = "in" ) String indicatorUid,
+        @RequestParam( value = "ou" ) String organisationUnitUid,
+        @RequestParam( value = "level", required = false ) Integer level,
+        HttpServletResponse response ) throws Exception
+    {
+        if ( level == null )
+        {
+            OrganisationUnit unit = organisationUnitService.getOrganisationUnit( organisationUnitUid );
+
+            level = organisationUnitService.getLevelOfOrganisationUnit( unit.getId() );
+            level++;
+        }
+
+        MapView mapView = mappingService.getIndicatorLastYearMapView( indicatorUid, organisationUnitUid, level );
+
+        renderMapViewPng( mapView, response );
+    }
+
+    //--------------------------------------------------------------------------
+    // Supportive methods
+    //--------------------------------------------------------------------------
+
+    private void renderMapViewPng( MapView mapView, HttpServletResponse response )
+        throws Exception
+    {
+        BufferedImage image = mapGenerationService.generateMapImage( mapView );
+
+        if ( image != null )
+        {
+            contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_PNG, CacheStrategy.RESPECT_SYSTEM_SETTING, "mapview.png", false );
+
+            ImageIO.write( image, "PNG", response.getOutputStream() );
+        }
+        else
+        {
+            response.setStatus( HttpServletResponse.SC_NO_CONTENT );
+        }
+    }
+}

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/list.xsl'
--- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/list.xsl	2012-10-23 13:24:16 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/list.xsl	2012-10-25 17:18:52 +0000
@@ -12,7 +12,7 @@
     <xsl:apply-templates select="d:*[local-name()!='pager']"/>
   </xsl:template>
 
-  <xsl:template match="d:resources|d:maps|d:charts|d:categoryCombos|d:categories|
+  <xsl:template match="d:resources|d:maps|d:mapViews|d:charts|d:categoryCombos|d:categories|
       d:categoryOptions|d:categoryOptionCombos|d:dataElements|d:indicators|
       d:organisationUnits|d:dataElementGroups|d:dataElementGroupSets|d:dataSets|
       d:documents|d:indicatorGroups|d:indicatorGroupSets|d:organisationUnitGroups|

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/map.xsl'
--- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/map.xsl	2012-07-30 19:02:10 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/map.xsl	2012-10-25 17:18:52 +0000
@@ -4,89 +4,24 @@
 
   <xsl:template match="d:map">
     <div class="map">
-      <h2><xsl:value-of select="@name"/></h2>
-	  
-	  <table>
-		<tr>
-			<td>Resource Data</td>
-			<td><a href="{@href}/data">png</a></td>
-		</tr>
-	  </table><br/>
-	  
-	  <table>
-		<tr>
-			<td>Dynamic Data</td>
-			<td><a href="data">png</a></td>
-		</tr>
-		<tr>
-			<td>in</td>
-			<td>indicator uid (req)</td>
-		</tr>
-		<tr>
-			<td>ou</td>
-			<td>organisation unit uid (req)</td>
-		</tr>
-		<tr>
-			<td>level</td>
-			<td>organisation unit level (opt)</td>
-		</tr>
-	  </table><br/>
-	  
-      <a href="{@href}/data"><img src="{@href}/data" style="border-style:solid; border-width: 1px; padding: 5px;" /></a>
-
-      <h3>Details</h3>
+      <h2> <xsl:value-of select="@name" /> </h2>
 
       <table>
-        <xsl:for-each select="attribute::*">
-          <tr><td><xsl:value-of select="local-name()"/></td><td><xsl:value-of select="."/></td></tr>
-        </xsl:for-each>
-        <xsl:for-each select="child::*">
-          <tr><td><xsl:value-of select="local-name()"/></td><td>
-            <xsl:choose>
-              <xsl:when test="@name"><a href="{@href}"><xsl:value-of select="@name"/></a>
-              </xsl:when>
-              <xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
-            </xsl:choose>
-          </td></tr>
-        </xsl:for-each>
+        <tr>
+          <td>ID</td>
+          <td> <xsl:value-of select="@id" /> </td>
+        </tr>
+        <tr>
+          <td>Last Updated</td>
+          <td> <xsl:value-of select="@lastUpdated" /> </td>
+        </tr>
+        <tr>
+          <td>Code</td>
+          <td> <xsl:value-of select="@code" /> </td>
+        </tr>
       </table>
+      
     </div>
   </xsl:template>
 
-  <xsl:template match="d:map" mode="row">
-    <tr>
-      <td><xsl:value-of select="@name"/></td>
-      <td>
-        <xsl:element name="a">
-          <xsl:attribute name="href"><xsl:value-of select="@href"/></xsl:attribute>
-          <xsl:text>html</xsl:text>
-        </xsl:element>
-      </td>
-      <td>
-        <xsl:element name="a">
-          <xsl:attribute name="href"><xsl:value-of select="concat(@href,'.png')"/></xsl:attribute>
-          <xsl:text>png</xsl:text>
-        </xsl:element>
-      </td>
-      <td>
-        <xsl:element name="a">
-          <xsl:attribute name="href"><xsl:value-of select="concat(@href,'.xml')"/></xsl:attribute>
-          <xsl:text>xml</xsl:text>
-        </xsl:element>
-      </td>
-      <td>
-        <xsl:element name="a">
-          <xsl:attribute name="href"><xsl:value-of select="concat(@href,'.json')"/></xsl:attribute>
-          <xsl:text>json</xsl:text>
-        </xsl:element>
-      </td>
-      <td>
-        <xsl:element name="a">
-          <xsl:attribute name="href"><xsl:value-of select="concat(@href,'.jsonp')"/></xsl:attribute>
-          <xsl:text>jsonp</xsl:text>
-        </xsl:element>
-      </td>
-    </tr>
-  </xsl:template>
-
 </xsl:stylesheet>

=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/mapView.xsl'
--- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/mapView.xsl	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/mapView.xsl	2012-10-25 17:18:52 +0000
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0"
+                xmlns="http://www.w3.org/1999/xhtml"; xmlns:d="http://dhis2.org/schema/dxf/2.0";>
+
+  <xsl:template match="d:mapView">
+    <div class="mapView">
+      <h2><xsl:value-of select="@name"/></h2>
+      
+      <table>
+        <tr>
+            <td>Resource Data</td>
+            <td><a href="{@href}/data">png</a></td>
+        </tr>
+      </table><br/>
+      
+      <table>
+        <tr>
+            <td>Dynamic Data</td>
+            <td><a href="data">png</a></td>
+        </tr>
+        <tr>
+            <td>in</td>
+            <td>indicator uid (req)</td>
+        </tr>
+        <tr>
+            <td>ou</td>
+            <td>organisation unit uid (req)</td>
+        </tr>
+        <tr>
+            <td>level</td>
+            <td>organisation unit level (opt)</td>
+        </tr>
+      </table><br/>
+      
+      <a href="{@href}/data"><img src="{@href}/data" style="border-style:solid; border-width: 1px; padding: 5px;" /></a>
+
+      <h3>Details</h3>
+
+      <table>
+        <xsl:for-each select="attribute::*">
+          <tr><td><xsl:value-of select="local-name()"/></td><td><xsl:value-of select="."/></td></tr>
+        </xsl:for-each>
+        <xsl:for-each select="child::*">
+          <tr><td><xsl:value-of select="local-name()"/></td><td>
+            <xsl:choose>
+              <xsl:when test="@name"><a href="{@href}"><xsl:value-of select="@name"/></a>
+              </xsl:when>
+              <xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
+            </xsl:choose>
+          </td></tr>
+        </xsl:for-each>
+      </table>
+    </div>
+  </xsl:template>
+
+  <xsl:template match="d:mapView" mode="row">
+    <tr>
+      <td><xsl:value-of select="@name"/></td>
+      <td>
+        <xsl:element name="a">
+          <xsl:attribute name="href"><xsl:value-of select="@href"/></xsl:attribute>
+          <xsl:text>html</xsl:text>
+        </xsl:element>
+      </td>
+      <td>
+        <xsl:element name="a">
+          <xsl:attribute name="href"><xsl:value-of select="concat(@href,'.png')"/></xsl:attribute>
+          <xsl:text>png</xsl:text>
+        </xsl:element>
+      </td>
+      <td>
+        <xsl:element name="a">
+          <xsl:attribute name="href"><xsl:value-of select="concat(@href,'.xml')"/></xsl:attribute>
+          <xsl:text>xml</xsl:text>
+        </xsl:element>
+      </td>
+      <td>
+        <xsl:element name="a">
+          <xsl:attribute name="href"><xsl:value-of select="concat(@href,'.json')"/></xsl:attribute>
+          <xsl:text>json</xsl:text>
+        </xsl:element>
+      </td>
+      <td>
+        <xsl:element name="a">
+          <xsl:attribute name="href"><xsl:value-of select="concat(@href,'.jsonp')"/></xsl:attribute>
+          <xsl:text>jsonp</xsl:text>
+        </xsl:element>
+      </td>
+    </tr>
+  </xsl:template>
+
+</xsl:stylesheet>

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/model2html.xsl'
--- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/model2html.xsl	2012-10-17 12:39:02 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/model2html.xsl	2012-10-25 17:18:52 +0000
@@ -17,6 +17,7 @@
   <xsl:include href="resource.xsl" />
   <xsl:include href="relativePeriods.xsl" />
   <xsl:include href="map.xsl" />
+  <xsl:include href="mapView.xsl" />
   <xsl:include href="mapLegend.xsl" />
   <xsl:include href="mapLegendSet.xsl" />
   <xsl:include href="mapLayer.xsl" />