dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #19704
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8707: Map annotiations
------------------------------------------------------------
revno: 8707
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-10-25 15:19:00 +0200
message:
Map annotiations
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/Map.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/mapping/MappingServiceTest.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/Map.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/Map.java 2012-10-25 12:38:20 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/Map.java 2012-10-25 13:19:00 +0000
@@ -31,11 +31,23 @@
import java.util.Set;
import org.hisp.dhis.common.BaseIdentifiableObject;
+import org.hisp.dhis.common.Dxf2Namespace;
+import org.hisp.dhis.common.annotation.Scanned;
+import org.hisp.dhis.common.view.DetailedView;
+import org.hisp.dhis.common.view.ExportView;
import org.hisp.dhis.user.User;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonView;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+
/**
* @author Lars Helge Overland
*/
+@JacksonXmlRootElement( localName = "map", namespace = Dxf2Namespace.NAMESPACE )
public class Map
extends BaseIdentifiableObject
{
@@ -46,7 +58,8 @@
private String latitude;
private Integer zoom;
-
+
+ @Scanned
private Set<MapView> views = new HashSet<MapView>();
// -------------------------------------------------------------------------
@@ -70,6 +83,10 @@
// Getters and setters
// -------------------------------------------------------------------------
+ @JsonProperty
+ @JsonSerialize( as = BaseIdentifiableObject.class )
+ @JsonView( {DetailedView.class, ExportView.class} )
+ @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
public User getUser()
{
return user;
@@ -80,6 +97,9 @@
this.user = user;
}
+ @JsonProperty
+ @JsonView( {DetailedView.class, ExportView.class} )
+ @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
public String getLongitude()
{
return longitude;
@@ -90,6 +110,9 @@
this.longitude = longitude;
}
+ @JsonProperty
+ @JsonView( {DetailedView.class, ExportView.class} )
+ @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
public String getLatitude()
{
return latitude;
@@ -100,6 +123,9 @@
this.latitude = latitude;
}
+ @JsonProperty
+ @JsonView( {DetailedView.class, ExportView.class} )
+ @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
public Integer getZoom()
{
return zoom;
@@ -110,6 +136,10 @@
this.zoom = zoom;
}
+ @JsonProperty
+ @JsonView( {DetailedView.class, ExportView.class} )
+ @JacksonXmlElementWrapper( localName = "views", namespace = Dxf2Namespace.NAMESPACE )
+ @JacksonXmlProperty( localName = "mapView", namespace = Dxf2Namespace.NAMESPACE )
public Set<MapView> getViews()
{
return views;
=== 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 12:38:20 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java 2012-10-25 13:19:00 +0000
@@ -65,7 +65,7 @@
public static final String LAYER_THEMATIC2 = "thematic2";
public static final String LAYER_FACILITY = "facility";
public static final String LAYER_SYMBOL = "symbol";
-
+
private static final long serialVersionUID = 1866358818802275436L;
private String layer;
=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java 2012-06-05 15:36:07 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java 2012-10-25 13:19:00 +0000
@@ -114,7 +114,8 @@
exportClasses.put( ValidationRule.class, "validationRules" );
exportClasses.put( ValidationRuleGroup.class, "validationRuleGroups" );
- exportClasses.put( MapView.class, "maps" );
+ exportClasses.put( org.hisp.dhis.mapping.Map.class, "maps" );
+ exportClasses.put( MapView.class, "mapViews" );
exportClasses.put( MapLegend.class, "mapLegends" );
exportClasses.put( MapLegendSet.class, "mapLegendSets" );
exportClasses.put( MapLayer.class, "mapLayers" );
=== 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 12:38:20 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/mapping/MappingServiceTest.java 2012-10-25 13:19:00 +0000
@@ -31,8 +31,8 @@
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
-import static org.hisp.dhis.mapping.MappingService.*;
-import static org.hisp.dhis.mapping.MapView.*;
+import static org.hisp.dhis.mapping.MapView.LAYER_THEMATIC1;
+import static org.hisp.dhis.mapping.MappingService.MAPLEGENDSET_TYPE_AUTOMATIC;
import java.util.ArrayList;
import java.util.Collection;
@@ -54,7 +54,6 @@
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodService;
import org.hisp.dhis.period.PeriodType;
-import org.junit.Ignore;
import org.junit.Test;
/**
@@ -316,34 +315,6 @@
assertEquals( 2, mappingService.getAllMapViews().size() );
}
- @Test
- @Ignore
- // TODO
- public void testGetMapViewsByFeatureType()
- {
- 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",
- 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",
- mapLegendSet, 5, 20, 1 );
-
- MapView mapView3 = new MapView( LAYER_THEMATIC1, "MapViewC", MappingService.MAP_VALUE_TYPE_DATAELEMENT, indicatorGroup,
- indicator, dataElementGroup, dataElement, periodType, period,
- organisationUnit, organisationUnitLevel, MAPLEGENDSET_TYPE_AUTOMATIC, 1, 1, "A", "B",
- mapLegendSet, 5, 20, 1 );
-
- mappingService.addMapView( mapView1 );
- mappingService.addMapView( mapView2 );
- mappingService.addMapView( mapView3 );
-
- assertEquals( 1, mappingService.getMapViewsByFeatureType( OrganisationUnit.FEATURETYPE_POLYGON ).size() );
- assertEquals( 2, mappingService.getMapViewsByFeatureType( OrganisationUnit.FEATURETYPE_MULTIPOLYGON ).size() );
- }
-
// -------------------------------------------------------------------------
// MapLayer
// -------------------------------------------------------------------------
=== 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-05-28 14:25:12 +0000
+++ 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
@@ -27,14 +27,25 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.awt.image.BufferedImage;
+import java.io.InputStream;
+
+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.dxf2.utils.JacksonUtils;
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.OrganisationUnitService;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
@@ -42,12 +53,6 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
-import javax.imageio.ImageIO;
-import javax.servlet.http.HttpServletResponse;
-import java.awt.image.BufferedImage;
-
-import static org.hisp.dhis.api.utils.ContextUtils.CacheStrategy;
-
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
* @author Lars Helge Overland
@@ -71,6 +76,30 @@
@Autowired
private ContextUtils contextUtils;
+ //--------------------------------------------------------------------------
+ // CRUD
+ //--------------------------------------------------------------------------
+
+ @RequestMapping( method = RequestMethod.POST, consumes = "application/json" )
+ @PreAuthorize( "hasRole('F_GIS_ADMIN') or hasRole('ALL')" )
+ public void postJsonObject( HttpServletResponse response, HttpServletRequest request, InputStream input ) throws Exception
+ {
+ Map map = JacksonUtils.fromJson( input, Map.class );
+
+ for ( MapView mapView : map.getViews() )
+ {
+ mappingService.addMapView( mapView );
+ }
+
+ mappingService.addMap( map );
+
+ ContextUtils.createdResponse( response, "Map created", RESOURCE_PATH + "/" + map.getUid() );
+ }
+
+ //--------------------------------------------------------------------------
+ // Data
+ //--------------------------------------------------------------------------
+
@RequestMapping( value = { "/{uid}/data", "/{uid}/data.png" }, method = RequestMethod.GET )
public void getMap( @PathVariable String uid, HttpServletResponse response ) throws Exception
{
@@ -99,9 +128,9 @@
renderMapViewPng( mapView, response );
}
- //-------------------------------------------------------------------------------------------------------
+ //--------------------------------------------------------------------------
// Supportive methods
- //-------------------------------------------------------------------------------------------------------
+ //--------------------------------------------------------------------------
private void renderMapViewPng( MapView mapView, HttpServletResponse response )
throws Exception