Search in sources :

Example 1 with FailedLoadProcedure

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

the class ReflectiveProcedureCompiler method compileProcedure.

private CallableProcedure compileProcedure(Class<?> procDefinition, MethodHandle constructor, Method method, Optional<String> warning, boolean fullAccess, QualifiedName procName) throws ProcedureException, IllegalAccessException {
    MethodHandle procedureMethod = lookup.unreflect(method);
    List<FieldSignature> inputSignature = inputSignatureDeterminer.signatureFor(method);
    OutputMapper outputMapper = outputMappers.mapper(method);
    Optional<String> description = description(method);
    Procedure procedure = method.getAnnotation(Procedure.class);
    Mode mode = procedure.mode();
    if (method.isAnnotationPresent(PerformsWrites.class)) {
        if (!procedure.mode().equals(org.neo4j.procedure.Mode.DEFAULT)) {
            throw new ProcedureException(Status.Procedure.ProcedureRegistrationFailed, "Conflicting procedure annotation, cannot use PerformsWrites and mode");
        } else {
            mode = Mode.WRITE;
        }
    }
    Optional<String> deprecated = deprecated(method, procedure::deprecatedBy, "Use of @Procedure(deprecatedBy) without @Deprecated in " + procName);
    List<FieldInjections.FieldSetter> setters = allFieldInjections.setters(procDefinition);
    if (!fullAccess && !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());
            ProcedureSignature signature = new ProcedureSignature(procName, inputSignature, outputMapper.signature(), Mode.DEFAULT, Optional.empty(), new String[0], description, warning);
            return new FailedLoadProcedure(signature);
        }
    }
    ProcedureSignature signature = new ProcedureSignature(procName, inputSignature, outputMapper.signature(), mode, deprecated, config.rolesFor(procName.toString()), description, warning);
    return new ReflectiveProcedure(signature, constructor, procedureMethod, outputMapper, setters);
}
Also used : FailedLoadProcedure(org.neo4j.kernel.api.proc.FailedLoadProcedure) Mode(org.neo4j.procedure.Mode) FieldSignature(org.neo4j.kernel.api.proc.FieldSignature) ProcedureSignature(org.neo4j.kernel.api.proc.ProcedureSignature) FailedLoadProcedure(org.neo4j.kernel.api.proc.FailedLoadProcedure) CallableProcedure(org.neo4j.kernel.api.proc.CallableProcedure) Procedure(org.neo4j.procedure.Procedure) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) ComponentInjectionException(org.neo4j.kernel.api.exceptions.ComponentInjectionException) OutputMapper(org.neo4j.kernel.impl.proc.OutputMappers.OutputMapper) 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 CallableProcedure (org.neo4j.kernel.api.proc.CallableProcedure)1 FailedLoadProcedure (org.neo4j.kernel.api.proc.FailedLoadProcedure)1 FieldSignature (org.neo4j.kernel.api.proc.FieldSignature)1 ProcedureSignature (org.neo4j.kernel.api.proc.ProcedureSignature)1 OutputMapper (org.neo4j.kernel.impl.proc.OutputMappers.OutputMapper)1 Mode (org.neo4j.procedure.Mode)1 Procedure (org.neo4j.procedure.Procedure)1