apoc.trigger.TriggerExtended Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of apoc Show documentation
Show all versions of apoc Show documentation
A collection of useful Neo4j Procedures
The newest version!
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package apoc.trigger;
import apoc.Description;
import apoc.Extended;
import apoc.coll.SetBackedList;
import apoc.result.VirtualNode;
import apoc.result.VirtualRelationship;
import java.util.*;
import java.util.stream.Collectors;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.procedure.*;
/**
* @author mh
* @since 20.09.16
*/
@Extended
public class TriggerExtended {
public static class TriggerInfo {
public String name;
public String query;
public Map selector;
public Map params;
public boolean installed;
public boolean paused;
public TriggerInfo(String name, String query, Map selector, boolean installed, boolean paused) {
this.name = name;
this.query = query;
this.selector = selector;
this.installed = installed;
this.paused = paused;
}
public TriggerInfo(
String name,
String query,
Map selector,
Map params,
boolean installed,
boolean paused) {
this.name = name;
this.query = query;
this.selector = selector;
this.params = params;
this.installed = installed;
this.paused = paused;
}
}
@Context
public GraphDatabaseService db;
@UserFunction
@Description(
"function to filter labelEntries by label, to be used within a trigger kernelTransaction with {assignedLabels}, {removedLabels}, {assigned/removedNodeProperties}")
public List 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) 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 nodeSet = new HashSet<>(100);
Label label = labelString == null ? null : Label.label(labelString);
for (List