Search in sources :

Example 1 with JsonAttributeValue

use of org.hisp.dhis.webapi.json.domain.JsonAttributeValue in project dhis2-core by dhis2.

the class MetadataImportExportControllerTest method testPostValidGeoJsonAttribute.

@Test
void testPostValidGeoJsonAttribute() throws IOException {
    POST("/metadata", "{\"organisationUnits\": [ {\"id\":\"rXnqqH2Pu6N\",\"name\": \"My Unit 2\",\"shortName\": \"OU2\",\"openingDate\": \"2020-01-01\"," + "\"attributeValues\": [{\"value\":  \"{\\\"type\\\": \\\"Polygon\\\"," + "\\\"coordinates\\\":  [[[100,0],[101,0],[101,1],[100,1],[100,0]]] }\"," + "\"attribute\": {\"id\": \"RRH9IFiZZYN\"}}]}]," + "\"attributes\":[{\"id\":\"RRH9IFiZZYN\",\"valueType\":\"GEOJSON\",\"organisationUnitAttribute\":true,\"name\":\"testgeojson\"}]}").content(HttpStatus.OK);
    JsonIdentifiableObject organisationUnit = GET("/organisationUnits/{id}", "rXnqqH2Pu6N").content().asObject(JsonIdentifiableObject.class);
    assertEquals(1, organisationUnit.getAttributeValues().size());
    JsonAttributeValue attributeValue = organisationUnit.getAttributeValues().get(0);
    GeoJsonObject geoJSON = new ObjectMapper().readValue(attributeValue.getValue(), GeoJsonObject.class);
    assertTrue(geoJSON instanceof Polygon);
    Polygon polygon = (Polygon) geoJSON;
    assertEquals(100, polygon.getCoordinates().get(0).get(0).getLongitude());
}
Also used : JsonIdentifiableObject(org.hisp.dhis.webapi.json.domain.JsonIdentifiableObject) JsonAttributeValue(org.hisp.dhis.webapi.json.domain.JsonAttributeValue) GeoJsonObject(org.geojson.GeoJsonObject) Polygon(org.geojson.Polygon) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 GeoJsonObject (org.geojson.GeoJsonObject)1 Polygon (org.geojson.Polygon)1 DhisControllerConvenienceTest (org.hisp.dhis.webapi.DhisControllerConvenienceTest)1 JsonAttributeValue (org.hisp.dhis.webapi.json.domain.JsonAttributeValue)1 JsonIdentifiableObject (org.hisp.dhis.webapi.json.domain.JsonIdentifiableObject)1 Test (org.junit.jupiter.api.Test)1