mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-05-30 16:52:11 +00:00
GeoJson types can be lowercase in Elasticsearch.
Original Pull Request #1657 Closes #1655
This commit is contained in:
parent
89d6ae7f49
commit
159520d001
@ -172,19 +172,19 @@ public class GeoConverters {
|
||||
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);
|
||||
@ -217,7 +217,7 @@ public class GeoConverters {
|
||||
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");
|
||||
@ -255,7 +255,7 @@ public class GeoConverters {
|
||||
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");
|
||||
@ -290,7 +290,7 @@ public class GeoConverters {
|
||||
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");
|
||||
@ -322,7 +322,7 @@ public class GeoConverters {
|
||||
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);
|
||||
}
|
||||
@ -350,7 +350,7 @@ public class GeoConverters {
|
||||
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));
|
||||
@ -394,7 +394,7 @@ public class GeoConverters {
|
||||
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");
|
||||
@ -441,7 +441,8 @@ public class GeoConverters {
|
||||
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");
|
||||
@ -461,7 +462,7 @@ public class GeoConverters {
|
||||
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) {
|
||||
|
@ -53,6 +53,9 @@ class GeoConvertersUnitTests {
|
||||
@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 {
|
||||
@ -75,7 +78,7 @@ class GeoConvertersUnitTests {
|
||||
|
||||
// make sure we can read int values as well
|
||||
String json = "{\n" + //
|
||||
" \"type\": \"Point\",\n" + //
|
||||
" \"type\": \"point\",\n" + //
|
||||
" \"coordinates\": [12, 34.0]\n" + //
|
||||
"}"; //
|
||||
|
||||
@ -117,8 +120,14 @@ class GeoConvertersUnitTests {
|
||||
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));
|
||||
@ -158,7 +167,7 @@ class GeoConvertersUnitTests {
|
||||
|
||||
// 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" //
|
||||
@ -205,7 +214,7 @@ class GeoConvertersUnitTests {
|
||||
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" + //
|
||||
@ -256,7 +265,7 @@ class GeoConvertersUnitTests {
|
||||
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" + //
|
||||
@ -308,7 +317,7 @@ class GeoConvertersUnitTests {
|
||||
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" + //
|
||||
@ -369,14 +378,14 @@ class GeoConvertersUnitTests {
|
||||
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" + //
|
||||
|
Loading…
x
Reference in New Issue
Block a user