use of apoc.Description in project neo4j-apoc-procedures by neo4j-contrib.
the class Trigger method nodesByLabel.
@UserFunction
@Description("function to filter labelEntries by label, to be used within a trigger statement with {assignedLabels}, {removedLabels}, {assigned/removedNodeProperties}")
public List<Node> nodesByLabel(@Name("labelEntries") Object entries, @Name("label") String labelString) {
if (!(entries instanceof Map))
return Collections.emptyList();
Map map = (Map) entries;
if (map.isEmpty())
return Collections.emptyList();
Object result = ((Map) entries).get(labelString);
if (result instanceof List)
return (List<Node>) result;
Object anEntry = map.values().iterator().next();
if (anEntry instanceof List) {
List list = (List) anEntry;
if (!list.isEmpty()) {
if (list.get(0) instanceof Map) {
Set<Node> nodeSet = new HashSet<>(100);
Label label = labelString == null ? null : Label.label(labelString);
for (List<Map<String, Object>> entry : (Collection<List<Map<String, Object>>>) map.values()) {
for (Map<String, Object> propertyEntry : entry) {
Object node = propertyEntry.get("node");
if (node instanceof Node && (label == null || ((Node) node).hasLabel(label))) {
nodeSet.add((Node) node);
}
}
}
if (!nodeSet.isEmpty())
return new SetBackedList<>(nodeSet);
} else if (list.get(0) instanceof Node) {
if (labelString == null) {
Set<Node> nodeSet = new HashSet<>(map.size() * list.size());
map.values().forEach((l) -> nodeSet.addAll((Collection<Node>) l));
return new SetBackedList<>(nodeSet);
}
}
}
}
return Collections.emptyList();
}
Aggregations