use of org.neo4j.internal.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.
the class TypeCheckers method converterFor.
DefaultValueConverter converterFor(Type javaType) throws ProcedureException {
if (isAnyValue(javaType)) {
// For AnyValue we support subtyping
javaType = findValidSuperClass(javaType);
}
DefaultValueConverter converter = javaToNeo.get(javaType);
if (converter != null) {
return converter;
}
if (javaType instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType) javaType;
Type rawType = pt.getRawType();
if (rawType == List.class) {
Type type = pt.getActualTypeArguments()[0];
return toList(converterFor(type), type);
} else if (rawType == Map.class) {
Type type = pt.getActualTypeArguments()[0];
if (type != String.class) {
throw new ProcedureException(Status.Procedure.ProcedureRegistrationFailed, "Maps are required to have `String` keys - but this map has `%s` keys.", type.getTypeName());
}
return TO_MAP;
}
}
throw javaToNeoMappingError(javaType);
}
use of org.neo4j.internal.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.
the class ProcedureCompilationTest method shouldHandleNonStaticInnerClasses.
@Test
void shouldHandleNonStaticInnerClasses() throws ProcedureException {
// Given
ProcedureSignature signature = ProcedureSignature.procedureSignature("test", "foo").out(singletonList(inputField("name", NTString))).build();
// When
CallableProcedure stringStream = compileProcedure(signature, emptyList(), method(InnerClass.class, "innerStream"));
// Then
RawIterator<AnyValue[], ProcedureException> iterator = stringStream.apply(ctx, EMPTY, RESOURCE_TRACKER);
assertArrayEquals(new AnyValue[] { stringValue("hello") }, iterator.next());
assertFalse(iterator.hasNext());
}
use of org.neo4j.internal.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.
the class ProcedureCompilationTest method shouldCallSimpleProcedure.
@Test
void shouldCallSimpleProcedure() throws ProcedureException {
// Given
ProcedureSignature signature = ProcedureSignature.procedureSignature("test", "foo").in("in", NTInteger).out(singletonList(inputField("name", NTInteger))).build();
// When
CallableProcedure longStream = compileProcedure(signature, emptyList(), method("longStream", long.class));
// Then
RawIterator<AnyValue[], ProcedureException> iterator = longStream.apply(ctx, new AnyValue[] { longValue(1337L) }, RESOURCE_TRACKER);
assertArrayEquals(new AnyValue[] { longValue(1337L) }, iterator.next());
assertFalse(iterator.hasNext());
}
use of org.neo4j.internal.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.
the class ProcedureJarLoaderTest method shouldGiveHelpfulErrorOnInvalidProcedure.
@Test
void shouldGiveHelpfulErrorOnInvalidProcedure() throws Throwable {
// Given
URL jar = createJarFor(ClassWithOneProcedure.class, ClassWithInvalidProcedure.class);
ProcedureException exception = assertThrows(ProcedureException.class, () -> jarloader.loadProceduresFromDir(parentDir(jar)));
assertThat(exception.getMessage()).isEqualTo(format("Procedures must return a Stream of records, where a record is a concrete class%n" + "that you define, with public non-final fields defining the fields in the record.%n" + "If you''d like your procedure to return `boolean`, you could define a record class like:%n" + "public class Output '{'%n" + " public boolean out;%n" + "'}'%n%n" + "And then define your procedure as returning `Stream<Output>`."));
}
use of org.neo4j.internal.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.
the class ProcedureWithArgumentsTest method shouldRunSimpleProcedure.
@Test
void shouldRunSimpleProcedure() throws Throwable {
// Given
CallableProcedure procedure = compile(ClassWithProcedureWithSimpleArgs.class).get(0);
// When
RawIterator<AnyValue[], ProcedureException> out = procedure.apply(prepareContext(), new AnyValue[] { stringValue("Pontus"), longValue(35L) }, EMPTY_RESOURCE_TRACKER);
// Then
List<AnyValue[]> collect = asList(out);
assertThat(collect.get(0)[0]).isEqualTo(stringValue("Pontus is 35 years old."));
}
Aggregations