DATAES-932 - GeoPoint - Point conversion is wrong.

Original PR: #521
This commit is contained in:
Peter-Josef Meisch
2020-09-20 21:28:25 +02:00
committed by GitHub
parent 5dc68600f4
commit 3edc5b0fb0
6 changed files with 59 additions and 42 deletions

View File

@@ -143,13 +143,13 @@ public class MappingElasticsearchConverterUnitTests {
observatoryRoad = new Address();
observatoryRoad.city = "Los Angeles";
observatoryRoad.street = "2800 East Observatory Road";
observatoryRoad.location = new Point(34.118347D, -118.3026284D);
observatoryRoad.location = new Point(-118.3026284D, 34.118347D);
bigBunsCafe = new Place();
bigBunsCafe.name = "Big Buns Cafe";
bigBunsCafe.city = "Los Angeles";
bigBunsCafe.street = "15 South Fremont Avenue";
bigBunsCafe.location = new Point(34.0945637D, -118.1545845D);
bigBunsCafe.location = new Point(-118.1545845D, 34.0945637D);
sarahAsMap = Document.create();
sarahAsMap.put("id", "sarah");
@@ -272,22 +272,44 @@ public class MappingElasticsearchConverterUnitTests {
}
@Test // DATAES-530
public void shouldMapGeoPointElasticsearchNames() {
public void shouldMapGeoPointElasticsearchNames() throws JSONException {
// given
Point point = new Point(10, 20);
String pointAsString = point.getX() + "," + point.getY();
double[] pointAsArray = { point.getX(), point.getY() };
double lon = 5;
double lat = 48;
Point point = new Point(lon, lat);
// ES has Strings in "lat,lon", but has arrays as [lon,lat]!!
String pointAsString = lat + "," + lon;
double[] pointAsArray = { lon, lat };
String expected = "{\n" + //
" \"pointA\": {\n" + //
" \"lon\": 5.0,\n" + //
" \"lat\": 48.0\n" + //
" },\n" + //
" \"pointB\": {\n" + //
" \"lon\": 5.0,\n" + //
" \"lat\": 48.0\n" + //
" },\n" + //
" \"pointC\": \"48.0,5.0\",\n" + //
" \"pointD\": [\n" + //
" 5.0,\n" + //
" 48.0\n" + //
" ]\n" + //
"}\n"; //
GeoEntity geoEntity = GeoEntity.builder().pointA(point).pointB(GeoPoint.fromPoint(point)).pointC(pointAsString)
.pointD(pointAsArray).build();
// when
String jsonResult = mappingElasticsearchConverter.mapObject(geoEntity).toJson();
// then
assertThat(jsonResult).contains(pointTemplate("pointA", point));
assertThat(jsonResult).contains(pointTemplate("pointB", point));
assertThat(jsonResult).contains(String.format(Locale.ENGLISH, "\"%s\":\"%s\"", "pointC", pointAsString));
assertThat(jsonResult)
.contains(String.format(Locale.ENGLISH, "\"%s\":[%.1f,%.1f]", "pointD", pointAsArray[0], pointAsArray[1]));
assertEquals(expected, jsonResult, false);
// assertThat(jsonResult).contains(pointTemplate("pointA", point));
// assertThat(jsonResult).contains(pointTemplate("pointB", point));
// assertThat(jsonResult).contains(String.format(Locale.ENGLISH, "\"%s\":\"%s\"", "pointC", pointAsString));
// assertThat(jsonResult)
// .contains(String.format(Locale.ENGLISH, "\"%s\":[%.1f,%.1f]", "pointD", pointAsArray[0], pointAsArray[1]));
}
@Test // DATAES-530
@@ -868,7 +890,7 @@ public class MappingElasticsearchConverterUnitTests {
}
private String pointTemplate(String name, Point point) {
return String.format(Locale.ENGLISH, "\"%s\":{\"lat\":%.1f,\"lon\":%.1f}", name, point.getX(), point.getY());
return String.format(Locale.ENGLISH, "\"%s\":{\"lat\":%.1f,\"lon\":%.1f}", name, point.getY(), point.getX());
}
private Map<String, Object> writeToMap(Object source) {

View File

@@ -302,7 +302,7 @@ public class ElasticsearchTemplateGeoTests {
// given
loadClassBaseEntities();
CriteriaQuery geoLocationCriteriaQuery3 = new CriteriaQuery(
new Criteria("location").boundedBy(new Point(53.5171d, 0), new Point(49.5171d, 0.2062d)));
new Criteria("location").boundedBy(new Point(0, 53.5171d), new Point(0.2062d, 49.5171d)));
// when
SearchHits<AuthorMarkerEntity> geoAuthorsForGeoCriteria3 = operations.search(geoLocationCriteriaQuery3,

View File

@@ -641,7 +641,6 @@ public class MappingBuilderTests extends MappingContextBaseTests {
String mapping = getMappingBuilder().buildPropertyMapping(RankFeatureEntity.class);
System.out.println(mapping);
assertEquals(expected, mapping, false);
}

View File

@@ -798,7 +798,7 @@ public abstract class CustomMethodRepositoryBaseTests {
repository.save(sampleEntity);
// when
Page<SampleEntity> page = repository.findByLocationWithin(new Point(45.7806d, 3.0875d),
Page<SampleEntity> page = repository.findByLocationWithin(new Point(3.0875d, 45.7806d),
new Distance(2, Metrics.KILOMETERS), PageRequest.of(0, 10));
// then
@@ -838,7 +838,7 @@ public abstract class CustomMethodRepositoryBaseTests {
assertThat(pageAll.getTotalElements()).isEqualTo(2L);
// when
Page<SampleEntity> page = repository.findByLocationNear(new Box(new Point(46d, 3d), new Point(45d, 4d)),
Page<SampleEntity> page = repository.findByLocationNear(new Box(new Point(3d, 46d), new Point(4d, 45d)),
PageRequest.of(0, 10));
// then
@@ -861,7 +861,7 @@ public abstract class CustomMethodRepositoryBaseTests {
repository.save(sampleEntity);
// when
Page<SampleEntity> page = repository.findByLocationNear(new Point(45.7806d, 3.0875d),
Page<SampleEntity> page = repository.findByLocationNear(new Point(3.0875d, 45.7806d),
new Distance(2, Metrics.KILOMETERS), PageRequest.of(0, 10));
// then
@@ -1334,7 +1334,7 @@ public abstract class CustomMethodRepositoryBaseTests {
repository.save(sampleEntity2);
// when
long count = repository.countByLocationWithin(new Point(45.7806d, 3.0875d), new Distance(2, Metrics.KILOMETERS));
long count = repository.countByLocationWithin(new Point(3.0875d, 45.7806d), new Distance(2, Metrics.KILOMETERS));
// then
assertThat(count).isEqualTo(1L);
@@ -1365,7 +1365,7 @@ public abstract class CustomMethodRepositoryBaseTests {
repository.save(sampleEntity2);
// when
long count = repository.countByLocationNear(new Box(new Point(46d, 3d), new Point(45d, 4d)));
long count = repository.countByLocationNear(new Box(new Point(3d, 46d), new Point(4d, 45d)));
// then
assertThat(count).isEqualTo(1L);
@@ -1396,7 +1396,7 @@ public abstract class CustomMethodRepositoryBaseTests {
repository.save(sampleEntity2);
// when
long count = repository.countByLocationNear(new Point(45.7806d, 3.0875d), new Distance(2, Metrics.KILOMETERS));
long count = repository.countByLocationNear(new Point(3.0875d, 45.7806d), new Distance(2, Metrics.KILOMETERS));
// then
assertThat(count).isEqualTo(1L);