Search in sources :

Example 1 with FailedLoadFunction

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

the class ReflectiveProcedureCompiler method compileFunction.

private CallableUserFunction compileFunction(Class<?> procDefinition, MethodHandle constructor, Method method, QualifiedName procName) throws ProcedureException, IllegalAccessException {
    if (procName.namespace() == null || procName.namespace().length == 0) {
        throw new ProcedureException(Status.Procedure.ProcedureRegistrationFailed, "It is not allowed to define functions in the root namespace please use a namespace, e.g. `@UserFunction(\"org.example.com.%s\")", procName.name());
    }
    List<FieldSignature> inputSignature = inputSignatureDeterminer.signatureFor(method);
    Class<?> returnType = method.getReturnType();
    TypeMappers.NeoValueConverter valueConverter = typeMappers.converterFor(returnType);
    MethodHandle procedureMethod = lookup.unreflect(method);
    Optional<String> description = description(method);
    UserFunction function = method.getAnnotation(UserFunction.class);
    Optional<String> deprecated = deprecated(method, function::deprecatedBy, "Use of @UserFunction(deprecatedBy) without @Deprecated in " + procName);
    List<FieldInjections.FieldSetter> setters = allFieldInjections.setters(procDefinition);
    if (!config.fullAccessFor(procName.toString())) {
        try {
            setters = safeFieldInjections.setters(procDefinition);
        } catch (ComponentInjectionException e) {
            description = Optional.of(procName.toString() + " is not available due to having restricted access rights, check configuration.");
            log.warn(description.get());
            UserFunctionSignature signature = new UserFunctionSignature(procName, inputSignature, valueConverter.type(), deprecated, config.rolesFor(procName.toString()), description);
            return new FailedLoadFunction(signature);
        }
    }
    UserFunctionSignature signature = new UserFunctionSignature(procName, inputSignature, valueConverter.type(), deprecated, config.rolesFor(procName.toString()), description);
    return new ReflectiveUserFunction(signature, constructor, procedureMethod, valueConverter, setters);
}
Also used : FieldSignature(org.neo4j.kernel.api.proc.FieldSignature) UserFunctionSignature(org.neo4j.kernel.api.proc.UserFunctionSignature) FailedLoadFunction(org.neo4j.kernel.api.proc.FailedLoadFunction) CallableUserFunction(org.neo4j.kernel.api.proc.CallableUserFunction) UserFunction(org.neo4j.procedure.UserFunction) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) ComponentInjectionException(org.neo4j.kernel.api.exceptions.ComponentInjectionException) MethodHandle(java.lang.invoke.MethodHandle)

Aggregations

MethodHandle (java.lang.invoke.MethodHandle)1 ComponentInjectionException (org.neo4j.kernel.api.exceptions.ComponentInjectionException)1 ProcedureException (org.neo4j.kernel.api.exceptions.ProcedureException)1 CallableUserFunction (org.neo4j.kernel.api.proc.CallableUserFunction)1 FailedLoadFunction (org.neo4j.kernel.api.proc.FailedLoadFunction)1 FieldSignature (org.neo4j.kernel.api.proc.FieldSignature)1 UserFunctionSignature (org.neo4j.kernel.api.proc.UserFunctionSignature)1 UserFunction (org.neo4j.procedure.UserFunction)1