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