use of apoc.result.VirtualRelationship in project neo4j-apoc-procedures by neo4j-contrib.
the class Bolt method toRelationship.
private Object toRelationship(Object value, boolean virtual, Map<Long, Object> nodesCache) {
Value internalValue = ((InternalEntity) value).asValue();
Relationship relationship = internalValue.asRelationship();
if (virtual) {
VirtualNode start = (VirtualNode) nodesCache.getOrDefault(relationship.startNodeId(), new VirtualNode(relationship.startNodeId(), db));
VirtualNode end = (VirtualNode) nodesCache.getOrDefault(relationship.endNodeId(), new VirtualNode(relationship.endNodeId(), db));
VirtualRelationship virtualRelationship = new VirtualRelationship(relationship.id(), start, end, RelationshipType.withName(relationship.type()), relationship.asMap());
return virtualRelationship;
} else
return Util.map("entityType", internalValue.type().name(), "type", relationship.type(), "id", relationship.id(), "start", relationship.startNodeId(), "end", relationship.endNodeId(), "properties", relationship.asMap());
}
use of apoc.result.VirtualRelationship in project neo4j-apoc-procedures by neo4j-contrib.
the class Cluster method graph.
@Procedure
@Description("apoc.cluster.graph - visually displays the servers participating in the Causal Cluster, their " + "roles, and which server in the cluster you are connected to.")
public Stream<GraphResult> graph() {
Result execute = db.execute("CALL dbms.cluster.overview()");
List<Node> servers = new LinkedList<>();
List<Relationship> relationships = new LinkedList<>();
while (execute.hasNext()) {
Map<String, Object> next = execute.next();
String role = (String) next.get("role");
String id = (String) next.get("id");
Label roleLabel = Label.label(role);
String[] addresses = ((List<String>) next.get("addresses")).toArray(new String[0]);
Map<String, Object> properties = new HashMap<>();
properties.put("name", shortName.get(role));
properties.put("title", role);
properties.put(boltAddressKey, addresses[0]);
properties.put("http_address", addresses[1]);
properties.put("cluster_id", id);
Node server = new VirtualNode(new Label[] { roleLabel }, properties, db);
servers.add(server);
}
Optional<Node> leaderNode = getLeaderNode(servers);
if (leaderNode.isPresent()) {
for (Node server : servers) {
if (server.hasLabel(Label.label("FOLLOWER"))) {
VirtualRelationship follows = new VirtualRelationship(server, leaderNode.get(), RelationshipType.withName("FOLLOWS"));
relationships.add(follows);
}
}
}
VirtualNode client = new VirtualNode(new Label[] { Label.label("CLIENT") }, singletonMap("name", "Client"), db);
Optional<Relationship> clientConnection = determineClientConnection(servers, client);
if (clientConnection.isPresent()) {
servers.add(client);
relationships.add(clientConnection.get());
}
GraphResult graphResult = new GraphResult(servers, relationships);
return Stream.of(graphResult);
}
use of apoc.result.VirtualRelationship in project neo4j-apoc-procedures by neo4j-contrib.
the class Meta method metaGraph.
private Stream<GraphResult> metaGraph(Collection<String> labelNames, Collection<String> relTypeNames, boolean removeMissing) {
try (Statement stmt = kernelTx.acquireStatement()) {
ReadOperations ops = stmt.readOperations();
Map<String, Integer> labels = labelsInUse(ops, labelNames);
Map<String, Integer> relTypes = relTypesInUse(ops, relTypeNames);
Map<String, Node> vNodes = new TreeMap<>();
Map<Pattern, Relationship> vRels = new HashMap<>(relTypes.size() * 2);
labels.forEach((labelName, id) -> {
long count = ops.countsForNodeWithoutTxState(id);
if (count > 0) {
mergeMetaNode(Label.label(labelName), vNodes, count);
}
});
relTypes.forEach((typeName, typeId) -> {
long global = ops.countsForRelationshipWithoutTxState(ANY_LABEL, typeId, ANY_LABEL);
labels.forEach((labelNameA, labelIdA) -> {
long relCountOut = ops.countsForRelationshipWithoutTxState(labelIdA, typeId, ANY_LABEL);
if (relCountOut > 0) {
labels.forEach((labelNameB, labelIdB) -> {
long relCountIn = ops.countsForRelationshipWithoutTxState(ANY_LABEL, typeId, labelIdB);
if (relCountIn > 0) {
Node nodeA = vNodes.get(labelNameA);
Node nodeB = vNodes.get(labelNameB);
Relationship vRel = new VirtualRelationship(nodeA, nodeB, RelationshipType.withName(typeName)).withProperties(map("type", typeName, "out", relCountOut, "in", relCountIn, "count", global));
vRels.put(Pattern.of(labelNameA, typeName, labelNameB), vRel);
}
});
}
});
});
if (removeMissing)
filterNonExistingRelationships(vRels);
GraphResult graphResult = new GraphResult(new ArrayList<>(vNodes.values()), new ArrayList<>(vRels.values()));
return Stream.of(graphResult);
}
}
use of apoc.result.VirtualRelationship in project neo4j-apoc-procedures by neo4j-contrib.
the class Meta method addRel.
private void addRel(Map<List<String>, Relationship> rels, Map<String, Node> labels, Relationship rel, boolean strict) {
String typeName = rel.getType().name();
Node startNode = rel.getStartNode();
Node endNode = rel.getEndNode();
for (Label labelA : startNode.getLabels()) {
Node nodeA = strict ? labels.get(labelA.name()) : mergeMetaNode(labelA, labels, 0);
if (nodeA == null)
continue;
for (Label labelB : endNode.getLabels()) {
List<String> key = asList(labelA.name(), labelB.name(), typeName);
Relationship vRel = rels.get(key);
if (vRel == null) {
Node nodeB = strict ? labels.get(labelB.name()) : mergeMetaNode(labelB, labels, 0);
if (nodeB == null)
continue;
vRel = new VirtualRelationship(nodeA, nodeB, rel.getType()).withProperties(singletonMap("type", typeName));
rels.put(key, vRel);
}
vRel.setProperty("count", ((long) vRel.getProperty("count", 0L)) + 1);
}
}
}
Aggregations