Search in sources :

Example 11 with Signature

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;
}
Also used : Signature(uk.gov.gchq.koryphe.signature.Signature) ValidationResult(uk.gov.gchq.koryphe.ValidationResult)

Example 12 with Signature

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;
}
Also used : TupleAdaptedPredicate(uk.gov.gchq.koryphe.tuple.predicate.TupleAdaptedPredicate) Signature(uk.gov.gchq.koryphe.signature.Signature) ValidationResult(uk.gov.gchq.koryphe.ValidationResult)

Example 13 with Signature

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;
}
Also used : Signature(uk.gov.gchq.koryphe.signature.Signature) TupleAdaptedBinaryOperator(uk.gov.gchq.koryphe.tuple.binaryoperator.TupleAdaptedBinaryOperator) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) ElementAggregator(uk.gov.gchq.gaffer.data.element.function.ElementAggregator)

Aggregations

Signature (uk.gov.gchq.koryphe.signature.Signature)13 ValidationResult (uk.gov.gchq.koryphe.ValidationResult)8 Predicate (java.util.function.Predicate)4 HashSet (java.util.HashSet)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 ArrayList (java.util.ArrayList)2 TupleAdaptedBinaryOperator (uk.gov.gchq.koryphe.tuple.binaryoperator.TupleAdaptedBinaryOperator)2 TupleAdaptedPredicate (uk.gov.gchq.koryphe.tuple.predicate.TupleAdaptedPredicate)2 BinaryOperator (java.util.function.BinaryOperator)1 ElementAggregator (uk.gov.gchq.gaffer.data.element.function.ElementAggregator)1 OperationException (uk.gov.gchq.gaffer.operation.OperationException)1 AdaptedBinaryOperator (uk.gov.gchq.koryphe.binaryoperator.AdaptedBinaryOperator)1 AdaptedPredicate (uk.gov.gchq.koryphe.predicate.AdaptedPredicate)1 TupleAdaptedFunction (uk.gov.gchq.koryphe.tuple.function.TupleAdaptedFunction)1 IntegerTupleAdaptedPredicate (uk.gov.gchq.koryphe.tuple.predicate.IntegerTupleAdaptedPredicate)1