Search in sources :

Example 1 with CallableProcedure

use of org.neo4j.kernel.api.proc.CallableProcedure in project neo4j by neo4j.

the class Procedures method start.

@Override
public void start() throws Throwable {
    ProcedureJarLoader loader = new ProcedureJarLoader(compiler, log);
    ProcedureJarLoader.Callables callables = loader.loadProceduresFromDir(pluginDir);
    for (CallableProcedure procedure : callables.procedures()) {
        register(procedure);
    }
    for (CallableUserFunction function : callables.functions()) {
        register(function);
    }
    for (CallableUserAggregationFunction function : callables.aggregationFunctions()) {
        register(function);
    }
    // And register built-in procedures
    builtin.accept(this);
}
Also used : CallableUserFunction(org.neo4j.kernel.api.proc.CallableUserFunction) CallableUserAggregationFunction(org.neo4j.kernel.api.proc.CallableUserAggregationFunction) CallableProcedure(org.neo4j.kernel.api.proc.CallableProcedure)

Example 2 with CallableProcedure

use of org.neo4j.kernel.api.proc.CallableProcedure in project neo4j by neo4j.

the class ResourceInjectionTest method shouldFailNicelyWhenUnsafeAPISafeMode.

@Test
public void shouldFailNicelyWhenUnsafeAPISafeMode() throws Throwable {
    //When
    List<CallableProcedure> procList = compiler.compileProcedure(ProcedureWithUnsafeAPI.class, Optional.empty(), false);
    verify(log).warn("org.neo4j.kernel.impl.proc.listCoolPeople is not " + "available due to having restricted access rights, check configuration.");
    assertThat(procList.size(), equalTo(1));
    try {
        procList.get(0).apply(new BasicContext(), new Object[0]);
        fail();
    } catch (ProcedureException e) {
        assertThat(e.getMessage(), containsString("org.neo4j.kernel.impl.proc.listCoolPeople is not " + "available due to having restricted access rights, check configuration."));
    }
}
Also used : BasicContext(org.neo4j.kernel.api.proc.BasicContext) CallableProcedure(org.neo4j.kernel.api.proc.CallableProcedure) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Test(org.junit.Test)

Example 3 with CallableProcedure

use of org.neo4j.kernel.api.proc.CallableProcedure in project neo4j by neo4j.

the class ReflectiveProcedureTest method shouldLoadWhiteListedProcedure.

@Test
public void shouldLoadWhiteListedProcedure() throws Throwable {
    // Given
    ProcedureConfig config = new ProcedureConfig(Config.defaults().with(genericMap(procedure_whitelist.name(), "org.neo4j.kernel.impl.proc.listCoolPeople")));
    Log log = mock(Log.class);
    ReflectiveProcedureCompiler procedureCompiler = new ReflectiveProcedureCompiler(new TypeMappers(), components, components, log, config);
    // When
    CallableProcedure proc = procedureCompiler.compileProcedure(SingleReadOnlyProcedure.class, Optional.empty(), false).get(0);
    // When
    RawIterator<Object[], ProcedureException> result = proc.apply(new BasicContext(), new Object[0]);
    // Then
    assertEquals(result.next()[0], "Bonnie");
}
Also used : Log(org.neo4j.logging.Log) NullLog(org.neo4j.logging.NullLog) BasicContext(org.neo4j.kernel.api.proc.BasicContext) CallableProcedure(org.neo4j.kernel.api.proc.CallableProcedure) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Test(org.junit.Test)

Example 4 with CallableProcedure

use of org.neo4j.kernel.api.proc.CallableProcedure in project neo4j by neo4j.

the class ReflectiveProcedureWithArgumentsTest method shouldRunSimpleProcedure.

