← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8712: Web api, impl post of maps

 

------------------------------------------------------------
revno: 8712
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-10-25 16:58:43 +0200
message:
  Web api, impl post of maps
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/mapping/hibernate/MapView.hbm.xml
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/mapping/MappingServiceTest.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/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-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 13:19:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java	2012-10-25 14:58:43 +0000
@@ -65,6 +65,12 @@
     public static final String LAYER_THEMATIC2 = "thematic2";
     public static final String LAYER_FACILITY = "facility";
     public static final String LAYER_SYMBOL = "symbol";
+
+    public static final String VALUE_TYPE_INDICATOR = "indicator";
+    public static final String VALUE_TYPE_DATAELEMENT = "dataelement";
+
+    public static final String LEGEND_TYPE_AUTOMATIC = "automatic";
+    public static final String LEGEND_TYPE_PREDEFINED = "predefined";
     
     private static final long serialVersionUID = 1866358818802275436L;
 
@@ -80,8 +86,6 @@
 
     private DataElement dataElement;
 
-    private PeriodType periodType;
-
     private Period period;
 
     private OrganisationUnit parentOrganisationUnit;
@@ -113,7 +117,7 @@
     }
 
     public MapView( String layer, String name, String valueType, IndicatorGroup indicatorGroup, Indicator indicator,
-                    DataElementGroup dataElementGroup, DataElement dataElement, PeriodType periodType,
+                    DataElementGroup dataElementGroup, DataElement dataElement,
                     Period period, OrganisationUnit parentOrganisationUnit, OrganisationUnitLevel organisationUnitLevel,
                     String legendType, Integer method, Integer classes, String colorLow, String colorHigh,
                     MapLegendSet legendSet, Integer radiusLow, Integer radiusHigh, int opacity )
@@ -125,7 +129,6 @@
         this.indicator = indicator;
         this.dataElementGroup = dataElementGroup;
         this.dataElement = dataElement;
-        this.periodType = periodType;
         this.period = period;
         this.parentOrganisationUnit = parentOrganisationUnit;
         this.organisationUnitLevel = organisationUnitLevel;
@@ -141,46 +144,6 @@
     }
 
     // -------------------------------------------------------------------------
-    // hashCode, equals and toString
-    // -------------------------------------------------------------------------
-
-    @Override
-    public int hashCode()
-    {
-        return name.hashCode();
-    }
-
-    @Override
-    public boolean equals( Object object )
-    {
-        if ( this == object )
-        {
-            return true;
-        }
-
-        if ( object == null )
-        {
-            return false;
-        }
-
-        if ( getClass() != object.getClass() )
-        {
-            return false;
-        }
-
-        final MapView other = (MapView) object;
-
-        return name.equals( other.name );
-    }
-
-    @Override
-    public String toString()
-    {
-        return "[Name: " + name + ", indicator: " + indicator + ", org unit: " +
-            parentOrganisationUnit + ", period: " + period + ", value type: " + valueType + "]";
-    }
-
-    // -------------------------------------------------------------------------
     // Getters and setters
     // -------------------------------------------------------------------------
 
@@ -273,12 +236,7 @@
     @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
     public PeriodType getPeriodType()
     {
-        return periodType;
-    }
-
-    public void setPeriodType( PeriodType periodType )
-    {
-        this.periodType = periodType;
+        return period.getPeriodType();
     }
 
     @JsonProperty
@@ -457,6 +415,13 @@
     }
 
     @Override
