← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5439: Web api: added map generation for dynamic indicator and parent org unit arguments

 

Merge authors:
  Lars Helge Øverland (larshelge)
------------------------------------------------------------
revno: 5439 [merge]
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-12-15 18:53:48 +0100
message:
  Web api: added map generation for dynamic indicator and parent org unit arguments
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java
  dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMapGenerationService.java
  dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.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/mapping/MappingService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java	2011-12-15 16:57:22 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java	2011-12-15 17:53:48 +0000
@@ -145,6 +145,8 @@
     
     MapView getMapViewByName( String name );
 
+    MapView getIndicatorLastYearMapView( String indicatorUid, String organisationUnitUid, int level );
+    
     Collection<MapView> getAllMapViews();
 
     Collection<MapView> getMapViewsByFeatureType( String featureType );

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java	2011-12-14 14:28:04 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java	2011-12-15 17:53:48 +0000
@@ -523,9 +523,10 @@
         return reportingMonth;
     }
 
-    public void setReportingMonth( boolean reportingMonth )
+    public RelativePeriods setReportingMonth( boolean reportingMonth )
     {
         this.reportingMonth = reportingMonth;
+        return this;
     }
 
     @XmlElement
@@ -535,9 +536,10 @@
         return reportingBimonth;
     }
 
-    public void setReportingBimonth( boolean reportingBimonth )
+    public RelativePeriods setReportingBimonth( boolean reportingBimonth )
     {
         this.reportingBimonth = reportingBimonth;
+        return this;
     }
 
     @XmlElement
@@ -547,9 +549,10 @@
         return reportingQuarter;
     }
 
-    public void setReportingQuarter( boolean reportingQuarter )
+    public RelativePeriods setReportingQuarter( boolean reportingQuarter )
     {
         this.reportingQuarter = reportingQuarter;
+        return this;
     }
 
     @XmlElement
@@ -559,9 +562,10 @@
         return monthsThisYear;
     }
 
-    public void setMonthsThisYear( boolean monthsThisYear )
+    public RelativePeriods setMonthsThisYear( boolean monthsThisYear )
     {
         this.monthsThisYear = monthsThisYear;
+        return this;
     }
 
     @XmlElement
@@ -571,9 +575,10 @@
         return quartersThisYear;
     }
 
-    public void setQuartersThisYear( boolean quartersThisYear )
+    public RelativePeriods setQuartersThisYear( boolean quartersThisYear )
     {
         this.quartersThisYear = quartersThisYear;
+        return this;
     }
 
     @XmlElement
@@ -583,9 +588,10 @@
         return thisYear;
     }
 
-    public void setThisYear( boolean thisYear )
+    public RelativePeriods setThisYear( boolean thisYear )
     {
         this.thisYear = thisYear;
+        return this;
     }
 
     @XmlElement
@@ -595,9 +601,10 @@
         return monthsLastYear;
     }
 
-    public void setMonthsLastYear( boolean monthsLastYear )
+    public RelativePeriods setMonthsLastYear( boolean monthsLastYear )
     {
         this.monthsLastYear = monthsLastYear;
+        return this;
     }
 
     @XmlElement
@@ -607,9 +614,10 @@
         return quartersLastYear;
     }
 
-    public void setQuartersLastYear( boolean quartersLastYear )
+    public RelativePeriods setQuartersLastYear( boolean quartersLastYear )
     {
         this.quartersLastYear = quartersLastYear;
+        return this;
     }
 
     @XmlElement
@@ -619,9 +627,10 @@
         return lastYear;
     }
 
-    public void setLastYear( boolean lastYear )
+    public RelativePeriods setLastYear( boolean lastYear )
     {
         this.lastYear = lastYear;
+        return this;
     }
 
     @XmlElement
@@ -631,9 +640,10 @@
         return last5Years;
     }
 
-    public void setLast5Years( boolean last5Years )
+    public RelativePeriods setLast5Years( boolean last5Years )
     {
         this.last5Years = last5Years;
+        return this;
     }
 
     @XmlElement
@@ -643,9 +653,10 @@
         return last12Months;
     }
 
-    public void setLast12Months( boolean last12Months )
+    public RelativePeriods setLast12Months( boolean last12Months )
     {
         this.last12Months = last12Months;
+        return this;
     }
 
     @XmlElement
@@ -655,9 +666,10 @@
         return last6BiMonths;
     }
 
