Search in sources :

Example 26 with ValidationResult

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

the class OperationChainHandler method prepareOperationChain.

public <O> OperationChain<O> prepareOperationChain(final OperationChain<O> operationChain, final Context context, final Store store) {
    final ValidationResult validationResult = opChainValidator.validate(operationChain, context.getUser(), store);
    if (!validationResult.isValid()) {
        throw new IllegalArgumentException("Operation chain is invalid. " + validationResult.getErrorString());
    }
    OperationChain<O> optimisedOperationChain = operationChain;
    for (final OperationChainOptimiser opChainOptimiser : opChainOptimisers) {
        optimisedOperationChain = opChainOptimiser.optimise(optimisedOperationChain);
    }
    return optimisedOperationChain;
}
Also used : ValidationResult(uk.gov.gchq.koryphe.ValidationResult) OperationChainOptimiser(uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser)

Example 27 with ValidationResult

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

the class AggregateHandler method doOperation.

public Iterable<? extends Element> doOperation(final Aggregate operation, final Schema schema) throws OperationException {
    if (null == operation.getInput()) {
        throw new OperationException("Aggregate operation has null iterable of elements");
    }
    // all elements should be used. This matches the way a View works.
    if (null == operation.getEntities() && null == operation.getEdges()) {
        final Map<String, AggregatePair> entityMap = new HashMap<>();
        schema.getEntityGroups().forEach(e -> entityMap.put(e, new AggregatePair()));
        operation.setEntities(entityMap);
        final Map<String, AggregatePair> edgeMap = new HashMap<>();
        schema.getEdgeGroups().forEach(e -> edgeMap.put(e, new AggregatePair()));
        operation.setEdges(edgeMap);
    }
    final ValidationResult result = validator.validate(operation, schema);
    if (!result.isValid()) {
        throw new OperationException("Aggregate operation is invalid. " + result.getErrorString());
    }
    return AggregatorUtil.queryAggregate(operation.getInput(), schema, buildView(operation));
}
Also used : HashMap(java.util.HashMap) AggregatePair(uk.gov.gchq.gaffer.operation.util.AggregatePair) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Example 28 with ValidationResult

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

the class TransformHandler method doOperation.

public Iterable<? extends Element> doOperation(final Transform operation, final Schema schema) throws OperationException {
    if (null == operation.getInput()) {
        throw new OperationException("Transform operation has null iterable of elements");
    }
    // all elements should be used. This matches the way a View works.
    if (null == operation.getEntities() && null == operation.getEdges()) {
        final Map<String, ElementTransformer> entityMap = new HashMap<>();
        schema.getEntityGroups().forEach(e -> entityMap.put(e, new ElementTransformer()));
        operation.setEntities(entityMap);
        final Map<String, ElementTransformer> edgeMap = new HashMap<>();
        schema.getEdgeGroups().forEach(e -> edgeMap.put(e, new ElementTransformer()));
        operation.setEdges(edgeMap);
    }
    final ValidationResult result = validator.validate(operation, schema);
    if (!result.isValid()) {
        throw new OperationException("Transform operation is invalid. " + result.getErrorString());
    }
    return new StreamTransformIterable(operation);
}
Also used : StreamTransformIterable(uk.gov.gchq.gaffer.store.operation.util.StreamTransformIterable) HashMap(java.util.HashMap) ElementTransformer(uk.gov.gchq.gaffer.data.element.function.ElementTransformer) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Example 29 with ValidationResult

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

the class FilterHandler method doOperation.

public Iterable<? extends Element> doOperation(final Filter operation, final Schema schema) throws OperationException {
    if (null == operation.getInput()) {
        throw new OperationException("Filter operation has null iterable of elements");
    }
    // all elements should be used. This matches the way a View works.
    if (null == operation.getEntities() && null == operation.getEdges()) {
        final Map<String, ElementFilter> entityMap = new HashMap<>();
        schema.getEntityGroups().forEach(e -> entityMap.put(e, new ElementFilter()));
        operation.setEntities(entityMap);
        final Map<String, ElementFilter> edgeMap = new HashMap<>();
        schema.getEdgeGroups().forEach(e -> edgeMap.put(e, new ElementFilter()));
        operation.setEdges(edgeMap);
    }
    final ValidationResult result = validator.validate(operation, schema);
    if (!result.isValid()) {
        throw new OperationException("Filter operation is invalid. " + result.getErrorString());
    }
    return new StreamFilterIterable(operation);
}
Also used : StreamFilterIterable(uk.gov.gchq.gaffer.operation.util.StreamFilterIterable) HashMap(java.util.HashMap) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Example 30 with ValidationResult

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

the class ViewValidatorTest method shouldValidateAndReturnTrueNoGroupByProperties.

@Test
public void shouldValidateAndReturnTrueNoGroupByProperties() {
    // Given
    final ViewValidator validator = new ViewValidator();
    final View view = new View.Builder().entity(TestGroups.ENTITY).edge(TestGroups.EDGE).build();
    final Schema schema = new Schema.Builder().type("vertex", String.class).type("true", Boolean.class).entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().vertex("vertex").build()).edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().source("vertex").destination("vertex").directed("true").build()).build();
    // When
    final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS);
    // Then
    assertTrue(result.isValid());
}
Also used : ValidationResult(uk.gov.gchq.koryphe.ValidationResult) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.jupiter.api.Test)

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