+    public String toString()
+    {
+        return "[Indicator: " + indicator + ", org unit: " +
+            parentOrganisationUnit + ", period: " + period + ", value type: " + valueType + "]";
+    }
+
+    @Override
     public void mergeWith( IdentifiableObject other )
     {
         super.mergeWith( other );
@@ -470,7 +435,6 @@
             indicator = mapView.getIndicator() == null ? indicator : mapView.getIndicator();
             dataElementGroup = mapView.getDataElementGroup() == null ? dataElementGroup : mapView.getDataElementGroup();
             dataElement = mapView.getDataElement() == null ? dataElement : mapView.getDataElement();
-            periodType = mapView.getPeriodType() == null ? periodType : mapView.getPeriodType();
             period = mapView.getPeriod() == null ? period : mapView.getPeriod();
             parentOrganisationUnit = mapView.getParentOrganisationUnit() == null ? parentOrganisationUnit : mapView.getParentOrganisationUnit();
             organisationUnitLevel = mapView.getOrganisationUnitLevel() == null ? organisationUnitLevel : mapView.getOrganisationUnitLevel();

=== 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	2012-10-25 12:38:20 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java	2012-10-25 14:58:43 +0000
@@ -44,9 +44,6 @@
 
     final String GEOJSON_DIR = "geojson";
 
-    final String MAP_VALUE_TYPE_INDICATOR = "indicator";
-    final String MAP_VALUE_TYPE_DATAELEMENT = "dataelement";
-
     final String MAP_LEGEND_SYMBOLIZER_COLOR = "color";
     final String MAP_LEGEND_SYMBOLIZER_IMAGE = "image";
 
@@ -61,9 +58,6 @@
     final String MAP_LAYER_TYPE_BASELAYER = "baselayer";
     final String MAP_LAYER_TYPE_OVERLAY = "overlay";
     
-    final String MAPLEGENDSET_TYPE_AUTOMATIC = "automatic";
-    final String MAPLEGENDSET_TYPE_PREDEFINED = "predefined";
-    
     // -------------------------------------------------------------------------
     // IndicatorMapValue
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java	2012-10-25 12:38:20 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java	2012-10-25 14:58:43 +0000
@@ -46,7 +46,6 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 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;
@@ -460,7 +459,7 @@
 
         DataElement dataElement = null;
 
-        if ( mapValueType.equals( MappingService.MAP_VALUE_TYPE_INDICATOR ) )
+        if ( mapValueType.equals( MapView.VALUE_TYPE_INDICATOR ) )
         {
             indicatorGroup = indicatorService.getIndicatorGroup( indicatorGroupId );
             indicator = indicatorService.getIndicator( indicatorId );
@@ -471,9 +470,6 @@
             dataElement = dataElementService.getDataElement( dataElementId );
         }
 
-        PeriodType periodType = periodTypeName != null && !periodTypeName.isEmpty() ? periodService
-            .getPeriodTypeByClass( PeriodType.getPeriodTypeByName( periodTypeName ).getClass() ) : null;
-
         Period period = periodId != null ? periodService.getPeriod( periodId ) : null;
 
         OrganisationUnit parent = organisationUnitService.getOrganisationUnit( parentOrganisationUnitId );
@@ -483,7 +479,7 @@
         MapLegendSet mapLegendSet = mapLegendSetId != null ? getMapLegendSet( mapLegendSetId ) : null;
 
         addMapView( new MapView( MapView.LAYER_THEMATIC1, name, mapValueType, indicatorGroup, indicator, dataElementGroup, dataElement,
-            periodType, period, parent, level, mapLegendType, method, classes, colorLow, colorHigh,
+            period, parent, level, mapLegendType, method, classes, colorLow, colorHigh,
             mapLegendSet, radiusLow, radiusHigh, 1 ) );
     }
 
@@ -544,7 +540,7 @@
         mapView.setParentOrganisationUnit( unit );
         mapView.setOrganisationUnitLevel( new OrganisationUnitLevel( level, "" ) );
         mapView.setName( indicator.getName() );
-        mapView.setValueType( MappingService.MAP_VALUE_TYPE_INDICATOR );
+        mapView.setValueType( MapView.VALUE_TYPE_INDICATOR );
 
         return mapView;
     }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/mapping/hibernate/MapView.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/mapping/hibernate/MapView.hbm.xml	2012-10-25 12:38:20 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/mapping/hibernate/MapView.hbm.xml	2012-10-25 14:58:43 +0000
@@ -29,9 +29,6 @@
     <many-to-one name="dataElement" class="org.hisp.dhis.dataelement.DataElement" column="dataelementid"
       foreign-key="fk_mapview_dataelementid" />
 
-    <many-to-one name="periodType" class="org.hisp.dhis.period.PeriodType" column="periodtypeid"
-      foreign-key="fk_mapview_periodtypeid" />
-
     <many-to-one name="period" class="org.hisp.dhis.period.Period" column="periodid" foreign-key="fk_mapview_periodid" />
 
     <many-to-one name="parentOrganisationUnit" class="org.hisp.dhis.organisationunit.OrganisationUnit"

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/mapping/MappingServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/mapping/MappingServiceTest.java	2012-10-25 13:19:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/mapping/MappingServiceTest.java	2012-10-25 14:58:43 +0000
@@ -32,7 +32,8 @@
 import static junit.framework.Assert.assertNull;
 import static junit.framework.Assert.assertTrue;
 import static org.hisp.dhis.mapping.MapView.LAYER_THEMATIC1;
