Fix graph rendering to explicitly choose edges with MATCH
@@ -68,6 +68,9 @@ public class OHttpGraphResponse extends OHttpResponse {
// DIVIDE VERTICES FROM EDGES
final Set<OVertex> vertices = new HashSet<>();
+ Set<ORID> edgeRids = new HashSet<ORID>();
+ boolean lightweightFound = false;
+
final Iterator<Object> iIterator = OMultiValue.getMultiValueIterator(iRecords);
while (iIterator.hasNext()) {
Object entry = iIterator.next();
@@ -95,6 +98,11 @@ public class OHttpGraphResponse extends OHttpResponse {
OEdge edge = element.asEdge().get();
vertices.add(edge.getTo());
vertices.add(edge.getFrom());
+ if (edge.getIdentity() != null) {
+ edgeRids.add(edge.getIdentity());
+ } else {
+ lightweightFound = true;
+ }
} else
// IGNORE IT
continue;
@@ -124,9 +132,15 @@ public class OHttpGraphResponse extends OHttpResponse {
}
json.endCollection();
+ if (lightweightFound) {
+ //clean up cached edges and re-calculate, there could be more
+ edgeRids.clear();
+ }
+
// WRITE EDGES
json.beginCollection("edges");
- Set<ORID> edgeRids = new HashSet<ORID>();
+
+ if (edgeRids.isEmpty()) {
for (OVertex vertex : vertices) {
for (OEdge e : vertex.getEdges(ODirection.OUT)) {
OEdge edge = (OEdge) e;
@@ -139,20 +153,13 @@ public class OHttpGraphResponse extends OHttpResponse {
edgeRids.add(edge.getIdentity());
- json.beginObject();
- json.writeAttribute("@rid", edge.getIdentity());
- json.writeAttribute("@class", edge.getSchemaType().map(x -> x.getName()).orElse(null));
-
- json.writeAttribute("out", edge.getVertex(ODirection.OUT).getIdentity());
- json.writeAttribute("in", edge.getVertex(ODirection.IN).getIdentity());
-
- for (String field : edge.getPropertyNames()) {
- final Object v = edge.getProperty(field);
- if (v != null)
- json.writeAttribute(field, v);
+ printEdge(json, edge);
}
-
- json.endObject();
+ }
+ } else {
+ for (ORID edgeRid : edgeRids) {
+ OEdge edge = edgeRid.getRecord();
+ printEdge(json, edge);
}
}
@@ -183,4 +190,23 @@ public class OHttpGraphResponse extends OHttpResponse {
graph.close();
}
}
+
+ private void printEdge(OJSONWriter json, OEdge edge) throws IOException {
+ json.beginObject();
+ json.writeAttribute("@rid", edge.getIdentity());
+ json.writeAttribute("@class", edge.getSchemaType().map(x -> x.getName()).orElse(null));
+
+ json.writeAttribute("out", edge.getVertex(ODirection.OUT).getIdentity());
+ json.writeAttribute("in", edge.getVertex(ODirection.IN).getIdentity());
+
+ for (String field : edge.getPropertyNames()) {
+ if (!(field.equals("out") || field.equals("in"))) {
+ final Object v = edge.getProperty(field);
+ if (v != null)
+ json.writeAttribute(field, v);
+ }
+ }
+
+ json.endObject();
+ }
}
