Skip to content

Commit d4a712a

Browse files
author
a-brandt
committed
ShortestPathEntity updates
1 parent 649d5cc commit d4a712a

File tree

4 files changed

+29
-17
lines changed

4 files changed

+29
-17
lines changed

src/main/java/com/arangodb/ArangoDriver.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5320,6 +5320,10 @@ public <V, E> ShortestPathEntity<V, E> graphGetShortesPath(
53205320
Class<V> vertexClass,
53215321
Class<E> edgeClass) throws ArangoException {
53225322

5323+
if (shortestPathOptions == null) {
5324+
shortestPathOptions = new ShortestPathOptions();
5325+
}
5326+
53235327
return cursorDriver.getShortesPath(getDefaultDatabase(), graphName, startVertexExample, endVertexExample,
53245328
shortestPathOptions, getDefaultAqlQueryOptions(), vertexClass, edgeClass);
53255329
}

src/main/java/com/arangodb/entity/EntityDeserializers.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,23 +1969,32 @@ public static class ShortestPathEntityDeserializer implements JsonDeserializer<S
19691969
edgeClazz = nextParameterized();
19701970
}
19711971

1972-
if (result.has("vertex")) {
1973-
if (result.get("vertex").isJsonObject()) {
1974-
entity.setVertex(result.getAsJsonObject("vertex").getAsJsonPrimitive("_id").getAsString());
1975-
} else if (result.get("vertex").isJsonPrimitive()) {
1976-
entity.setVertex(result.getAsJsonPrimitive("vertex").getAsString());
1977-
}
1978-
}
19791972
if (result.has("distance")) {
19801973
entity.setDistance(result.get("distance").getAsLong());
19811974
} else {
19821975
entity.setDistance(-1L);
19831976
}
1984-
if (result.has("startVertex")) {
1985-
entity.setStartVertex(result.get("startVertex").getAsString());
1977+
if (result.has("edges")) {
1978+
// new version >= 2.6
1979+
entity.setEdges(getEdges(edgeClazz, context, result.getAsJsonArray("edges")));
1980+
}
1981+
if (result.has("vertices")) {
1982+
// new version >= 2.6
1983+
entity.setVertices(getVertices(vertexClazz, context, result.getAsJsonArray("vertices")));
19861984
}
19871985
if (result.has("paths")) {
1988-
entity.setPaths(getPaths(context, result, vertexClazz, edgeClazz));
1986+
// old version < 2.6
1987+
JsonArray paths = result.getAsJsonArray("paths");
1988+
if (!paths.equals(null) && paths.size() > 0) {
1989+
JsonObject path = paths.get(0).getAsJsonObject();
1990+
1991+
if (path.has("edges")) {
1992+
entity.setEdges(getEdges(edgeClazz, context, path.getAsJsonArray("edges")));
1993+
}
1994+
if (path.has("vertices")) {
1995+
entity.setVertices(getVertices(vertexClazz, context, path.getAsJsonArray("vertices")));
1996+
}
1997+
}
19891998
}
19901999
} else {
19912000
entity.setDistance(-1L);

src/test/java/com/arangodb/ArangoDriverGraphEdgesGetCursorTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,7 @@ public void shortesPathTest() throws ArangoException {
330330
assertEquals(201, entity.getCode());
331331

332332
assertEquals(1L, entity.getDistance().longValue());
333-
assertEquals(vertex1.getDocumentHandle(), entity.getStartVertex());
334-
assertEquals(vertex2.getDocumentHandle(), entity.getVertex());
335-
// assertEquals(1, entity.getPaths().get(0).getEdges().size());
336-
// assertEquals(2, entity.getPaths().get(0).getVertices().size());
333+
assertEquals(1, entity.getEdges().size());
334+
assertEquals(2, entity.getVertices().size());
337335
}
338336
}

src/test/java/com/arangodb/example/GraphQueryExample.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,10 @@ public static void main(String[] args) {
122122

123123
private static void printShortestPath(ShortestPathEntity<Person, Knows> shortestPath) {
124124
if (shortestPath.getDistance() > -1) {
125-
System.out.printf("%20s -> %20s distance = %d, paths.size() = %d, paths.get(0).edges.size() = %d%n",
126-
shortestPath.getStartVertex(), shortestPath.getVertex(), shortestPath.getDistance(), shortestPath
127-
.getPaths().size(), shortestPath.getPaths().get(0).getEdges().size());
125+
System.out.printf("%s -> %s : distance = %d, getVertices().size() = %d, edges.size() = %d%n", shortestPath
126+
.getVertices().get(0).getDocumentHandle(),
127+
shortestPath.getVertices().get(shortestPath.getVertices().size() - 1).getDocumentHandle(),
128+
shortestPath.getDistance(), shortestPath.getVertices().size(), shortestPath.getEdges().size());
128129
} else {
129130
System.out.println("no path");
130131
}

0 commit comments

Comments
 (0)