-    public void setLast6BiMonths( boolean last6BiMonths )
+    public RelativePeriods setLast6BiMonths( boolean last6BiMonths )
     {
         this.last6BiMonths = last6BiMonths;
+        return this;
     }
 
     @XmlElement
@@ -667,9 +679,10 @@
         return last4Quarters;
     }
 
-    public void setLast4Quarters( boolean last4Quarters )
+    public RelativePeriods setLast4Quarters( boolean last4Quarters )
     {
         this.last4Quarters = last4Quarters;
+        return this;
     }
 
     @XmlElement
@@ -679,9 +692,10 @@
         return last2SixMonths;
     }
 
-    public void setLast2SixMonths( boolean last2SixMonths )
+    public RelativePeriods setLast2SixMonths( boolean last2SixMonths )
     {
         this.last2SixMonths = last2SixMonths;
+        return this;
     }
 
     // -------------------------------------------------------------------------

=== 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-15 16:57:22 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMapGenerationService.java	2011-12-15 17:02:41 +0000
@@ -172,16 +172,17 @@
         // NOTE There is no need to provide startDate and endDate as period is
         // set
         Collection<AggregatedMapValue> mapValues;
-        if ( mapView.getMapValueType().equals( "dataelement" ) )
+        
+        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() );
         }
-        else
-        {
-            mapValues = mappingService.getIndicatorMapValues( mapView.getIndicator().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-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java'
--- dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java	2011-12-11 13:47:04 +0000
+++ dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java	2011-12-15 17:53:48 +0000
@@ -46,6 +46,7 @@
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.period.RelativePeriods;
 import org.hisp.dhis.system.util.ConversionUtils;
 import org.hisp.dhis.system.util.MathUtils;
 import org.hisp.dhis.user.CurrentUserService;
@@ -518,6 +519,26 @@
         return mappingStore.getMapViewByName( name );
     }
 
+    public MapView getIndicatorLastYearMapView( String indicatorUid, String organisationUnitUid, int level )
+    {
+        MapView mapView = new MapView();
+        
+        Period period = periodService.reloadPeriod( 
+            new RelativePeriods().setLastYear( true ).getRelativePeriods().iterator().next() );
+        
+        Indicator indicator = indicatorService.getIndicator( indicatorUid );
+        OrganisationUnit unit = organisationUnitService.getOrganisationUnit( organisationUnitUid );
+        
+        mapView.setIndicator( indicator );
+        mapView.setPeriod( period );
+        mapView.setParentOrganisationUnit( unit );
+        mapView.setOrganisationUnitLevel( new OrganisationUnitLevel( level, "" ) );
+        mapView.setName( indicator.getName() );
+        mapView.setMapValueType( MappingService.MAP_VALUE_TYPE_INDICATOR );
+        
+        return mapView;
+    }
+
     public Collection<MapView> getAllMapViews()
     {
         User user = currentUserService.getCurrentUser();
@@ -550,7 +571,7 @@
 
         return mapViews;
     }
-
+    
     // -------------------------------------------------------------------------
     // MapLayer
     // -------------------------------------------------------------------------

=== 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	2011-12-15 16:24:21 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MapController.java	2011-12-15 17:53:48 +0000
@@ -47,6 +47,7 @@
 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;
 
 @Controller
@@ -79,7 +80,7 @@
         return "maps";
     }
 
-    @RequestMapping( value = "/{uid}", method = RequestMethod.GET )
+    @RequestMapping( value = {"/{uid}","/{uid}/data"}, method = RequestMethod.GET )
     public String getMap( @PathVariable String uid, IdentifiableObjectParams params, Model model, HttpServletRequest request )
     {
         MapView mapView = mappingService.getMapView( uid );
@@ -94,6 +95,19 @@
 
         return "map";
     }
+    
+    @RequestMapping( value = "/data", method = RequestMethod.GET )
+    public String getMap( Model model,
+        @RequestParam( value = "in" ) String indicatorUid, 
+        @RequestParam( value = "ou" ) String organisationUnitUid,
+        @RequestParam Integer level )
+    {
+        MapView mapView = mappingService.getIndicatorLastYearMapView( indicatorUid, organisationUnitUid, level );
+
+        model.addAttribute( "model", mapView );
+
+        return "map";
+    }
 
     //-------------------------------------------------------------------------------------------------------
     // POST