use of uk.gov.gchq.koryphe.signature.Signature in project Gaffer by gchq.
the class ViewValidator method validateFunctionArgumentTypes.
private ValidationResult validateFunctionArgumentTypes(final ElementTransformer transformer, final ViewElementDefinition viewElDef, final SchemaElementDefinition schemaElDef) {
final ValidationResult result = new ValidationResult();
if (null != transformer && null != transformer.getComponents()) {
for (final TupleAdaptedFunction<String, ?, ?> adaptedFunction : transformer.getComponents()) {
if (null == adaptedFunction.getFunction()) {
result.addError(transformer.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.getFunction());
result.add(inputSig.assignable(inputTypeClasses));
}
final Class[] outputTypeClasses = getTypeClasses(adaptedFunction.getProjection(), viewElDef, schemaElDef);
if (!ArrayUtils.contains(outputTypeClasses, null)) {
final Signature outputSig = Signature.getOutputSignature(adaptedFunction.getFunction());
result.add(outputSig.assignable(outputTypeClasses));
}
}
}
}
return result;
}
use of uk.gov.gchq.koryphe.signature.Signature in project Gaffer by gchq.
the class FilterValidator method validateFilterPropertyClasses.
/**
* Validates that the predicates to be executed are assignable to the corresponding properties
*
* @param elementDef The SchemaElementDefinition to validate against
* @param filter The ElementFilter to be validated against
* @return ValidationResult of the validation
*/
private ValidationResult validateFilterPropertyClasses(final SchemaElementDefinition elementDef, final ElementFilter filter) {
final ValidationResult result = new ValidationResult();
if (null != elementDef) {
final List<TupleAdaptedPredicate<String, ?>> components = filter.getComponents();
for (final TupleAdaptedPredicate<String, ?> component : components) {
final Map<String, String> properties = elementDef.getPropertyMap();
if (!properties.isEmpty()) {
if (null == component.getPredicate()) {
result.addError(filter.getClass().getSimpleName() + " contains a null function.");
} else {
final Class[] selectionClasses = getTypeClasses(component.getSelection(), elementDef);
if (!ArrayUtils.contains(selectionClasses, null)) {
final Signature inputSig = Signature.getInputSignature(component.getPredicate());
result.add(inputSig.assignable(selectionClasses));
}
}
}
}
}
return result;
}
use of uk.gov.gchq.koryphe.signature.Signature in project Gaffer by gchq.
the class AggregateValidator method validateAggregatePropertyClasses.
/**
* Validates that the binary operators to be executed are assignable to the corresponding non-transient properties
*
* @param elementDef The SchemaElementDefinition to validate against
* @param pair AggregatePair, containing a String array of groupBy properties, and an ElementAggregator
* @return ValidationResult of the validation
*/
private ValidationResult validateAggregatePropertyClasses(final SchemaElementDefinition elementDef, final AggregatePair pair) {
final ValidationResult result = new ValidationResult();
if (null != elementDef) {
final ElementAggregator aggregator = pair.getElementAggregator();
if (null != aggregator) {
final List<TupleAdaptedBinaryOperator<String, ?>> components = aggregator.getComponents();
for (final TupleAdaptedBinaryOperator<String, ?> component : components) {
final String[] selection = component.getSelection();
final Class[] selectionClasses = Arrays.stream(selection).map(elementDef::getPropertyClass).toArray(Class[]::new);
final Map<String, String> properties = elementDef.getPropertyMap();
if (!properties.isEmpty()) {
if (null == component.getBinaryOperator()) {
result.addError(aggregator.getClass().getSimpleName() + " contains a null function.");
}
for (int i = 0; i < selectionClasses.length; i++) {
if (properties.containsKey(selection[i])) {
final Signature inputSig = Signature.getInputSignature(component.getBinaryOperator());
result.add(inputSig.assignable(selectionClasses[i]));
}
}
}
}
}
}
return result;
}
Aggregations