Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-03-2018 07:34 AM
Hello.
I'm using Apoc Procedures in my Java app. I'm interested into XML import and the function mergeNodes.
The first one works fine, but the problem is only on the second one: mergeNodes.
I know how to register APOC procedures, so here my code:
private static void registerApocProcedure(GraphDatabaseService graphDB) throws IllegalArgumentException {
//Register APOC procedures
Procedures procedures = ((GraphDatabaseAPI) graphDB).getDependencyResolver().resolveDependency(Procedures.class);
List<Class<?>> apocProcedures = Arrays.asList(Xml.class, Merge.class, RefactorConfig.class, RefactorResult.class, RelationshipRefactorResult.class, NodeRefactorResult.class);
apocProcedures.forEach((proc) -> {
try {
procedures.registerProcedure(proc);
} catch (KernelException e) {
throw new RuntimeException("Error registering "+proc,e);
}
});
}
As you can see I also included some procedures that recalls the name of apoc.refactor.mergeNodes, but when I run my app I got the error:
There is no procedure with the name apoc.refactor.mergeNodes
registered for this database instance. Please ensure you've spelled the procedure name correctly and that the procedure is properly deployed.
It seems to me that I'm not using the right APOC procedure. If this is the problem, which is the right APOC procedure which implements the mergeNodes?
Thanks!
Solved! Go to Solution.
11-27-2018 10:44 AM
apoc.text.join
is a function and not a procedure. Therefore you need to call procedures.registerFunction(proc)
to register it.
10-03-2018 12:22 PM
Looks like you're missing GraphRefactoring
, see https://github.com/neo4j-contrib/neo4j-apoc-procedures/blob/3.4/src/main/java/apoc/refactor/GraphRef...
On a different notice: if you're using apoc procedures from within your java code, you can directly instantiate the class implementing the apoc procedure like this (pseudo code)
GraphRefactoring graphRefactoring = new GraphRefactoring();
graphRefactoring.db = myGraphDb;
graphRefactoring.log = myLog;
graphRefactoring.mergeNodes(params)
This way you don't have to register anything.
11-26-2018 12:13 PM
Thanks and sorry for late reply.
Is there a way to understand which class I need to load given the name?
For example, now I need to load the corresponding class of apoc.text.join.
Cheers.
11-26-2018 11:42 PM
You need to inspect APOC sources for this. In your example take a look in package apoc.text
(https://github.com/neo4j-contrib/neo4j-apoc-procedures/tree/3.4/src/main/java/apoc/text). Take a look at @Description
annotations, for your example specifically https://github.com/neo4j-contrib/neo4j-apoc-procedures/blob/3.4/src/main/java/apoc/text/Strings.java...
11-27-2018 02:20 AM
I followed your suggestion and I tried with:
private static void registerApocProcedure(GraphDatabaseService graphDB) throws IllegalArgumentException {
//Register APOC procedures
Procedures procedures = ((GraphDatabaseAPI) graphDB).getDependencyResolver().resolveDependency(Procedures.class);
List<Class<?>> apocProcedures = Arrays.asList(Xml.class, GraphRefactoring.class, apoc.text.Strings.class);
apocProcedures.forEach((proc) -> {
try {
procedures.registerProcedure(proc);
} catch (KernelException e) {
throw new RuntimeException("Error registering "+proc,e);
}
});
}
I added apoc.text.Strings.class, but it didn't work.
The only way to recover join is to call the function like this:
apoc.text.Strings joinFunction = new Strings();
joinFunction.join(texts, delimiter);
there is only one problem: I already have a cypher query which uses apoc.text.join, and I do not know how to make it work together. Is there a solution for this?
Many thanks.
11-27-2018 10:44 AM
apoc.text.join
is a function and not a procedure. Therefore you need to call procedures.registerFunction(proc)
to register it.
All the sessions of the conference are now available online