Skip to content

GeoJson types can be lowercase in Elasticsearch. #1657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,19 @@ public GeoJson<? extends Iterable<?>> convert(Map<String, Object> source) {
String type = GeoConverters.getGeoJsonType(source);

switch (type) {
case GeoJsonPoint.TYPE:
case "point":
return MapToGeoJsonPointConverter.INSTANCE.convert(source);
case GeoJsonMultiPoint.TYPE:
case "multipoint":
return MapToGeoJsonMultiPointConverter.INSTANCE.convert(source);
case GeoJsonLineString.TYPE:
case "linestring":
return MapToGeoJsonLineStringConverter.INSTANCE.convert(source);
case GeoJsonMultiLineString.TYPE:
case "multilinestring":
return MapToGeoJsonMultiLineStringConverter.INSTANCE.convert(source);
case GeoJsonPolygon.TYPE:
case "polygon":
return MapToGeoJsonPolygonConverter.INSTANCE.convert(source);
case GeoJsonMultiPolygon.TYPE:
case "multipolygon":
return MapToGeoJsonMultiPolygonConverter.INSTANCE.convert(source);
case GeoJsonGeometryCollection.TYPE:
case "geometrycollection":
return MapToGeoJsonGeometryCollectionConverter.INSTANCE.convert(source);
default:
throw new IllegalArgumentException("unknown GeoJson type " + type);
Expand Down Expand Up @@ -217,7 +217,7 @@ public enum MapToGeoJsonPointConverter implements Converter<Map<String, Object>,
public GeoJsonPoint convert(Map<String, Object> source) {

String type = GeoConverters.getGeoJsonType(source);
Assert.isTrue(type.equals(GeoJsonPoint.TYPE), "does not contain a type 'Point'");
Assert.isTrue(type.equalsIgnoreCase(GeoJsonPoint.TYPE), "does not contain a type 'Point'");

Object coordinates = source.get("coordinates");
Assert.notNull(coordinates, "Document to convert does not contain coordinates");
Expand Down Expand Up @@ -255,7 +255,7 @@ public enum MapToGeoJsonMultiPointConverter implements Converter<Map<String, Obj
public GeoJsonMultiPoint convert(Map<String, Object> source) {

String type = GeoConverters.getGeoJsonType(source);
Assert.isTrue(type.equals(GeoJsonMultiPoint.TYPE), "does not contain a type 'MultiPoint'");
Assert.isTrue(type.equalsIgnoreCase(GeoJsonMultiPoint.TYPE), "does not contain a type 'MultiPoint'");
Object coordinates = source.get("coordinates");
Assert.notNull(coordinates, "Document to convert does not contain coordinates");
Assert.isTrue(coordinates instanceof List, "coordinates must be a List");
Expand Down Expand Up @@ -290,7 +290,7 @@ public enum MapToGeoJsonLineStringConverter implements Converter<Map<String, Obj
public GeoJsonLineString convert(Map<String, Object> source) {

String type = GeoConverters.getGeoJsonType(source);
Assert.isTrue(type.equals(GeoJsonLineString.TYPE), "does not contain a type 'LineString'");
Assert.isTrue(type.equalsIgnoreCase(GeoJsonLineString.TYPE), "does not contain a type 'LineString'");
Object coordinates = source.get("coordinates");
Assert.notNull(coordinates, "Document to convert does not contain coordinates");
Assert.isTrue(coordinates instanceof List, "coordinates must be a List");
Expand Down Expand Up @@ -322,7 +322,7 @@ public enum MapToGeoJsonMultiLineStringConverter implements Converter<Map<String
public GeoJsonMultiLineString convert(Map<String, Object> source) {

String type = GeoConverters.getGeoJsonType(source);
Assert.isTrue(type.equals(GeoJsonMultiLineString.TYPE), "does not contain a type 'MultiLineString'");
Assert.isTrue(type.equalsIgnoreCase(GeoJsonMultiLineString.TYPE), "does not contain a type 'MultiLineString'");
List<GeoJsonLineString> lines = geoJsonLineStringsFromMap(source);
return GeoJsonMultiLineString.of(lines);
}
Expand Down Expand Up @@ -350,7 +350,7 @@ public enum MapToGeoJsonPolygonConverter implements Converter<Map<String, Object
public GeoJsonPolygon convert(Map<String, Object> source) {

String type = GeoConverters.getGeoJsonType(source);
Assert.isTrue(type.equals(GeoJsonPolygon.TYPE), "does not contain a type 'Polygon'");
Assert.isTrue(type.equalsIgnoreCase(GeoJsonPolygon.TYPE), "does not contain a type 'Polygon'");
List<GeoJsonLineString> lines = geoJsonLineStringsFromMap(source);
Assert.isTrue(lines.size() > 0, "no linestrings defined in polygon");
GeoJsonPolygon geoJsonPolygon = GeoJsonPolygon.of(lines.get(0));
Expand Down Expand Up @@ -394,7 +394,7 @@ public enum MapToGeoJsonMultiPolygonConverter implements Converter<Map<String, O
public GeoJsonMultiPolygon convert(Map<String, Object> source) {

String type = GeoConverters.getGeoJsonType(source);
Assert.isTrue(type.equals(GeoJsonMultiPolygon.TYPE), "does not contain a type 'MultiPolygon'");
Assert.isTrue(type.equalsIgnoreCase(GeoJsonMultiPolygon.TYPE), "does not contain a type 'MultiPolygon'");
Object coordinates = source.get("coordinates");
Assert.notNull(coordinates, "Document to convert does not contain coordinates");
Assert.isTrue(coordinates instanceof List, "coordinates must be a List");
Expand Down Expand Up @@ -441,7 +441,8 @@ public enum MapToGeoJsonGeometryCollectionConverter
public GeoJsonGeometryCollection convert(Map<String, Object> source) {

String type = GeoConverters.getGeoJsonType(source);
Assert.isTrue(type.equals(GeoJsonGeometryCollection.TYPE), "does not contain a type 'GeometryCollection'");
Assert.isTrue(type.equalsIgnoreCase(GeoJsonGeometryCollection.TYPE),
"does not contain a type 'GeometryCollection'");
Object geometries = source.get("geometries");
Assert.notNull(geometries, "Document to convert does not contain geometries");
Assert.isTrue(geometries instanceof List, "geometries must be a List");
Expand All @@ -461,7 +462,7 @@ private static String getGeoJsonType(Map<String, Object> source) {
Assert.notNull(type, "Document to convert does not contain a type");
Assert.isTrue(type instanceof String, "type must be a String");

return type.toString();
return type.toString().toLowerCase();
}

private static List<Double> toCoordinates(Point point) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class GeoJsonTests {
@DisplayName("GeoJsonPoint")
class GeoJsonPointUnitTests {

// NOTE: the test converting from a map contains the type names in lowercase, that might be returned from
// Elasticsearch

@Test // DATAES-930
@DisplayName("should be converted to a Map")
void shouldBeConvertedToAMap() throws JSONException {
Expand All @@ -75,7 +78,7 @@ void shouldBeConvertedFromAMap() {

// make sure we can read int values as well
String json = "{\n" + //
" \"type\": \"Point\",\n" + //
" \"type\": \"point\",\n" + //
" \"coordinates\": [12, 34.0]\n" + //
"}"; //

Expand Down Expand Up @@ -117,8 +120,14 @@ void shouldBeConvertedToAMap() throws JSONException {
void shouldBeConvertedFromAMap() {

// make sure we can read int values as well
String json = "{\n" + " \"type\": \"MultiPoint\",\n" + " \"coordinates\": [\n" + " [12.0, 34],\n"
+ " [56, 78.0]\n" + " ]\n" + "}\n";
String json = "{\n" + //
" \"type\": \"multipoint\",\n" //
+ " \"coordinates\": [\n" + //
" [12.0, 34],\n" + //
" [56, 78.0]\n" + //
" ]\n" + //
"}\n"; //

Document document = Document.parse(json);

GeoJsonMultiPoint expected = GeoJsonMultiPoint.of(new Point(12, 34), new Point(56, 78));
Expand Down Expand Up @@ -158,7 +167,7 @@ void shouldBeConvertedFromAMap() {

// make sure we can read int values as well
String json = "{\n" + //
" \"type\": \"LineString\",\n" + //
" \"type\": \"linestring\",\n" + //
" \"coordinates\": [\n" + //
" [12.0, 34],\n" + //
" [56, 78.0]\n" //
Expand Down Expand Up @@ -205,7 +214,7 @@ void shouldBeConvertedToAMap() throws JSONException {
void shouldBeConvertedFromAMap() {
// make sure we can read int values as well
String json = "{\n" + //
" \"type\": \"MultiLineString\",\n" + //
" \"type\": \"multilinestring\",\n" + //
" \"coordinates\": [\n" + //
" [[12, 34.0], [56.0, 78]],\n" + //
" [[90.0, 12], [34, 56.0]]\n" + //
Expand Down Expand Up @@ -256,7 +265,7 @@ void shouldBeConvertedToAMap() throws JSONException {
void shouldBeConvertedFromAMap() {

String json = "{\n" + //
" \"type\": \"Polygon\",\n" + //
" \"type\": \"polygon\",\n" + //
" \"coordinates\": [\n" + //
" [[12, 34.0], [56.0, 78], [90, 12.0], [12, 34.0]],\n" + //
" [[56.0, 78], [90, 12.0], [34.0, 56], [56.0, 78]]\n" + //
Expand Down Expand Up @@ -308,7 +317,7 @@ void shouldBeConvertedToAMap() throws JSONException {
void shouldBeConvertedFromAMap() {

String json = "{\n" + //
" \"type\": \"MultiPolygon\",\n" + //
" \"type\": \"multipolygon\",\n" + //
" \"coordinates\": [\n" + //
" [[[12, 34.0], [56.0, 78], [90, 12.0], [12, 34.0]]],\n" + //
" [[[56, 78.0], [90, 12.0], [34.0, 56], [56, 78.0]]]\n" + //
Expand Down Expand Up @@ -369,14 +378,14 @@ void shouldBeConvertedToAMap() throws JSONException {
void shouldBeConvertedFromAMap() {

String json = "{\n" + //
" \"type\": \"GeometryCollection\",\n" + //
" \"type\": \"geometrycollection\",\n" + //
" \"geometries\": [\n" + //
" {\n" + //
" \"type\": \"Point\",\n" + //
" \"type\": \"point\",\n" + //
" \"coordinates\": [12.0, 34.0]\n" + //
" },\n" + //
" {\n" + //
" \"type\": \"Polygon\",\n" + //
" \"type\": \"polygon\",\n" + //
" \"coordinates\": [\n" + //
" [[12.0, 34.0], [56.0, 78.0], [90.0, 12.0], [12.0, 34.0]]\n" + //
" ]\n" + //
Expand Down