From 4ada8b78fc18585e5a67caf543a2b99eedb27066 Mon Sep 17 00:00:00 2001 From: Viet Nguyen Date: Tue, 11 Jun 2024 12:13:42 +0700 Subject: [PATCH] fix: api/maps/uid/data return error 500 --- .../dhis-service-reporting/pom.xml | 14 +++++++++++- .../dhis/mapgeneration/InternalMapObject.java | 2 +- .../mapgeneration/GeoToolsMapObjectTest.java | 22 +++++++++++++++++++ dhis-2/pom.xml | 13 +++++++++++ 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/dhis-2/dhis-services/dhis-service-reporting/pom.xml b/dhis-2/dhis-services/dhis-service-reporting/pom.xml index 66be700c0567..26091d8c2cab 100644 --- a/dhis-2/dhis-services/dhis-service-reporting/pom.xml +++ b/dhis-2/dhis-services/dhis-service-reporting/pom.xml @@ -206,7 +206,14 @@ org.locationtech.jts jts-core - + + org.geotools + gt-epsg-hsql + + + org.geotools + gt-cql + org.hisp.dhis @@ -243,6 +250,11 @@ mockito-junit-jupiter test + + org.geotools + gt-geojson + test + diff --git a/dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/mapgeneration/InternalMapObject.java b/dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/mapgeneration/InternalMapObject.java index 2f769a38b97c..62008824bb10 100644 --- a/dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/mapgeneration/InternalMapObject.java +++ b/dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/mapgeneration/InternalMapObject.java @@ -171,7 +171,7 @@ public SimpleFeatureType getFeatureType() { } try { - return DataUtilities.createType(GEOMETRIES, "geometry:" + type + ":srid=3785"); + return DataUtilities.createType(GEOMETRIES, "geometry:" + type + ":srid=3857"); } catch (SchemaException ex) { throw new RuntimeException("failed to create geometry", ex); } diff --git a/dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/mapgeneration/GeoToolsMapObjectTest.java b/dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/mapgeneration/GeoToolsMapObjectTest.java index 208e15f574f3..71169f368fec 100644 --- a/dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/mapgeneration/GeoToolsMapObjectTest.java +++ b/dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/mapgeneration/GeoToolsMapObjectTest.java @@ -27,11 +27,16 @@ */ package org.hisp.dhis.mapgeneration; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.awt.Color; +import java.io.IOException; +import org.geotools.geojson.geom.GeometryJSON; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.locationtech.jts.geom.Geometry; /** * @author Kenneth Solbø Andersen @@ -39,6 +44,11 @@ class GeoToolsMapObjectTest { private InternalMapObject geoToolsMapObject; + private GeometryJSON geometryJSON = new GeometryJSON(); + private String multiPolygonCoordinates = + "[[[[11.11,22.22],[33.33,44.44],[55.55,66.66],[11.11,22.22]]]," + + "[[[77.77,88.88],[99.99,11.11],[22.22,33.33],[77.77,88.88]]]," + + "[[[44.44,55.55],[66.66,77.77],[88.88,99.99],[44.44,55.55]]]]"; @BeforeEach void before() { @@ -92,4 +102,16 @@ void testSetGetStrokeColor() { geoToolsMapObject.setStrokeColor(Color.WHITE); assertEquals(Color.WHITE, geoToolsMapObject.getStrokeColor()); } + + @Test + void testCreateFeatureType() throws IOException { + Geometry geometry = + geometryJSON.read( + "{\"type\":\"MultiPolygon\", \"coordinates\":" + multiPolygonCoordinates + "}"); + geoToolsMapObject.setGeometry(geometry); + assertDoesNotThrow( + () -> { + assertNotNull(MapUtils.createFeatureLayerFromMapObject(geoToolsMapObject)); + }); + } } diff --git a/dhis-2/pom.xml b/dhis-2/pom.xml index 79f683621a8c..315ae180be7e 100644 --- a/dhis-2/pom.xml +++ b/dhis-2/pom.xml @@ -1355,6 +1355,16 @@ gt-referencing ${geotools.version} + + org.geotools + gt-epsg-hsql + ${geotools.version} + + + org.geotools + gt-cql + ${geotools.version} + @@ -2003,6 +2013,9 @@ jasperreports.version=${jasperreports.version} true org.projectlombok:lombok + org.geotools:gt-main + org.geotools:gt-epsg-hsql + org.geotools:gt-cql org.junit.jupiter:junit-jupiter org.springframework.security:spring-security-core net.sf.jasperreports:jasperreports