Search in sources :

Example 6 with Description

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();
}
Also used : ApocConfiguration(apoc.ApocConfiguration) java.util(java.util) Log(org.neo4j.logging.Log) PropertyEntry(org.neo4j.graphdb.event.PropertyEntry) org.neo4j.procedure(org.neo4j.procedure) Iterators(org.neo4j.helpers.collection.Iterators) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TransactionData(org.neo4j.graphdb.event.TransactionData) TransactionEventHandler(org.neo4j.graphdb.event.TransactionEventHandler) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) LabelEntry(org.neo4j.graphdb.event.LabelEntry) Stream(java.util.stream.Stream) Description(apoc.Description) org.neo4j.graphdb(org.neo4j.graphdb) GraphProperties(org.neo4j.kernel.impl.core.GraphProperties) SetBackedList(apoc.coll.SetBackedList) Util(apoc.util.Util) Util.map(apoc.util.Util.map) NodeManager(org.neo4j.kernel.impl.core.NodeManager) SetBackedList(apoc.coll.SetBackedList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Description(apoc.Description)

Aggregations

Description (apoc.Description)6 Procedure (org.neo4j.procedure.Procedure)5 GraphResult (apoc.result.GraphResult)2 VirtualNode (apoc.result.VirtualNode)2 Util (apoc.util.Util)2 java.util (java.util)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Stream (java.util.stream.Stream)2 org.neo4j.graphdb (org.neo4j.graphdb)2 Node (org.neo4j.graphdb.Node)2 Relationship (org.neo4j.graphdb.Relationship)2 Result (org.neo4j.graphdb.Result)2 Log (org.neo4j.logging.Log)2 ApocConfiguration (apoc.ApocConfiguration)1 Pools (apoc.Pools)1 SetBackedList (apoc.coll.SetBackedList)1 NodesAndRelsSubGraph (apoc.export.util.NodesAndRelsSubGraph)1 RowResult (apoc.result.RowResult)1 VirtualRelationship (apoc.result.VirtualRelationship)1 UriResolver (apoc.util.UriResolver)1