use of uk.gov.gchq.koryphe.signature.Signature in project Gaffer by gchq.
the class GraphConfigurationService method getFilterFunctions.
@SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "Need to wrap all runtime exceptions before they are given to the user")
@Override
public Set<Class> getFilterFunctions(final String inputClass) {
if (StringUtils.isEmpty(inputClass)) {
return getFilterFunctions();
}
final Class<?> clazz;
try {
clazz = Class.forName(SimpleClassNameIdResolver.getClassName(inputClass));
} catch (final Exception e) {
throw new IllegalArgumentException("Input class was not recognised: " + inputClass, e);
}
final Set<Class> classes = new HashSet<>();
for (final Class functionClass : ReflectionUtil.getSubTypes(Predicate.class)) {
try {
final Predicate function = (Predicate) functionClass.newInstance();
final Signature signature = Signature.getInputSignature(function);
if (null == signature.getNumClasses() || (1 == signature.getNumClasses() && (Signature.UnknownGenericType.class.isAssignableFrom(signature.getClasses()[0]) || signature.getClasses()[0].isAssignableFrom(clazz)))) {
classes.add(functionClass);
}
} catch (final Exception e) {
// just add the function.
classes.add(functionClass);
}
}
return classes;
}
use of uk.gov.gchq.koryphe.signature.Signature in project Gaffer by gchq.
the class GraphConfigurationServiceV2 method getFilterFunction.
@SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "Need to wrap all runtime exceptions before they are given to the user")
@Override
public Response getFilterFunction(final String inputClass) {
if (StringUtils.isEmpty(inputClass)) {
return getFilterFunction();
}
final Class<?> clazz;
try {
clazz = Class.forName(SimpleClassNameIdResolver.getClassName(inputClass));
} catch (final Exception e) {
throw new IllegalArgumentException("Input class was not recognised: " + inputClass, e);
}
final Set<Class> classes = new HashSet<>();
for (final Class functionClass : ReflectionUtil.getSubTypes(Predicate.class)) {
try {
final Predicate function = (Predicate) functionClass.newInstance();
final Signature signature = Signature.getInputSignature(function);
if (null == signature.getNumClasses() || (1 == signature.getNumClasses() && (Signature.UnknownGenericType.class.isAssignableFrom(signature.getClasses()[0]) || signature.getClasses()[0].isAssignableFrom(clazz)))) {
classes.add(functionClass);
}
} catch (final Exception e) {
// just add the function.
classes.add(functionClass);
}
}
return Response.ok(classes).header(GAFFER_MEDIA_TYPE_HEADER, GAFFER_MEDIA_TYPE).build();
}
use of uk.gov.gchq.koryphe.signature.Signature in project Gaffer by gchq.
the class GraphConfigurationController method getFilterFunctions.
@Override
public Set<Class> getFilterFunctions(@PathVariable("inputClass") final String inputClass) {
if (StringUtils.isEmpty(inputClass)) {
return getFilterFunctions();
}
final Class<?> clazz;
try {
clazz = Class.forName(SimpleClassNameIdResolver.getClassName(inputClass));
} catch (final ClassNotFoundException e) {
throw new IllegalArgumentException("Could not find input class: " + inputClass, e);
}
final Set<Class> applicablePredicates = new HashSet<>();
for (final Class predicateClass : ReflectionUtil.getSubTypes(Predicate.class)) {
Predicate predicate;
try {
predicate = (Predicate) predicateClass.newInstance();
} catch (final IllegalAccessException | InstantiationException e) {
LOGGER.warn("Failed to create new instance of " + predicateClass, e);
LOGGER.warn("Skipping");
continue;
}
Signature inputSignature = Signature.getInputSignature(predicate);
if (null == inputSignature.getNumClasses() || (1 == inputSignature.getNumClasses() && (Signature.UnknownGenericType.class.isAssignableFrom(inputSignature.getClasses()[0]) || inputSignature.getClasses()[0].isAssignableFrom(clazz)))) {
applicablePredicates.add(predicateClass);
}
}
return applicablePredicates;
}
use of uk.gov.gchq.koryphe.signature.Signature in project Gaffer by gchq.
the class SchemaElementDefinitionValidator method validateFunctionArgumentTypes.
protected ValidationResult validateFunctionArgumentTypes(final ElementAggregator aggregator, final SchemaElementDefinition schemaElDef) {
final ValidationResult result = new ValidationResult();
if (null != aggregator && null != aggregator.getComponents()) {
for (final TupleAdaptedBinaryOperator<String, ?> adaptedFunction : aggregator.getComponents()) {
if (null == adaptedFunction.getBinaryOperator()) {
result.addError(aggregator.getClass().getSimpleName() + " contains a null function.");
} else {
final Signature inputSig = Signature.getInputSignature(adaptedFunction.getBinaryOperator());
result.add(inputSig.assignable(getTypeClasses(adaptedFunction.getSelection(), schemaElDef)));
final Signature outputSig = Signature.getOutputSignature(adaptedFunction.getBinaryOperator());
result.add(outputSig.assignable(getTypeClasses(adaptedFunction.getSelection(), schemaElDef)));
}
}
}
return result;
}
use of uk.gov.gchq.koryphe.signature.Signature in project Gaffer by gchq.
the class ViewValidator method validateFunctionArgumentTypes.
private ValidationResult validateFunctionArgumentTypes(final ElementAggregator aggregator, final ViewElementDefinition viewElDef, final SchemaElementDefinition schemaElDef) {
final ValidationResult result = new ValidationResult();
if (null != aggregator && null != aggregator.getComponents()) {
for (final TupleAdaptedBinaryOperator<String, ?> adaptedFunction : aggregator.getComponents()) {
if (null == adaptedFunction.getBinaryOperator()) {
result.addError(aggregator.getClass().getSimpleName() + " contains a null function.");
} else {
final Class[] inputTypeClasses = getTypeClasses(adaptedFunction.getSelection(), viewElDef, schemaElDef);
if (!ArrayUtils.contains(inputTypeClasses, null)) {
final Signature inputSig = Signature.getInputSignature(adaptedFunction.getBinaryOperator());
result.add(inputSig.assignable(inputTypeClasses));
}
}
}
}
return result;
}
Aggregations