use of org.neo4j.kernel.api.proc.CallableProcedure in project neo4j by neo4j.
the class ReflectiveProcedureCompiler method compileProcedure.
List<CallableProcedure> compileProcedure(Class<?> procDefinition, Optional<String> warning, boolean fullAccess) throws KernelException {
try {
List<Method> procedureMethods = Arrays.stream(procDefinition.getDeclaredMethods()).filter(m -> m.isAnnotationPresent(Procedure.class)).collect(Collectors.toList());
if (procedureMethods.isEmpty()) {
return emptyList();
}
MethodHandle constructor = constructor(procDefinition);
ArrayList<CallableProcedure> out = new ArrayList<>(procedureMethods.size());
for (Method method : procedureMethods) {
String valueName = method.getAnnotation(Procedure.class).value();
String definedName = method.getAnnotation(Procedure.class).name();
QualifiedName procName = extractName(procDefinition, method, valueName, definedName);
if (fullAccess || config.isWhitelisted(procName.toString())) {
out.add(compileProcedure(procDefinition, constructor, method, warning, fullAccess, procName));
} else {
log.warn(String.format("The procedure '%s' is not on the whitelist and won't be loaded.", procName.toString()));
}
}
out.sort(Comparator.comparing(a -> a.signature().name().toString()));
return out;
} catch (KernelException e) {
throw e;
} catch (Exception e) {
throw new ProcedureException(Status.Procedure.ProcedureRegistrationFailed, e, "Failed to compile procedure defined in `%s`: %s", procDefinition.getSimpleName(), e.getMessage());
}
}
use of org.neo4j.kernel.api.proc.CallableProcedure in project neo4j by neo4j.
the class ReflectiveProcedureTest method shouldGiveHelpfulErrorOnNullMessageException.
@Test
public void shouldGiveHelpfulErrorOnNullMessageException() throws Throwable {
// Given
CallableProcedure proc = compile(ProcedureThatThrowsNullMsgExceptionAtInvocation.class).get(0);
// Expect
exception.expect(ProcedureException.class);
exception.expectMessage("Failed to invoke procedure `org.neo4j.kernel.impl.proc.throwsAtInvocation`: " + "Caused by: java.lang.IndexOutOfBoundsException");
// When
proc.apply(new BasicContext(), new Object[0]);
}
use of org.neo4j.kernel.api.proc.CallableProcedure in project neo4j by neo4j.
the class ReflectiveProcedureTest method shouldAllowNonStaticOutput.
@Test
public void shouldAllowNonStaticOutput() throws Throwable {
// When
CallableProcedure proc = compile(ProcedureWithNonStaticOutputRecord.class).get(0);
// Then
assertEquals(1, proc.signature().outputSignature().size());
}
use of org.neo4j.kernel.api.proc.CallableProcedure in project neo4j by neo4j.
the class ReflectiveProcedureTest method shouldAllowOverridingProcedureNameWithoutNamespace.
@Test
public void shouldAllowOverridingProcedureNameWithoutNamespace() throws Throwable {
// When
CallableProcedure proc = compile(ProcedureWithSingleName.class).get(0);
// Then
assertEquals("singleName", proc.signature().name().toString());
}
use of org.neo4j.kernel.api.proc.CallableProcedure in project neo4j by neo4j.
the class ReflectiveProcedureTest method shouldInjectLogging.
@Test
public void shouldInjectLogging() throws KernelException {
// Given
Log log = spy(Log.class);
components.register(Log.class, (ctx) -> log);
CallableProcedure procedure = procedureCompiler.compileProcedure(LoggingProcedure.class, Optional.empty(), true).get(0);
// When
procedure.apply(new BasicContext(), new Object[0]);
// Then
verify(log).debug("1");
verify(log).info("2");
verify(log).warn("3");
verify(log).error("4");
}
Aggregations