How to call APOC functions from Java?


(Fsportelli0) #1

Hello everyone.
I have a Java app working with Neo4j and APOC.
I'm facing a problem calling an APOC function from java, which is apoc.text.join.
When I run a Cypher query I got this error:
org.neo4j.cypher.SyntaxException: Unknown function 'apoc.text.join'
My register function is:

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 recently added apoc.text.Strings.class where it's supposed to be the Join function, but it doesn't work.
I also tried to install Neo4j with APOC plugin and run the embedded browser, the same queries with apoc.text.join work fine!
Calling: CALL apoc.help('apoc.text.join'), apoc.text.join is marked as a function.

So, is the way of calling a APOC function in Java different?
Am I doing something wrong?
Many thanks!


(Michael Hunger) #2

You also have to call procedures.registerFunction(proc) with each class.