Search in sources :

Example 1 with UserFunctionSignature

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

the class ProcedureRegistry method register.

/**
     * Register a new function.
     *
     * @param function the function.
     */
public void register(CallableUserFunction function, boolean overrideCurrentImplementation) throws ProcedureException {
    UserFunctionSignature signature = function.signature();
    QualifiedName name = signature.name();
    CallableUserFunction oldImplementation = functions.get(name);
    if (oldImplementation == null) {
        functions.put(name, function);
    } else {
        if (overrideCurrentImplementation) {
            functions.put(name, function);
        } else {
            throw new ProcedureException(Status.Procedure.ProcedureRegistrationFailed, "Unable to register function, because the name `%s` is already in use.", name);
        }
    }
}
Also used : CallableUserFunction(org.neo4j.kernel.api.proc.CallableUserFunction) QualifiedName(org.neo4j.kernel.api.proc.QualifiedName) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) UserFunctionSignature(org.neo4j.kernel.api.proc.UserFunctionSignature)

Example 2 with UserFunctionSignature

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

the class ProcedureRegistry method register.

/**
     * Register a new function.
     *
     * @param function the function.
     */
public void register(CallableUserAggregationFunction function, boolean overrideCurrentImplementation) throws ProcedureException {
    UserFunctionSignature signature = function.signature();
    QualifiedName name = signature.name();
    CallableUserFunction oldImplementation = functions.get(name);
    if (oldImplementation == null) {
        aggregationFunctions.put(name, function);
    } else {
        if (overrideCurrentImplementation) {
            aggregationFunctions.put(name, function);
        } else {
            throw new ProcedureException(Status.Procedure.ProcedureRegistrationFailed, "Unable to register aggregation function, because the name `%s` is already in use.", name);
        }
    }
}
Also used : CallableUserFunction(org.neo4j.kernel.api.proc.CallableUserFunction) QualifiedName(org.neo4j.kernel.api.proc.QualifiedName) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) UserFunctionSignature(org.neo4j.kernel.api.proc.UserFunctionSignature)

Example 3 with UserFunctionSignature

use of org.neo4j.kernel.api.proc.UserFunctionSignature 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)

Example 4 with UserFunctionSignature

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

the class ConfiguredProceduresTestBase method shouldSetAllowedToConfigSettingForUDF.

@SuppressWarnings("OptionalGetWithoutIsPresent")
@Test
public void shouldSetAllowedToConfigSettingForUDF() throws Throwable {
    configuredSetup(stringMap(SecuritySettings.default_allowed.name(), "nonEmpty"));
    Procedures procedures = neo.getLocalGraph().getDependencyResolver().resolveDependency(Procedures.class);
    UserFunctionSignature funcSig = procedures.function(new QualifiedName(new String[] { "test" }, "nonAllowedFunc")).get();
    assertThat(Arrays.asList(funcSig.allowed()), containsInAnyOrder("nonEmpty"));
}
Also used : QualifiedName(org.neo4j.kernel.api.proc.QualifiedName) Procedures(org.neo4j.kernel.impl.proc.Procedures) UserFunctionSignature(org.neo4j.kernel.api.proc.UserFunctionSignature) Test(org.junit.Test)

Example 5 with UserFunctionSignature

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

the class ConfiguredProceduresTestBase method shouldNotSetProcedureAllowedIfSettingNotSetForUDF.

@SuppressWarnings("OptionalGetWithoutIsPresent")
@Test
public void shouldNotSetProcedureAllowedIfSettingNotSetForUDF() throws Throwable {
    configuredSetup(defaultConfiguration());
    Procedures procedures = neo.getLocalGraph().getDependencyResolver().resolveDependency(Procedures.class);
    UserFunctionSignature funcSig = procedures.function(new QualifiedName(new String[] { "test" }, "nonAllowedFunc")).get();
    assertThat(Arrays.asList(funcSig.allowed()), empty());
}
Also used : QualifiedName(org.neo4j.kernel.api.proc.QualifiedName) Procedures(org.neo4j.kernel.impl.proc.Procedures) UserFunctionSignature(org.neo4j.kernel.api.proc.UserFunctionSignature) Test(org.junit.Test)

Aggregations

UserFunctionSignature (org.neo4j.kernel.api.proc.UserFunctionSignature)7 ProcedureException (org.neo4j.kernel.api.exceptions.ProcedureException)4 CallableUserFunction (org.neo4j.kernel.api.proc.CallableUserFunction)4 QualifiedName (org.neo4j.kernel.api.proc.QualifiedName)4 Test (org.junit.Test)3 MethodHandle (java.lang.invoke.MethodHandle)2 ComponentInjectionException (org.neo4j.kernel.api.exceptions.ComponentInjectionException)2 FieldSignature (org.neo4j.kernel.api.proc.FieldSignature)2 Procedures (org.neo4j.kernel.impl.proc.Procedures)2 Method (java.lang.reflect.Method)1 URL (java.net.URL)1 BasicContext (org.neo4j.kernel.api.proc.BasicContext)1 CallableProcedure (org.neo4j.kernel.api.proc.CallableProcedure)1 CallableUserAggregationFunction (org.neo4j.kernel.api.proc.CallableUserAggregationFunction)1 FailedLoadAggregatedFunction (org.neo4j.kernel.api.proc.FailedLoadAggregatedFunction)1 FailedLoadFunction (org.neo4j.kernel.api.proc.FailedLoadFunction)1 ProcedureSignature (org.neo4j.kernel.api.proc.ProcedureSignature)1 UserAggregationFunction (org.neo4j.procedure.UserAggregationFunction)1 UserAggregationResult (org.neo4j.procedure.UserAggregationResult)1 UserAggregationUpdate (org.neo4j.procedure.UserAggregationUpdate)1