Search in sources :

Example 6 with Signature

use of uk.gov.gchq.koryphe.signature.Signature in project Gaffer by gchq.

the class TransformValidator method validateTransformPropertyClasses.

/**
 * Validates that the functions to be executed are assignable to the corresponding properties
 *
 * @param elementDef  The SchemaElementDefinition to validate against.
 * @param transformer The ElementFilter to be validated against
 * @return ValidationResult of the validation
 */
private ValidationResult validateTransformPropertyClasses(final SchemaElementDefinition elementDef, final ElementTransformer transformer) {
    final ValidationResult result = new ValidationResult();
    if (null != elementDef) {
        final List<TupleAdaptedFunction<String, ?, ?>> components = transformer.getComponents();
        for (final TupleAdaptedFunction<String, ?, ?> component : components) {
            final Map<String, String> properties = elementDef.getPropertyMap();
            if (!properties.isEmpty()) {
                if (null == component.getFunction()) {
                    result.addError(transformer.getClass().getSimpleName());
                } else {
                    final Class[] selectionClasses = getTypeClasses(component.getSelection(), elementDef);
                    if (!ArrayUtils.contains(selectionClasses, null)) {
                        final Signature inputSig = Signature.getInputSignature(component.getFunction());
                        result.add(inputSig.assignable(selectionClasses));
                    }
                    final Class[] projectionClasses = getTypeClasses(component.getProjection(), elementDef);
                    if (!ArrayUtils.contains(projectionClasses, null)) {
                        final Signature outputSig = Signature.getOutputSignature(component.getFunction());
                        result.add(outputSig.assignable(projectionClasses));
                    }
                }
            }
        }
    }
    return result;
}
Also used : Signature(uk.gov.gchq.koryphe.signature.Signature) TupleAdaptedFunction(uk.gov.gchq.koryphe.tuple.function.TupleAdaptedFunction) ValidationResult(uk.gov.gchq.koryphe.ValidationResult)

Example 7 with Signature

use of uk.gov.gchq.koryphe.signature.Signature in project gaffer-doc by gchq.

the class PropertiesWalkthrough method listAggregators.

protected boolean listAggregators(final Class<?> clazz) {
    final List<String> aggregateClasses = new ArrayList<>();
    for (final BinaryOperator function : AGGREGATE_FUNCTIONS) {
        final Signature signature = Signature.getInputSignature(function);
        if (signature.assignable(clazz).isValid()) {
            aggregateClasses.add(WalkthroughStrSubstitutor.getJavaDocLink(function.getClass(), false));
        }
    }
    if (!aggregateClasses.isEmpty()) {
        print(AGGREGATORS_KEY, "\nAggregators:");
        print(AGGREGATORS_KEY, "\n- " + StringUtils.join(aggregateClasses, "\n- "));
    }
    return !aggregateClasses.isEmpty();
}
Also used : Signature(uk.gov.gchq.koryphe.signature.Signature) ArrayList(java.util.ArrayList) AdaptedBinaryOperator(uk.gov.gchq.koryphe.binaryoperator.AdaptedBinaryOperator) TupleAdaptedBinaryOperator(uk.gov.gchq.koryphe.tuple.binaryoperator.TupleAdaptedBinaryOperator) BinaryOperator(java.util.function.BinaryOperator)

Example 8 with Signature

use of uk.gov.gchq.koryphe.signature.Signature in project gaffer-doc by gchq.

the class PropertiesWalkthrough method listPredicates.

protected boolean listPredicates(final Class<?> clazz) {
    final List<String> validateClasses = new ArrayList<>();
    for (final Predicate function : PREDICATES) {
        try {
            final Signature signature = Signature.getInputSignature(function);
            if (signature.assignable(clazz).isValid()) {
                validateClasses.add(WalkthroughStrSubstitutor.getJavaDocLink(function.getClass(), false));
            }
        } catch (final Exception e) {
            // just add the function.
            validateClasses.add(WalkthroughStrSubstitutor.getJavaDocLink(function.getClass(), false));
        }
    }
    if (!validateClasses.isEmpty()) {
        print(PREDICATES_KEY, "\nPredicates:");
        print(PREDICATES_KEY, "\n- " + StringUtils.join(validateClasses, "\n- "));
    }
    return !validateClasses.isEmpty();
}
Also used : Signature(uk.gov.gchq.koryphe.signature.Signature) ArrayList(java.util.ArrayList) OperationException(uk.gov.gchq.gaffer.operation.OperationException) IntegerTupleAdaptedPredicate(uk.gov.gchq.koryphe.tuple.predicate.IntegerTupleAdaptedPredicate) TupleAdaptedPredicate(uk.gov.gchq.koryphe.tuple.predicate.TupleAdaptedPredicate) Predicate(java.util.function.Predicate) AdaptedPredicate(uk.gov.gchq.koryphe.predicate.AdaptedPredicate)

Example 9 with Signature

use of uk.gov.gchq.koryphe.signature.Signature in project Gaffer by gchq.

the class SchemaElementDefinitionValidator method validateFunctionArgumentTypes.

protected ValidationResult validateFunctionArgumentTypes(final ElementFilter filter, final SchemaElementDefinition schemaElDef) {
    final ValidationResult result = new ValidationResult();
    if (null != filter && null != filter.getComponents()) {
        for (final TupleAdaptedPredicate<String, ?> adaptedPredicate : filter.getComponents()) {
            if (null == adaptedPredicate.getPredicate()) {
                result.addError(filter.getClass().getSimpleName() + " contains a null function.");
            } else {
                final Signature inputSig = Signature.getInputSignature(adaptedPredicate.getPredicate());
                result.add(inputSig.assignable(getTypeClasses(adaptedPredicate.getSelection(), schemaElDef)));
            }
        }
    }
    return result;
}
Also used : Signature(uk.gov.gchq.koryphe.signature.Signature) ValidationResult(uk.gov.gchq.koryphe.ValidationResult)

Example 10 with Signature

use of uk.gov.gchq.koryphe.signature.Signature in project Gaffer by gchq.

the class ViewValidator method validateFunctionArgumentTypes.

private ValidationResult validateFunctionArgumentTypes(final ElementFilter filter, final ViewElementDefinition viewElDef, final SchemaElementDefinition schemaElDef) {
    final ValidationResult result = new ValidationResult();
    if (null != filter && null != filter.getComponents()) {
        for (final TupleAdaptedPredicate<String, ?> adaptedPredicate : filter.getComponents()) {
            if (null == adaptedPredicate.getPredicate()) {
                result.addError(filter.getClass().getSimpleName() + " contains a null function.");
            } else {
                final Class[] inputTypeClasses = getTypeClasses(adaptedPredicate.getSelection(), viewElDef, schemaElDef);
                if (!ArrayUtils.contains(inputTypeClasses, null)) {
                    final Signature inputSig = Signature.getInputSignature(adaptedPredicate.getPredicate());
                    result.add(inputSig.assignable(inputTypeClasses));
                }
            }
        }
    }
    return result;
}
Also used : Signature(uk.gov.gchq.koryphe.signature.Signature) ValidationResult(uk.gov.gchq.koryphe.ValidationResult)

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