Skip to content
Snippets Groups Projects
Commit a81a219e authored by Sanjeev-SLB's avatar Sanjeev-SLB
Browse files

Rebase

parents 21b11e9b 9a59c105
No related branches found
No related tags found
1 merge request!214Broken pipe IOException handler
Pipeline #70558 failed
......@@ -418,8 +418,8 @@ The following software have components provided under the terms of this license:
- Jackson datatype: jdk8 (from https://repo1.maven.org/maven2/com/fasterxml/jackson/datatype/jackson-datatype-jdk8)
- Jackson extensions to the Google HTTP Client Library for Java. (from https://repo1.maven.org/maven2/com/google/http-client/google-http-client-jackson)
- Jackson module: Afterburner (from https://github.com/FasterXML/jackson-modules-base)
- Jackson module: JAXB Annotations (from https://github.com/FasterXML/jackson-modules-base)
- Jackson module: JAXB Annotations (from https://github.com/FasterXML/jackson-modules-base)
- Jackson module: Old JAXB Annotations (javax.xml.bind) (from https://github.com/FasterXML/jackson-modules-base)
- Jackson module: Old JAXB Annotations (javax.xml.bind) (from https://github.com/FasterXML/jackson-modules-base)
- Jackson-annotations (from http://github.com/FasterXML/jackson)
- Jackson-annotations (from http://github.com/FasterXML/jackson)
- Jackson-core (from https://github.com/FasterXML/jackson-core)
......@@ -468,6 +468,7 @@ The following software have components provided under the terms of this license:
- Maven Artifact Manager (from https://repo1.maven.org/maven2/org/apache/maven/maven-artifact-manager)
- Maven Core (from https://repo1.maven.org/maven2/org/apache/maven/maven-core)
- Maven Error Diagnostics (from https://repo1.maven.org/maven2/org/apache/maven/maven-error-diagnostics)
- Maven Local Settings Model (from https://repo1.maven.org/maven2/org/apache/maven/maven-settings)
- Maven Model (from https://repo1.maven.org/maven2/org/apache/maven/maven-model)
- Maven Monitor (from https://repo1.maven.org/maven2/org/apache/maven/maven-monitor)
- Maven Plugin API (from https://repo1.maven.org/maven2/org/apache/maven/maven-plugin-api)
......@@ -478,7 +479,6 @@ The following software have components provided under the terms of this license:
- Maven Project Builder (from https://repo1.maven.org/maven2/org/apache/maven/maven-project)
- Maven Reporting API (from https://repo1.maven.org/maven2/org/apache/maven/reporting/maven-reporting-api)
- Maven Repository Metadata Model (from https://repo1.maven.org/maven2/org/apache/maven/maven-repository-metadata)
- Maven Settings (from https://repo1.maven.org/maven2/org/apache/maven/maven-settings)
- Maven Wagon API (from https://repo1.maven.org/maven2/org/apache/maven/wagon/wagon-provider-api)
- Maven Wagon File Provider (from https://repo1.maven.org/maven2/org/apache/maven/wagon/wagon-file)
- Maven Wagon HTTP Shared Library (from https://repo1.maven.org/maven2/org/apache/maven/wagon/wagon-http-shared)
......@@ -538,8 +538,8 @@ The following software have components provided under the terms of this license:
- OAuth2 for Spring Security (from https://repo1.maven.org/maven2/org/springframework/security/oauth/spring-security-oauth2)
- OAuth2 for Spring Security (from https://repo1.maven.org/maven2/org/springframework/security/oauth/spring-security-oauth2)
- Objenesis (from http://objenesis.org)
- Okio (from https://github.com/square/okio/)
- Okio (from https://github.com/square/okio/)
- OkHttp URLConnection (from https://repo1.maven.org/maven2/com/squareup/okhttp3/okhttp-urlconnection)
- OkHttp URLConnection (from https://repo1.maven.org/maven2/com/squareup/okhttp3/okhttp-urlconnection)
- OpenCensus (from https://github.com/census-instrumentation/opencensus-java)
- OpenCensus (from https://github.com/census-instrumentation/opencensus-java)
- OpenCensus (from https://github.com/census-instrumentation/opencensus-java)
......@@ -670,10 +670,11 @@ The following software have components provided under the terms of this license:
- micrometer-registry-azure-monitor (from https://github.com/micrometer-metrics/micrometer)
- nio-multipart-parser (from )
- nio-stream-storage (from https://github.com/synchronoss/nio-stream-storage)
- okhttp (from https://github.com/square/okhttp)
- okhttp (from https://github.com/square/okhttp)
- okhttp-urlconnection (from https://github.com/square/okhttp)
- okhttp-urlconnection (from https://github.com/square/okhttp)
- okhttp (from https://square.github.io/okhttp/)
- okhttp (from https://square.github.io/okhttp/)
- okhttp-logging-interceptor (from https://square.github.io/okhttp/)
- okio (from https://github.com/square/okio/)
- okio (from https://github.com/square/okio/)
- org.conscrypt:conscrypt-openjdk-uber (from https://conscrypt.org/)
- org.xmlunit:xmlunit-core (from http://www.xmlunit.org/)
- parent-join (from https://github.com/elastic/elasticsearch)
......@@ -695,12 +696,14 @@ The following software have components provided under the terms of this license:
- rank-eval (from https://github.com/elastic/elasticsearch)
- resilience4j (from https://github.com/resilience4j/resilience4j)
- resilience4j (from https://resilience4j.readme.io)
- resilience4j (from https://github.com/resilience4j/resilience4j)
- resilience4j (from https://resilience4j.readme.io)
- resilience4j (from https://github.com/resilience4j/resilience4j)
- resilience4j (from https://resilience4j.readme.io)
- resilience4j (from https://github.com/resilience4j/resilience4j)
- resilience4j (from https://resilience4j.readme.io)
- resilience4j (from https://resilience4j.readme.io)
- resilience4j (from https://resilience4j.readme.io)
- rest (from https://github.com/elastic/elasticsearch)
- rest-high-level (from https://github.com/elastic/elasticsearch)
- rxjava (from https://github.com/ReactiveX/RxJava)
......@@ -1174,7 +1177,7 @@ The following software have components provided under the terms of this license:
- Javassist (from http://www.javassist.org/)
- Javassist (from http://www.javassist.org/)
- RabbitMQ Java Client (from http://www.rabbitmq.com)
- okhttp (from https://github.com/square/okhttp)
- okhttp (from https://square.github.io/okhttp/)
========================================================================
MS-RL
......
......@@ -14,8 +14,10 @@
package org.opengroup.osdu.indexer.model.geojson;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;
import org.opengroup.osdu.indexer.model.geojson.jackson.FeatureCollectionDeserializer;
import org.opengroup.osdu.indexer.model.geojson.jackson.FeatureCollectionSerializer;
import java.util.ArrayList;
......@@ -25,6 +27,7 @@ import java.util.List;
@Data
@JsonSerialize(using = FeatureCollectionSerializer.class)
@JsonDeserialize(using = FeatureCollectionDeserializer.class)
public class FeatureCollection extends GeoJsonObject implements Iterable<Feature> {
private List<Feature> features = new ArrayList<Feature>();
......
......@@ -29,7 +29,6 @@ import java.io.Serializable;
@Getter
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
@AllArgsConstructor
@JsonDeserialize(using = PositionDeserializer.class)
@JsonSerialize(using = PositionSerializer.class)
public class Position implements Serializable {
......@@ -44,6 +43,12 @@ public class Position implements Serializable {
this.setLatitude(latitude);
}
public Position(double longitude, double latitude, double altitude) {
this.setLongitude(longitude);
this.setLatitude(latitude);
this.altitude = altitude;
}
public void setLongitude(double longitude) {
if (Double.isNaN(longitude))
throw new IllegalArgumentException("latitude must be number");
......
// Copyright © Schlumberger
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.opengroup.osdu.indexer.model.geojson.jackson;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import org.opengroup.osdu.indexer.model.geojson.Feature;
import org.opengroup.osdu.indexer.model.geojson.FeatureCollection;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class FeatureCollectionDeserializer extends JsonDeserializer<FeatureCollection> {
@Override
public FeatureCollection deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
FeatureCollection featureCollection = new FeatureCollection();
featureCollection.setFeatures(extractFeature(jsonParser));
return featureCollection;
}
private List<Feature> extractFeature(JsonParser jsonParser) throws IOException {
ObjectCodec codec = jsonParser.getCodec();
JsonNode featureCollection = codec.readTree(jsonParser);
JsonNode features = featureCollection.get("features");
final List<Feature> result = new ArrayList<>();
for (JsonNode node : features) {
result.add(codec.treeToValue(node, Feature.class));
}
return result;
}
}
......@@ -34,7 +34,6 @@ public class FeatureCollectionSerializer extends JsonSerializer<FeatureCollectio
jsonGenerator.writeArrayFieldStart("geometries");
for (Feature feature : value.getFeatures()) {
jsonGenerator.writeStartObject();
if (feature.getGeometry() instanceof GeometryCollection) {
GeometryCollection geometryCollection = (GeometryCollection) feature.getGeometry();
for (GeoJsonObject shape : geometryCollection.getGeometries()) {
......@@ -43,7 +42,6 @@ public class FeatureCollectionSerializer extends JsonSerializer<FeatureCollectio
} else {
serializeGeoShape(feature.getGeometry(), jsonGenerator);
}
jsonGenerator.writeEndObject();
}
jsonGenerator.writeEndArray();
......@@ -59,23 +57,35 @@ public class FeatureCollectionSerializer extends JsonSerializer<FeatureCollectio
private void serializeGeoShape(GeoJsonObject geoJsonObject, JsonGenerator jsonGenerator) throws IOException {
if (geoJsonObject instanceof Point) {
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField("type", "point");
jsonGenerator.writeObjectField("coordinates", ((Point) geoJsonObject).getCoordinates());
jsonGenerator.writeEndObject();
} else if (geoJsonObject instanceof LineString) {
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField("type", "linestring");
jsonGenerator.writeObjectField("coordinates", ((LineString) geoJsonObject).getCoordinates());
jsonGenerator.writeEndObject();
} else if (geoJsonObject instanceof Polygon) {
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField("type", "polygon");
jsonGenerator.writeObjectField("coordinates", ((Polygon) geoJsonObject).getCoordinates());
jsonGenerator.writeEndObject();
} else if (geoJsonObject instanceof MultiPoint) {
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField("type", "multipoint");
jsonGenerator.writeObjectField("coordinates", ((MultiPoint) geoJsonObject).getCoordinates());
jsonGenerator.writeEndObject();
} else if (geoJsonObject instanceof MultiLineString) {
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField("type", "multilinestring");
jsonGenerator.writeObjectField("coordinates", ((MultiLineString) geoJsonObject).getCoordinates());
jsonGenerator.writeEndObject();
} else if (geoJsonObject instanceof MultiPolygon) {
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField("type", "multipolygon");
jsonGenerator.writeObjectField("coordinates", ((MultiPolygon) geoJsonObject).getCoordinates());
jsonGenerator.writeEndObject();
}
}
}
......@@ -44,122 +44,140 @@ public class GeoShapeParserTest {
public void should_throwException_provided_emptyGeoJson() {
String shapeJson = "{}";
this.validateInput(this.sut::parseGeoJson, shapeJson, "shape not included");
this.validateInput(this.sut::parseGeoJson, shapeJson, Strings.EMPTY, "shape not included");
}
@Test
public void should_throwException_parseInvalidPoint() {
String shapeJson = "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-205.01621,39.57422]}}]}";
this.validateInput(this.sut::parseGeoJson, shapeJson, "unable to parse FeatureCollection");
this.validateInput(this.sut::parseGeoJson, shapeJson, Strings.EMPTY, "unable to parse FeatureCollection");
}
@Test
public void should_throwException_parseInvalidPoint_NaN() {
String shapeJson = "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-205.01621,NaN]}}]}";
this.validateInput(this.sut::parseGeoJson, shapeJson, "unable to parse FeatureCollection");
this.validateInput(this.sut::parseGeoJson, shapeJson, Strings.EMPTY, "unable to parse FeatureCollection");
}
@Test
public void should_throwException_parseInvalidPoint_missingLatitude() {
String shapeJson = "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-105.01621]}}]}";
this.validateInput(this.sut::parseGeoJson, shapeJson, "unable to parse FeatureCollection");
this.validateInput(this.sut::parseGeoJson, shapeJson, Strings.EMPTY, "unable to parse FeatureCollection");
}
@Test
public void should_throwException_missingMandatoryAttribute() {
String shapeJson = "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"geometry\":{\"mistype\":\"Point\",\"coordinates\":[-205.01621,39.57422]}}]}";
this.validateInput(this.sut::parseGeoJson, shapeJson, "must be a valid FeatureCollection");
this.validateInput(this.sut::parseGeoJson, shapeJson, Strings.EMPTY, "must be a valid FeatureCollection");
}
@Test
public void should_throwException_parseInvalidShape() {
String shapeJson = "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"geometry\":{\"type\":\"InvalidShape\",\"coordinates\":[-105.01621,39.57422]}}]}";
this.validateInput(this.sut::parseGeoJson, shapeJson, "must be a valid FeatureCollection");
this.validateInput(this.sut::parseGeoJson, shapeJson, Strings.EMPTY, "must be a valid FeatureCollection");
}
@Test
public void should_parseValidPoint() {
String shapeJson = "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-105.01621,39.57422]}}]}";
String expectedParsedShape = "{\"type\":\"geometrycollection\",\"geometries\":[{\"type\":\"point\",\"coordinates\":[-105.01621,39.57422]}]}";
this.validateInput(this.sut::parseGeoJson, shapeJson, Strings.EMPTY);
this.validateInput(this.sut::parseGeoJson, shapeJson, expectedParsedShape, Strings.EMPTY);
}
@Test
public void should_parseValidMultiPoint() {
String shapeJson = "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"geometry\":{\"type\":\"MultiPoint\",\"coordinates\":[[-105.01621,39.57422],[-80.666513,35.053994]]}}]}";
String expectedParsedShape = "{\"type\":\"geometrycollection\",\"geometries\":[{\"type\":\"multipoint\",\"coordinates\":[[-105.01621,39.57422],[-80.666513,35.053994]]}]}";
this.validateInput(this.sut::parseGeoJson, shapeJson, Strings.EMPTY);
this.validateInput(this.sut::parseGeoJson, shapeJson, expectedParsedShape, Strings.EMPTY);
}
@Test
public void should_parseValidLineString() {
String shapeJson = "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"geometry\":{\"type\":\"LineString\",\"coordinates\":[[-101.744384,39.32155],[-101.552124,39.330048],[-101.403808,39.330048],[-101.332397,39.364032],[-101.041259,39.368279],[-100.975341,39.304549],[-100.914916,39.245016],[-100.843505,39.164141],[-100.805053,39.104488],[-100.491943,39.100226],[-100.437011,39.095962],[-100.338134,39.095962],[-100.195312,39.027718],[-100.008544,39.010647],[-99.865722,39.00211],[-99.684448,38.972221],[-99.51416,38.929502],[-99.382324,38.920955],[-99.321899,38.895308],[-99.113159,38.869651],[-99.0802,38.85682],[-98.822021,38.85682],[-98.448486,38.848264],[-98.206787,38.848264],[-98.020019,38.878204],[-97.635498,38.873928]]}}]}";
String expectedParsedShape = "{\"type\":\"geometrycollection\",\"geometries\":[{\"type\":\"linestring\",\"coordinates\":[[-101.744384,39.32155],[-101.552124,39.330048],[-101.403808,39.330048],[-101.332397,39.364032],[-101.041259,39.368279],[-100.975341,39.304549],[-100.914916,39.245016],[-100.843505,39.164141],[-100.805053,39.104488],[-100.491943,39.100226],[-100.437011,39.095962],[-100.338134,39.095962],[-100.195312,39.027718],[-100.008544,39.010647],[-99.865722,39.00211],[-99.684448,38.972221],[-99.51416,38.929502],[-99.382324,38.920955],[-99.321899,38.895308],[-99.113159,38.869651],[-99.0802,38.85682],[-98.822021,38.85682],[-98.448486,38.848264],[-98.206787,38.848264],[-98.020019,38.878204],[-97.635498,38.873928]]}]}";
this.validateInput(this.sut::parseGeoJson, shapeJson, Strings.EMPTY);
this.validateInput(this.sut::parseGeoJson, shapeJson, expectedParsedShape, Strings.EMPTY);
}
@Test
public void should_parseValidMultiLineString() {
String shapeJson = "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"geometry\":{\"type\":\"MultiLineString\",\"coordinates\":[[[-105.021443,39.578057],[-105.021507,39.577809],[-105.021572,39.577495],[-105.021572,39.577164],[-105.021572,39.577032],[-105.021529,39.576784]],[[-105.019898,39.574997],[-105.019598,39.574898],[-105.019061,39.574782]],[[-105.017173,39.574402],[-105.01698,39.574385],[-105.016636,39.574385],[-105.016508,39.574402],[-105.01595,39.57427]],[[-105.014276,39.573972],[-105.014126,39.574038],[-105.013825,39.57417],[-105.01331,39.574452]]]}}]}";
String expectedParsedShape = "{\"type\":\"geometrycollection\",\"geometries\":[{\"type\":\"multilinestring\",\"coordinates\":[[[-105.021443,39.578057],[-105.021507,39.577809],[-105.021572,39.577495],[-105.021572,39.577164],[-105.021572,39.577032],[-105.021529,39.576784]],[[-105.019898,39.574997],[-105.019598,39.574898],[-105.019061,39.574782]],[[-105.017173,39.574402],[-105.01698,39.574385],[-105.016636,39.574385],[-105.016508,39.574402],[-105.01595,39.57427]],[[-105.014276,39.573972],[-105.014126,39.574038],[-105.013825,39.57417],[-105.01331,39.574452]]]}]}";
this.validateInput(this.sut::parseGeoJson, shapeJson, Strings.EMPTY);
this.validateInput(this.sut::parseGeoJson, shapeJson, expectedParsedShape, Strings.EMPTY);
}
@Test
public void should_parseValidPolygon() {
String shapeJson = "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[100,0],[101,0],[101,1],[100,1],[100,0]]]}}]}";
String expectedParsedShape = "{\"type\":\"geometrycollection\",\"geometries\":[{\"type\":\"polygon\",\"coordinates\":[[[100.0,0.0],[101.0,0.0],[101.0,1.0],[100.0,1.0],[100.0,0.0]]]}]}";
this.validateInput(this.sut::parseGeoJson, shapeJson, Strings.EMPTY);
this.validateInput(this.sut::parseGeoJson, shapeJson, expectedParsedShape, Strings.EMPTY);
}
@Test
public void should_throwException_parseInvalidPolygon_malformedLatitude() {
String shapeJson = "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[100,\"afgg\"],[101,0],[101,1],[100,1],[100,0]]]}}]}";
this.validateInput(this.sut::parseGeoJson, shapeJson, "unable to parse FeatureCollection");
this.validateInput(this.sut::parseGeoJson, shapeJson, Strings.EMPTY, "unable to parse FeatureCollection");
}
@Test
public void should_parseValidMultiPolygon() {
String shapeJson = "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"geometry\":{\"type\":\"MultiPolygon\",\"coordinates\":[[[[107,7],[108,7],[108,8],[107,8],[107,7]]],[[[100,0],[101,0],[101,1],[100,1],[100,0]]]]}}]}";
String expectedParsedShape = "{\"type\":\"geometrycollection\",\"geometries\":[{\"type\":\"multipolygon\",\"coordinates\":[[[[107.0,7.0],[108.0,7.0],[108.0,8.0],[107.0,8.0],[107.0,7.0]]],[[[100.0,0.0],[101.0,0.0],[101.0,1.0],[100.0,1.0],[100.0,0.0]]]]}]}";
this.validateInput(this.sut::parseGeoJson, shapeJson, Strings.EMPTY);
this.validateInput(this.sut::parseGeoJson, shapeJson, expectedParsedShape, Strings.EMPTY);
}
@Test
public void should_parseValidGeometryCollection() {
String shapeJson = "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"geometry\":{\"type\":\"GeometryCollection\",\"geometries\":[{\"type\":\"Point\",\"coordinates\":[-80.660805,35.049392]},{\"type\":\"Polygon\",\"coordinates\":[[[-80.664582,35.044965],[-80.663874,35.04428],[-80.662586,35.04558],[-80.663444,35.046036],[-80.664582,35.044965]]]},{\"type\":\"LineString\",\"coordinates\":[[-80.662372,35.059509],[-80.662693,35.059263],[-80.662844,35.05893],[-80.66308,35.058332],[-80.663595,35.057753],[-80.663874,35.057401],[-80.66441,35.057033],[-80.664861,35.056787],[-80.665419,35.056506],[-80.665633,35.056312],[-80.666019,35.055891],[-80.666191,35.055452],[-80.666191,35.055171],[-80.666255,35.05489],[-80.666213,35.054222],[-80.666213,35.053924],[-80.665955,35.052905],[-80.665698,35.052044],[-80.665504,35.051482],[-80.665762,35.050481],[-80.66617,35.049725],[-80.666513,35.049286],[-80.666921,35.048531],[-80.667006,35.048215],[-80.667071,35.047775],[-80.667049,35.047389],[-80.666964,35.046985],[-80.666813,35.046353],[-80.666599,35.045966],[-80.666406,35.045615],[-80.665998,35.045193],[-80.665526,35.044877],[-80.664989,35.044543],[-80.664496,35.044174],[-80.663852,35.043876],[-80.663037,35.043717]]}]}}]}";
String expectedParsedShape = "{\"type\":\"geometrycollection\",\"geometries\":[{\"type\":\"point\",\"coordinates\":[-80.660805,35.049392]},{\"type\":\"polygon\",\"coordinates\":[[[-80.664582,35.044965],[-80.663874,35.04428],[-80.662586,35.04558],[-80.663444,35.046036],[-80.664582,35.044965]]]},{\"type\":\"linestring\",\"coordinates\":[[-80.662372,35.059509],[-80.662693,35.059263],[-80.662844,35.05893],[-80.66308,35.058332],[-80.663595,35.057753],[-80.663874,35.057401],[-80.66441,35.057033],[-80.664861,35.056787],[-80.665419,35.056506],[-80.665633,35.056312],[-80.666019,35.055891],[-80.666191,35.055452],[-80.666191,35.055171],[-80.666255,35.05489],[-80.666213,35.054222],[-80.666213,35.053924],[-80.665955,35.052905],[-80.665698,35.052044],[-80.665504,35.051482],[-80.665762,35.050481],[-80.66617,35.049725],[-80.666513,35.049286],[-80.666921,35.048531],[-80.667006,35.048215],[-80.667071,35.047775],[-80.667049,35.047389],[-80.666964,35.046985],[-80.666813,35.046353],[-80.666599,35.045966],[-80.666406,35.045615],[-80.665998,35.045193],[-80.665526,35.044877],[-80.664989,35.044543],[-80.664496,35.044174],[-80.663852,35.043876],[-80.663037,35.043717]]}]}";
this.validateInput(this.sut::parseGeoJson, shapeJson, Strings.EMPTY);
this.validateInput(this.sut::parseGeoJson, shapeJson, expectedParsedShape, Strings.EMPTY);
}
@Test
public void should_parseValidFeatureCollection() {
String shapeJson = "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[1.9496737127045984,58.41415669686543],[1.8237672363511042,58.42946998193435],[1.8422735102001124,58.471472136376455],[1.9683241046247606,58.45614207250076],[1.9496737127045984,58.41415669686543]]]}}]}";
String expectedParsedShape = "{\"type\":\"geometrycollection\",\"geometries\":[{\"type\":\"polygon\",\"coordinates\":[[[1.9496737127045984,58.41415669686543],[1.8237672363511042,58.42946998193435],[1.8422735102001124,58.471472136376455],[1.9683241046247606,58.45614207250076],[1.9496737127045984,58.41415669686543]]]}]}";
this.validateInput(this.sut::parseGeoJson, shapeJson, Strings.EMPTY);
this.validateInput(this.sut::parseGeoJson, shapeJson, expectedParsedShape, Strings.EMPTY);
}
@Test
public void should_parseValidFeatureCollection_withZCoordinate() {
String shapeJson = "{\"type\":\"FeatureCollection\",\"bbox\":null,\"features\":[{\"type\":\"Feature\",\"bbox\":null,\"geometry\":{\"type\":\"Point\",\"bbox\":null,\"coordinates\":[5.7500000010406245,59.000000000399105, 1.0]},\"properties\":{}}],\"properties\":{},\"persistableReferenceCrs\":null,\"persistableReferenceUnitZ\":\"{\\\"scaleOffset\\\":{\\\"scale\\\":1.0,\\\"offset\\\":0.0},\\\"symbol\\\":\\\"m\\\",\\\"baseMeasurement\\\":{\\\"ancestry\\\":\\\"Length\\\",\\\"type\\\":\\\"UM\\\"},\\\"type\\\":\\\"USO\\\"}\"}";
String expectedParsedShape = "{\"type\":\"geometrycollection\",\"geometries\":[{\"type\":\"point\",\"coordinates\":[5.7500000010406245,59.000000000399105,1.0]}]}";
this.validateInput(this.sut::parseGeoJson, shapeJson, expectedParsedShape, Strings.EMPTY);
}
@Test
public void should_throwException_parseUnsupportedType_feature() {
String shapeJson = "{\"type\":\"Feature\",\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[-80.724878,35.265454],[-80.722646,35.260338],[-80.720329,35.260618],[-80.718698,35.260267],[-80.715093,35.260548],[-80.71681,35.255361],[-80.710887,35.255361],[-80.703248,35.265033],[-80.704793,35.268397],[-80.70857,35.268257],[-80.712518,35.270359],[-80.715179,35.267696],[-80.721359,35.267276],[-80.724878,35.265454]]]},\"properties\":{\"name\":\"Plaza Road Park\"}}";
this.validateInput(this.sut::parseGeoJson, shapeJson, "must be a valid FeatureCollection");
this.validateInput(this.sut::parseGeoJson, shapeJson, Strings.EMPTY, "must be a valid FeatureCollection");
}
private void validateInput(Function<Map<String, Object>, Map<String, Object>> parser, String shapeJson, String errorMessage) {
private void validateInput(Function<Map<String, Object>, Map<String, Object>> parser, String shapeJson, String expectedParsedShape, String errorMessage) {
try {
Type type = new TypeToken<Map<String, Object>>() {}.getType();
Map<String, Object> shapeObj = new Gson().fromJson(shapeJson, type);
Map<String, Object> expectedShape = new Gson().fromJson(expectedParsedShape, type);
Map<String, Object> parsedShape = parser.apply(shapeObj);
assertNotNull(parsedShape);
assertTrue(Strings.isNullOrEmpty(errorMessage));
assertTrue(parsedShape.equals(expectedShape));
} catch (IllegalArgumentException e) {
if (Strings.isNullOrEmpty(errorMessage)) {
fail(String.format("error parsing valid geo-json %s", shapeJson));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment