Search in sources :

Example 1 with OutputMapper

use of org.neo4j.kernel.impl.proc.OutputMappers.OutputMapper in project neo4j by neo4j.

the class OutputMappersTest method shouldSkipStaticFields.

@Test
public void shouldSkipStaticFields() throws Throwable {
    // When
    OutputMapper mapper = mapper(RecordWithStaticFields.class);
    // Then
    assertThat(mapper.signature(), contains(new FieldSignature("includeMe", Neo4jTypes.NTString)));
    assertThat(asList(mapper.apply(new RecordWithStaticFields("hello, world!"))), contains("hello, world!"));
}
Also used : FieldSignature(org.neo4j.kernel.api.proc.FieldSignature) OutputMapper(org.neo4j.kernel.impl.proc.OutputMappers.OutputMapper) Test(org.junit.Test)

Example 2 with OutputMapper

use of org.neo4j.kernel.impl.proc.OutputMappers.OutputMapper in project neo4j by neo4j.

the class OutputMappersTest method shouldMapSimpleRecordWithString.

@Test
public void shouldMapSimpleRecordWithString() throws Throwable {
    // When
    OutputMapper mapper = mapper(SingleStringFieldRecord.class);
    // Then
    assertThat(mapper.signature(), contains(new FieldSignature("name", Neo4jTypes.NTString)));
    assertThat(asList(mapper.apply(new SingleStringFieldRecord("hello, world!"))), contains("hello, world!"));
}
Also used : FieldSignature(org.neo4j.kernel.api.proc.FieldSignature) OutputMapper(org.neo4j.kernel.impl.proc.OutputMappers.OutputMapper) Test(org.junit.Test)

Example 3 with OutputMapper

use of org.neo4j.kernel.impl.proc.OutputMappers.OutputMapper 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

FieldSignature (org.neo4j.kernel.api.proc.FieldSignature)3 OutputMapper (org.neo4j.kernel.impl.proc.OutputMappers.OutputMapper)3 Test (org.junit.Test)2 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 ProcedureSignature (org.neo4j.kernel.api.proc.ProcedureSignature)1 Mode (org.neo4j.procedure.Mode)1 Procedure (org.neo4j.procedure.Procedure)1