@Test
public void shouldRunSimpleProcedure() throws Throwable {
    // Given
    CallableProcedure procedure = compile(ClassWithProcedureWithSimpleArgs.class).get(0);
    // When
    RawIterator<Object[], ProcedureException> out = procedure.apply(new BasicContext(), new Object[] { "Pontus", 35L });
    // Then
    List<Object[]> collect = asList(out);
    assertThat(collect.get(0)[0], equalTo("Pontus is 35 years old."));
}
Also used : BasicContext(org.neo4j.kernel.api.proc.BasicContext) CallableProcedure(org.neo4j.kernel.api.proc.CallableProcedure) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Test(org.junit.Test)

Example 5 with CallableProcedure

use of org.neo4j.kernel.api.proc.CallableProcedure in project neo4j by neo4j.

the class ProcedureJarLoaderTest method shouldLoadUnsafeAllowedProcedureFromJar.

@Test
public void shouldLoadUnsafeAllowedProcedureFromJar() throws Throwable {
    // Given
    URL jar = createJarFor(ClassWithUnsafeConfiguredComponent.class);
    // When
    ProcedureJarLoader.Callables callables = jarloader.loadProcedures(jar);
    List<CallableUserFunction> functions = callables.functions();
    List<CallableProcedure> procedures = callables.procedures();
    // Then
    List<ProcedureSignature> signatures = procedures.stream().map(CallableProcedure::signature).collect(toList());
    assertThat(signatures, contains(procedureSignature("org", "neo4j", "kernel", "impl", "proc", "unsafeFullAccessProcedure").out("someNumber", NTInteger).build()));
    assertThat(asList(procedures.get(0).apply(new BasicContext(), new Object[0])), contains(IsEqual.equalTo(new Object[] { 7331L })));
    List<UserFunctionSignature> functionsSignatures = functions.stream().map(CallableUserFunction::signature).collect(toList());
    assertThat(functionsSignatures, contains(functionSignature("org", "neo4j", "kernel", "impl", "proc", "unsafeFullAccessFunction").out(NTInteger).build()));
    assertThat(functions.get(0).apply(new BasicContext(), new Object[0]), equalTo(7331L));
}
Also used : CallableUserFunction(org.neo4j.kernel.api.proc.CallableUserFunction) BasicContext(org.neo4j.kernel.api.proc.BasicContext) UserFunctionSignature(org.neo4j.kernel.api.proc.UserFunctionSignature) URL(java.net.URL) ProcedureSignature(org.neo4j.kernel.api.proc.ProcedureSignature) CallableProcedure(org.neo4j.kernel.api.proc.CallableProcedure) Test(org.junit.Test)

Aggregations

CallableProcedure (org.neo4j.kernel.api.proc.CallableProcedure)26 Test (org.junit.Test)22 BasicContext (org.neo4j.kernel.api.proc.BasicContext)15 ProcedureException (org.neo4j.kernel.api.exceptions.ProcedureException)10 ProcedureSignature (org.neo4j.kernel.api.proc.ProcedureSignature)7 Log (org.neo4j.logging.Log)7 NullLog (org.neo4j.logging.NullLog)6 URL (java.net.URL)4 CallableUserFunction (org.neo4j.kernel.api.proc.CallableUserFunction)3 MethodHandle (java.lang.invoke.MethodHandle)2 ComponentInjectionException (org.neo4j.kernel.api.exceptions.ComponentInjectionException)2 CallableUserAggregationFunction (org.neo4j.kernel.api.proc.CallableUserAggregationFunction)2 FailedLoadProcedure (org.neo4j.kernel.api.proc.FailedLoadProcedure)2 FieldSignature (org.neo4j.kernel.api.proc.FieldSignature)2 QualifiedName (org.neo4j.kernel.api.proc.QualifiedName)2 UserFunctionSignature (org.neo4j.kernel.api.proc.UserFunctionSignature)2 OutputMapper (org.neo4j.kernel.impl.proc.OutputMappers.OutputMapper)2 Mode (org.neo4j.procedure.Mode)2 Procedure (org.neo4j.procedure.Procedure)2 MethodHandles (java.lang.invoke.MethodHandles)1