use of org.neo4j.kernel.api.exceptions.ProcedureException 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);
}
}
}
use of org.neo4j.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.
the class TypeMappers method converterFor.
public NeoValueConverter converterFor(Type javaType) throws ProcedureException {
NeoValueConverter 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.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.
the class ResourceInjectionTest method shouldFailNicelyWhenUnsafeAPISafeModeFunction.
@Test
public void shouldFailNicelyWhenUnsafeAPISafeModeFunction() throws Throwable {
//When
List<CallableUserFunction> procList = compiler.compileFunction(FunctionWithUnsafeAPI.class);
verify(log).warn("org.neo4j.kernel.impl.proc.listCoolPeople is not " + "available due to having restricted access rights, check configuration.");
assertThat(procList.size(), equalTo(1));
try {
procList.get(0).apply(new BasicContext(), new Object[0]);
fail();
} catch (ProcedureException e) {
assertThat(e.getMessage(), containsString("org.neo4j.kernel.impl.proc.listCoolPeople is not " + "available due to having restricted access rights, check configuration."));
}
}
use of org.neo4j.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.
the class ResourceInjectionTest method shouldFailNicelyWhenUnsafeAPISafeMode.
@Test
public void shouldFailNicelyWhenUnsafeAPISafeMode() throws Throwable {
//When
List<CallableProcedure> procList = compiler.compileProcedure(ProcedureWithUnsafeAPI.class, Optional.empty(), false);
verify(log).warn("org.neo4j.kernel.impl.proc.listCoolPeople is not " + "available due to having restricted access rights, check configuration.");
assertThat(procList.size(), equalTo(1));
try {
procList.get(0).apply(new BasicContext(), new Object[0]);
fail();
} catch (ProcedureException e) {
assertThat(e.getMessage(), containsString("org.neo4j.kernel.impl.proc.listCoolPeople is not " + "available due to having restricted access rights, check configuration."));
}
}
use of org.neo4j.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.
the class UserFunctionsTest method shouldMakeContextAvailable.
@Test
public void shouldMakeContextAvailable() throws Throwable {
// Given
Key<String> someKey = key("someKey", String.class);
procs.register(new CallableUserFunction.BasicUserFunction(signature) {
@Override
public Object apply(Context ctx, Object[] input) throws ProcedureException {
return ctx.get(someKey);
}
});
BasicContext ctx = new BasicContext();
ctx.put(someKey, "hello, world");
// When
Object result = procs.callFunction(ctx, signature.name(), new Object[0]);
// Then
assertThat(result, equalTo("hello, world"));
}
Aggregations