Skip to content

Commit 283d3a7

Browse files
committed
CASSJAVA-108 Update ESRI (and remove org.json) dependencies
patch by Bret McGuire; reviewed by Bret McGuire and Lukasz Antoniak reference: #2052
1 parent deffb92 commit 283d3a7

9 files changed

Lines changed: 95 additions & 20 deletions

File tree

core/src/main/java/com/datastax/dse/driver/internal/core/data/geometry/DefaultGeometry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public boolean equals(Object o) {
176176
return false;
177177
}
178178
DefaultGeometry that = (DefaultGeometry) o;
179-
return this.getOgcGeometry().equals(that.getOgcGeometry());
179+
return this.getOgcGeometry().equals((Object) that.getOgcGeometry());
180180
}
181181

182182
@Override

core/src/test/java/com/datastax/dse/driver/internal/core/data/geometry/DefaultLineStringTest.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@
2222

2323
import com.datastax.dse.driver.api.core.data.geometry.LineString;
2424
import com.datastax.dse.driver.api.core.data.geometry.Point;
25+
import com.datastax.oss.driver.shaded.guava.common.collect.Streams;
2526
import com.esri.core.geometry.ogc.OGCLineString;
27+
import com.fasterxml.jackson.databind.JsonNode;
28+
import com.fasterxml.jackson.databind.ObjectMapper;
29+
import com.fasterxml.jackson.databind.node.ArrayNode;
2630
import java.nio.ByteBuffer;
2731
import java.nio.ByteOrder;
2832
import org.junit.Test;
@@ -101,8 +105,25 @@ public void should_parse_valid_geo_json() {
101105
}
102106

