Search in sources :

Example 71 with ValidationResult

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

Example 72 with ValidationResult

use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.

the class ViewValidator method validateAgainstStoreTraits.

protected ValidationResult validateAgainstStoreTraits(final ViewElementDefinition viewElDef, final Set<StoreTrait> storeTraits) {
    final ValidationResult result = new ValidationResult();
    if (!storeTraits.contains(StoreTrait.QUERY_AGGREGATION) && null != viewElDef.getAggregator()) {
        result.addError("This store does not currently support " + StoreTrait.QUERY_AGGREGATION.name());
    }
    validateStoreTrait(viewElDef.getPreAggregationFilter(), StoreTrait.PRE_AGGREGATION_FILTERING, storeTraits, result);
    validateStoreTrait(viewElDef.getPostAggregationFilter(), StoreTrait.POST_AGGREGATION_FILTERING, storeTraits, result);
    validateStoreTrait(viewElDef.getTransformer(), StoreTrait.TRANSFORMATION, storeTraits, result);
    validateStoreTrait(viewElDef.getPostTransformFilter(), StoreTrait.POST_TRANSFORMATION_FILTERING, storeTraits, result);
    return result;
}
Also used : ValidationResult(uk.gov.gchq.koryphe.ValidationResult)

Example 73 with ValidationResult

use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.

the class ElementValidatorTest method shouldReturnValidValidationResultWhenSchemaValidateWithValidElement.

@Test
public void shouldReturnValidValidationResultWhenSchemaValidateWithValidElement() {
    // Given
    final Schema schema = mock(Schema.class);
    final String group = TestGroups.EDGE;
    final Element elm = mock(Element.class);
    final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
    final ElementFilter filter = mock(ElementFilter.class);
    final boolean includeIsA = true;
    final ElementValidator validator = new ElementValidator(schema, includeIsA);
    given(elm.getGroup()).willReturn(group);
    given(schema.getElement(group)).willReturn(elementDef);
    given(elementDef.getValidator(includeIsA)).willReturn(filter);
    given(filter.testWithValidationResult(elm)).willReturn(new ValidationResult());
    // When
    final ValidationResult result = validator.validateWithValidationResult(elm);
    // Then
    assertTrue(result.isValid());
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) Element(uk.gov.gchq.gaffer.data.element.Element) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) Test(org.junit.jupiter.api.Test)

Example 74 with ValidationResult

use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.

the class TransformValidator method validateOperation.

@Override
protected ValidationResult validateOperation(final Transform operation, final Schema schema) {
    final ValidationResult result = new ValidationResult();
    final Map<String, ?> entities = null != operation.getEntities() ? operation.getEntities() : new HashMap<>();
    final Map<String, ?> edges = null != operation.getEdges() ? operation.getEdges() : new HashMap<>();
    for (final Map.Entry<String, ?> entry : edges.entrySet()) {
        result.add(validateEdge(entry, schema));
        result.add(validateElementTransformer((ElementTransformer) entry.getValue()));
        result.add(validateTransformPropertyClasses(schema.getEdge(entry.getKey()), (ElementTransformer) entry.getValue()));
    }
    for (final Map.Entry<String, ?> entry : entities.entrySet()) {
        result.add(validateEntity(entry, schema));
        result.add(validateElementTransformer((ElementTransformer) entry.getValue()));
        result.add(validateTransformPropertyClasses(schema.getEntity(entry.getKey()), (ElementTransformer) entry.getValue()));
    }
    return result;
}
Also used : ElementTransformer(uk.gov.gchq.gaffer.data.element.function.ElementTransformer) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) Map(java.util.Map) HashMap(java.util.HashMap)

Example 75 with ValidationResult

use of uk.gov.gchq.koryphe.ValidationResult 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)

Aggregations

ValidationResult (uk.gov.gchq.koryphe.ValidationResult)132 Test (org.junit.jupiter.api.Test)86 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)32 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)27 HashMap (java.util.HashMap)13 OperationTest (uk.gov.gchq.gaffer.operation.OperationTest)12 ElementAggregator (uk.gov.gchq.gaffer.data.element.function.ElementAggregator)11 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)11 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)9 ExampleTransformFunction (uk.gov.gchq.gaffer.function.ExampleTransformFunction)9 OperationChainValidator (uk.gov.gchq.gaffer.store.operation.OperationChainValidator)9 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)8 Schema (uk.gov.gchq.gaffer.store.schema.Schema)8 Signature (uk.gov.gchq.koryphe.signature.Signature)8 Map (java.util.Map)7 OperationChainOptimiser (uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser)7 Set (java.util.Set)6 Operation (uk.gov.gchq.gaffer.operation.Operation)6 Element (uk.gov.gchq.gaffer.data.element.Element)5 ElementTransformer (uk.gov.gchq.gaffer.data.element.function.ElementTransformer)5