Skip to content

Commit

Permalink
fixed unit of measure of GeoResults distance (DE-803)
Browse files Browse the repository at this point in the history
  • Loading branch information
rashtao committed Jun 20, 2024
1 parent 7b29bff commit 0ac583f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,8 @@ private GeoResult<T> buildGeoResult(final ArangoCursor<JsonNode> cursor) {
*/
private GeoResult<T> buildGeoResult(final JsonNode slice) {
JsonNode distSlice = slice.get("_distance");
Double distanceInMeters = distSlice.isDouble() ? distSlice.doubleValue() : null;
T entity = operations.getConverter().read(domainClass, slice);
// FIXME: Unboxing of 'distanceInMeters' may produce 'NullPointerException'
Distance distance = new Distance(distanceInMeters / 1000, Metrics.KILOMETERS);
Distance distance = new Distance(distSlice.doubleValue() / 1000, Metrics.KILOMETERS).in(Metrics.NEUTRAL);
return new GeoResult<>(entity, distance);
}

Expand All @@ -159,9 +157,6 @@ private GeoResult<T> buildGeoResult(final JsonNode slice) {
private GeoResults<T> buildGeoResults(final ArangoCursor<JsonNode> cursor) {
final List<GeoResult<T>> list = new LinkedList<>();
cursor.forEachRemaining(o -> list.add(buildGeoResult(o)));
// FIXME: DE-803
// convert geoResults to Metrics.NEUTRAL before
// invoking GeoResults.GeoResults(java.util.List<? extends org.springframework.data.geo.GeoResult<T>>)
return new GeoResults<>(list);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ public void findAllByLocationWithinPageable() {
double expectedDistKm = distances.get(current.getContent()).in(Metrics.KILOMETERS).getValue();
assertThat(current.getContent()).isEqualTo(expected.get(i));
assertThat(current.getDistance().in(Metrics.KILOMETERS).getValue()).isCloseTo(expectedDistKm, withinPercentage(.01));
// FIXME: DE-803
// assertThat(page.getAverageDistance().in(Metrics.KILOMETERS).getValue()).isCloseTo(expectedDistKm, withinPercentage(.01));
assertThat(page.getAverageDistance().in(Metrics.KILOMETERS).getValue()).isCloseTo(expectedDistKm, withinPercentage(.01));
checkRefs(current.getContent());
}
}
Expand Down

0 comments on commit 0ac583f

Please sign in to comment.