103107
@Test
104-
public void should_convert_to_geo_json() {
105-
assertThat(lineString.asGeoJson()).isEqualTo(json);
108+
public void should_convert_to_geo_json() throws Exception {
109+
110+
ObjectMapper mapper = new ObjectMapper();
111+
JsonNode root = mapper.readTree(lineString.asGeoJson());
112+
assertThat(root.get("type").toString()).isEqualTo("\"LineString\"");
113+
114+
double expected[][] = {{30.0, 10.0}, {10.0, 30.0}, {40.0, 40.0}};
115+
JsonNode coordinatesNode = root.get("coordinates");
116+
assertThat(coordinatesNode.isArray()).isTrue();
117+
ArrayNode coordinatesArray = (ArrayNode) coordinatesNode;
118+
assertThat(coordinatesArray.size()).isEqualTo(3);
119+
for (int i = 0; i < expected.length; ++i) {
120+
121+
JsonNode elemNode = coordinatesArray.get(i);
122+
assertThat(elemNode.isArray()).isTrue();
123+
ArrayNode elemArray = (ArrayNode) elemNode;
124+
double[] arr = Streams.stream(elemArray.elements()).mapToDouble(JsonNode::asDouble).toArray();
125+
assertThat(arr).isEqualTo(expected[i]);
126+
}
106127
}
107128

108129
@Test

core/src/test/java/com/datastax/dse/driver/internal/core/data/geometry/DefaultPointTest.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121
import static org.assertj.core.api.Fail.fail;
2222

2323
import com.datastax.dse.driver.api.core.data.geometry.Point;
24+
import com.datastax.oss.driver.shaded.guava.common.collect.Streams;
2425
import com.esri.core.geometry.ogc.OGCPoint;
26+
import com.fasterxml.jackson.databind.JsonNode;
27+
import com.fasterxml.jackson.databind.ObjectMapper;
28+
import com.fasterxml.jackson.databind.node.ArrayNode;
2529
import java.nio.ByteBuffer;
2630
import java.nio.ByteOrder;
2731
import org.junit.Test;
@@ -83,8 +87,19 @@ public void should_parse_valid_geo_json() {
8387
}
8488

8589
@Test
86-
public void should_convert_to_geo_json() {
87-
assertThat(point.asGeoJson()).isEqualTo(json);
90+
public void should_convert_to_geo_json() throws Exception {
91+
92+
ObjectMapper mapper = new ObjectMapper();
93+
JsonNode root = mapper.readTree(point.asGeoJson());
94+
assertThat(root.get("type").toString()).isEqualTo("\"Point\"");
95+
96+
double expected[] = {1.1, 2.2};
97+
JsonNode coordinatesNode = root.get("coordinates");
98+
assertThat(coordinatesNode.isArray()).isTrue();
99+
ArrayNode coordinatesArray = (ArrayNode) coordinatesNode;
100+
double[] arr =
101+
Streams.stream(coordinatesArray.elements()).mapToDouble(JsonNode::asDouble).toArray();
102+
assertThat(arr).isEqualTo(expected);
88103
}
89104

90105
@Test

core/src/test/java/com/datastax/dse/driver/internal/core/data/geometry/DefaultPolygonTest.java

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@
2323
import com.datastax.dse.driver.api.core.data.geometry.LineString;
2424
import com.datastax.dse.driver.api.core.data.geometry.Point;
2525
import com.datastax.dse.driver.api.core.data.geometry.Polygon;
26+
import com.datastax.oss.driver.shaded.guava.common.collect.Streams;
2627
import com.esri.core.geometry.ogc.OGCPolygon;
28+
import com.fasterxml.jackson.databind.JsonNode;
29+
import com.fasterxml.jackson.databind.ObjectMapper;
30+
import com.fasterxml.jackson.databind.node.ArrayNode;
2731
import java.nio.ByteBuffer;
2832
import java.nio.ByteOrder;
2933
import org.junit.Test;
@@ -109,8 +113,43 @@ public void should_parse_valid_geo_json() {
109113
}
110114

111115
@Test
112-
public void should_convert_to_geo_json() {
113-
assertThat(polygon.asGeoJson()).isEqualTo(json);
116+
public void should_convert_to_geo_json() throws Exception {
117+
118+
ObjectMapper mapper = new ObjectMapper();
119+
JsonNode root = mapper.readTree(polygon.asGeoJson());
120+
assertThat(root.get("type").toString()).isEqualTo("\"Polygon\"");
121+
122+
/*
123+
Note that the order of values in expected differs from the order of insertion when creating
124+
the Polygon. OGC expects the "exterior" ring of the polygon to be listed in counter-clockwise
125+
order... and that's what this sequence represents (draw it out on a graph if you don't believe me).
126+
127+
Weirdly this is the opposite of the order used for this test when we were using ESRI 1.2.1.
128+
That fact (combined with the fact that only ESRI classes are used for serialization here) makes me
129+
think that the earlier version was just doing it wrong... or at least doing it in a way that
130+
didn't agree with the spec. Either way it is clearly correct that we should go counter-clockwise...
131+
so that's what we're doing.
132+
*/
133+
double expected[][] = {{30.0, 10.0}, {40.0, 40.0}, {20.0, 40.0}, {10.0, 20.0}, {30.0, 10.0}};
134+
JsonNode coordinatesNode = root.get("coordinates");
135+
assertThat(coordinatesNode.isArray()).isTrue();
136+
ArrayNode coordinatesArray = (ArrayNode) coordinatesNode;
137+
138+
// There's an extra layer here, presumably indicating the bounds of the polygon
139+
assertThat(coordinatesArray.size()).isEqualTo(1);
140+
JsonNode polygonNode = coordinatesArray.get(0);
141+
assertThat(polygonNode.isArray()).isTrue();
142+
ArrayNode polygonArray = (ArrayNode) polygonNode;
143+
144+
assertThat(polygonArray.size()).isEqualTo(5);
145+
for (int i = 0; i < expected.length; ++i) {
146+
147+
JsonNode elemNode = polygonArray.get(i);
148+
assertThat(elemNode.isArray()).isTrue();
149+
ArrayNode elemArray = (ArrayNode) elemNode;
150+
double[] arr = Streams.stream(elemArray.elements()).mapToDouble(JsonNode::asDouble).toArray();
151+
assertThat(arr).isEqualTo(expected[i]);
152+
}
114153
}
115154

116155
@Test

core/src/test/java/com/datastax/dse/driver/internal/core/insights/PlatformInfoFinderTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ public void should_find_dependencies_from_file() {
8282
expected.put("com.github.jnr:jffi", withUnverifiedRuntimeVersion("1.2.16"));
8383
expected.put("io.netty:netty-buffer", withUnverifiedRuntimeVersion("4.0.56.Final"));
8484
expected.put("org.ow2.asm:asm-commons", withUnverifiedRuntimeVersion("5.0.3"));
85-
expected.put("org.json:json", withUnverifiedRuntimeVersion("20090211"));
8685
expected.put("org.ow2.asm:asm-util", withUnverifiedRuntimeVersion("5.0.3"));
8786
expected.put("com.github.jnr:jnr-ffi", withUnverifiedRuntimeVersion("2.1.7"));
8887

@@ -91,7 +90,7 @@ public void should_find_dependencies_from_file() {
9190
new PlatformInfoFinder(this::nullUrlProvider).fetchDependenciesFromFile(inputStream);
9291

9392
// then
94-
assertThat(stringStringMap).hasSize(28);
93+
assertThat(stringStringMap).hasSize(27);
9594
assertThat(stringStringMap).isEqualTo(expected);
9695
}
9796

core/src/test/resources/insights/test-dependencies.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,4 @@ The following files have been resolved:
2727
org.ow2.asm:asm-analysis:jar:5.0.3:compile
2828
com.github.jnr:jnr-x86asm:jar:1.0.2:compile
2929
io.netty:netty-codec:jar:4.0.56.Final:compile
30-
org.json:json:jar:20090211:compile
3130
com.github.jnr:jffi:jar:native:1.2.16:runtime

osgi-tests/src/test/java/com/datastax/oss/driver/internal/osgi/support/BundleOptions.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,10 @@ public static CompositeOption esriBundles() {
194194
CoreOptions.wrappedBundle(
195195
mavenBundle("com.esri.geometry", "esri-geometry-api").versionAsInProject())
196196
.exports("com.esri.core.geometry.*")
197-
.imports("org.json", "org.codehaus.jackson")
197+
.imports("com.fasterxml.jackson.*", "com.fasterxml.jackson.databind.*")
198198
.bundleSymbolicName("com.esri.core.geometry")
199199
.overwriteManifest(WrappedUrlProvisionOption.OverwriteMode.FULL),
200-
mavenBundle("org.json", "json").versionAsInProject(),
201-
mavenBundle("org.codehaus.jackson", "jackson-core-asl").versionAsInProject(),
200+
mavenBundle("com.fasterxml.jackson.core", "jackson-core").versionAsInProject(),
202201
systemProperty("cassandra.geo").value("true"));
203202
}
204203

pom.xml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
<hdrhistogram.version>2.1.12</hdrhistogram.version>
5959
<metrics.version>4.1.18</metrics.version>
6060
<netty.version>4.1.130.Final</netty.version>
61-
<esri.version>1.2.1</esri.version>
61+
<esri.version>2.2.4</esri.version>
6262
<!--
6363
When upgrading TinkerPop please upgrade the version matrix in
6464
manual/core/integration/README.md
@@ -68,7 +68,6 @@
6868
<slf4j.version>2.0.16</slf4j.version>
6969
<!-- when changing version also update version in LICENSE_binary -->
7070
<reactive-streams.version>1.0.3</reactive-streams.version>
71-
<json.version>20230227</json.version>
7271
<jackson.version>2.20.1</jackson.version>
7372
<jackson-databind.version>${jackson.version}</jackson-databind.version>
7473
<!-- optional dependencies -->
@@ -162,11 +161,6 @@
162161
<artifactId>esri-geometry-api</artifactId>
163162
<version>${esri.version}</version>
164163
</dependency>
165-
<dependency>
166-
<groupId>org.json</groupId>
167-
<artifactId>json</artifactId>
168-
<version>${json.version}</version>
169-
</dependency>
170164
<dependency>
171165
<groupId>org.apache.tinkerpop</groupId>
172166
<artifactId>gremlin-core</artifactId>

upgrade_guide/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ under the License.
1919

2020
## Upgrade guide
2121

22+
### 4.19.3
23+
24+
#### Ordering of points in DefaultPolygon
25+
26+
This version includes an update to the ESRI dependency which appears to be more strict about following the OGC
27+
requirement that points of a polygon should be returned in counter-clockwise order. It's possible that
28+
previous versions of the driver could have returned these points in a different order so if your application
29+
relies on the ordering of points in a polygon make sure to test this behaviour when upgrading.
30+
2231
### 4.18.1
2332

2433
#### Keystore reloading in DefaultSslEngineFactory

0 commit comments

Comments
 (0)