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;
}
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));
}
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);
}
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);
}
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());
}
Aggregations