-import static org.hisp.dhis.mapping.MappingService.MAPLEGENDSET_TYPE_AUTOMATIC;
+import static org.hisp.dhis.mapping.MapView.LEGEND_TYPE_AUTOMATIC;
+import static org.hisp.dhis.mapping.MapView.VALUE_TYPE_INDICATOR;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -265,9 +266,9 @@
     @Test
     public void testAddGetMapView()
     {
-        MapView mapView = new MapView( LAYER_THEMATIC1, "MapViewA", MappingService.MAP_VALUE_TYPE_INDICATOR, indicatorGroup,
-            indicator, dataElementGroup, dataElement, periodType, period,
-            organisationUnit, organisationUnitLevel, MAPLEGENDSET_TYPE_AUTOMATIC, 1, 1, "A", "B",
+        MapView mapView = new MapView( LAYER_THEMATIC1, "MapViewA", VALUE_TYPE_INDICATOR, indicatorGroup,
+            indicator, dataElementGroup, dataElement, period,
+            organisationUnit, organisationUnitLevel, LEGEND_TYPE_AUTOMATIC, 1, 1, "A", "B",
             mapLegendSet, 5, 20, 1 );
 
         int idA = mappingService.addMapView( mapView );
@@ -275,16 +276,15 @@
         assertEquals( mapView, mappingService.getMapView( idA ) );
         assertEquals( indicatorGroup, mappingService.getMapView( idA ).getIndicatorGroup() );
         assertEquals( indicator, mappingService.getMapView( idA ).getIndicator() );
-        assertEquals( periodType, mappingService.getMapView( idA ).getPeriodType() );
         assertEquals( period, mappingService.getMapView( idA ).getPeriod() );
     }
 
     @Test
     public void testGetDeleteMapViewByName()
     {
-        MapView mapView = new MapView( LAYER_THEMATIC1, "MapViewA", MappingService.MAP_VALUE_TYPE_INDICATOR, indicatorGroup,
-            indicator, dataElementGroup, dataElement, periodType, period,
-            organisationUnit, organisationUnitLevel, MAPLEGENDSET_TYPE_AUTOMATIC, 1, 1, "A", "B",
+        MapView mapView = new MapView( LAYER_THEMATIC1, "MapViewA", VALUE_TYPE_INDICATOR, indicatorGroup,
+            indicator, dataElementGroup, dataElement, period,
+            organisationUnit, organisationUnitLevel, LEGEND_TYPE_AUTOMATIC, 1, 1, "A", "B",
             mapLegendSet, 5, 20, 1 );
 
         int id = mappingService.addMapView( mapView );
@@ -299,14 +299,14 @@
     @Test
     public void testGetAllMapViews()
     {
-        MapView mapView1 = new MapView( LAYER_THEMATIC1, "MapViewA", MappingService.MAP_VALUE_TYPE_INDICATOR, indicatorGroup,
-            indicator, dataElementGroup, dataElement, periodType, period,
-            organisationUnit, organisationUnitLevel, MAPLEGENDSET_TYPE_AUTOMATIC, 1, 1, "A", "B",
+        MapView mapView1 = new MapView( LAYER_THEMATIC1, "MapViewA", VALUE_TYPE_INDICATOR, indicatorGroup,
+            indicator, dataElementGroup, dataElement, period,
+            organisationUnit, organisationUnitLevel, LEGEND_TYPE_AUTOMATIC, 1, 1, "A", "B",
             mapLegendSet, 5, 20, 1 );
 
-        MapView mapView2 = new MapView( LAYER_THEMATIC1, "MapViewB", MappingService.MAP_VALUE_TYPE_DATAELEMENT, indicatorGroup,
-            indicator, dataElementGroup, dataElement, periodType, period,
-            organisationUnit, organisationUnitLevel, MAPLEGENDSET_TYPE_AUTOMATIC, 1, 1, "A", "B",
+        MapView mapView2 = new MapView( LAYER_THEMATIC1, "MapViewB", VALUE_TYPE_INDICATOR, indicatorGroup,
+            indicator, dataElementGroup, dataElement, period,
+            organisationUnit, organisationUnitLevel, LEGEND_TYPE_AUTOMATIC, 1, 1, "A", "B",
             mapLegendSet, 5, 20, 1 );
 
         mappingService.addMapView( mapView1 );

=== 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	2012-10-25 10:22:15 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMapGenerationService.java	2012-10-25 14:58:43 +0000
@@ -128,7 +128,7 @@
         Assert.isTrue( mapView != null );
         Assert.isTrue( mapView.getValueType() != null );
 
-        boolean isIndicator = MappingService.MAP_VALUE_TYPE_INDICATOR.equals( mapView.getValueType() );
+        boolean isIndicator = MapView.VALUE_TYPE_INDICATOR.equals( mapView.getValueType() );
 
         Collection<AggregatedMapValue> mapValues;
         

=== 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 13:19:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/mapping/MapController.java	2012-10-25 14:58:43 +0000
@@ -27,6 +27,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import static org.hisp.dhis.period.PeriodType.getPeriodFromIsoString;
+
 import java.awt.image.BufferedImage;
 import java.io.InputStream;
 
@@ -37,13 +39,18 @@
 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;
+import org.hisp.dhis.user.UserService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.stereotype.Controller;
@@ -69,7 +76,22 @@
 
     @Autowired
     private OrganisationUnitService organisationUnitService;
-
+    
+    @Autowired
+    private OrganisationUnitGroupService organisationUnitGroupService;
+    
+    @Autowired
+    private UserService userService;
+    
+    @Autowired
+    private IndicatorService indicatorService;
+    
+    @Autowired
+    private DataElementService dataElementService;
+    
+    @Autowired
+    private PeriodService periodService;
+        
     @Autowired
     private MapGenerationService mapGenerationService;
 
@@ -86,9 +108,59 @@
     {
         Map map = JacksonUtils.fromJson( input, Map.class );
         
-        for ( MapView mapView : map.getViews() )
-        {
-            mappingService.addMapView( mapView );
+        if ( map.getUser() != null )
+        {
+            map.setUser( userService.getUser( map.getUser().getUid() ) );
+        }
+        
+        for ( MapView view : map.getViews() )
+        {
+            if ( view.getIndicatorGroup() != null )
+            {
+                view.setIndicatorGroup( indicatorService.getIndicatorGroup( view.getIndicatorGroup().getUid() ) );
+            }
+            
+            if ( view.getIndicator() != null )
+            {
+                view.setIndicator( indicatorService.getIndicator( view.getIndicator().getUid() ) );
+            }
+            
+            if ( view.getDataElementGroup() != null )
+            {
+                view.setDataElementGroup( dataElementService.getDataElementGroup( view.getDataElementGroup().getUid() ) );
+            }
+            
+            if ( view.getDataElement() != null )
+            {
+                view.setDataElement( dataElementService.getDataElement( view.getDataElement().getUid() ) );
+            }
+            
+            if ( view.getPeriod() != null )
+            {
+                view.setPeriod( periodService.reloadPeriod( getPeriodFromIsoString( view.getPeriod().getUid() ) ) );
+            }
+            
+            if ( view.getParentOrganisationUnit() != null )
+            {
+                view.setParentOrganisationUnit( organisationUnitService.getOrganisationUnit( view.getParentOrganisationUnit().getUid() ) );
+            }
+            
+            if ( view.getOrganisationUnitLevel() != null )
+            {
+                view.setOrganisationUnitLevel( organisationUnitService.getOrganisationUnitLevel( view.getOrganisationUnitLevel().getUid() ) );
+            }
+            
+            if ( view.getLegendSet() != null )
+            {
+                view.setLegendSet( mappingService.getMapLegendSet( view.getLegendSet().getUid() ) );
+            }
+            
+            if ( view.getOrganisationUnitGroupSet() != null )
+            {
+                view.setOrganisationUnitGroupSet( organisationUnitGroupService.getOrganisationUnitGroupSet( view.getOrganisationUnitGroupSet().getUid() ) );
+            }
+            
+            mappingService.addMapView( view );
         }
         
         mappingService.addMap( map );