use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class FunctionValidator method validateEntity.
protected ValidationResult validateEntity(final Map.Entry<String, ?> entityEntry, final Schema schema) {
final ValidationResult result = new ValidationResult();
if (null != entityEntry) {
final String group = entityEntry.getKey();
final SchemaEntityDefinition schemaEntityDefinition = schema.getEntity(group);
if (null == schemaEntityDefinition) {
result.addError("Entity group: " + group + " does not exist in the schema.");
}
}
return result;
}
use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class SchemaElementDefinitionValidator method validateAggregator.
private ValidationResult validateAggregator(final ElementAggregator aggregator, final SchemaElementDefinition elementDef) {
final ValidationResult result = new ValidationResult();
if (null == elementDef.getPropertyMap() || elementDef.getPropertyMap().isEmpty()) {
// if no properties then no aggregation should be provided
if (null != aggregator && !aggregator.getComponents().isEmpty()) {
result.addError("Groups with no properties should not have any aggregators");
}
return result;
}
if (!elementDef.isAggregate()) {
if (!elementDef.getGroupBy().isEmpty()) {
result.addError("Groups with aggregation disabled should not have groupBy properties.");
}
return result;
}
if (null == aggregator || null == aggregator.getComponents() || aggregator.getComponents().isEmpty()) {
result.addError("Some properties do not have aggregators defined.");
return result;
}
// if aggregate functions are defined then check all properties are aggregated
// also check that no identifiers are selected
final Set<String> aggregatedProperties = new HashSet<>();
if (null != aggregator.getComponents()) {
for (final TupleAdaptedBinaryOperator<String, ?> adaptedFunction : aggregator.getComponents()) {
final String[] selection = adaptedFunction.getSelection();
if (null != selection) {
for (final String key : selection) {
final IdentifierType idType = IdentifierType.fromName(key);
if (null == idType) {
if (elementDef.containsProperty(key)) {
aggregatedProperties.add(key);
} else {
result.addError("Unknown property used in an aggregator: " + key);
}
} else {
result.addError("Identifiers cannot be selected for aggregation: " + idType.name());
}
}
if (selection.length > 1) {
Boolean containsGroupByProp = null;
// Check properties are stored in the same position: groupBy, non-groupBy, visibility, timestamp
for (final String key : selection) {
if (key.equals(elementDef.getSchemaReference().getVisibilityProperty())) {
result.addError("The visibility property must be aggregated by itself. " + "It is currently aggregated in the tuple: " + Arrays.toString(selection) + ", by aggregate function: " + adaptedFunction.getBinaryOperator().getClass().getName());
break;
} else {
final boolean newContainsGroupByProp = elementDef.getGroupBy().contains(key);
if (null == containsGroupByProp) {
containsGroupByProp = newContainsGroupByProp;
} else if (newContainsGroupByProp != containsGroupByProp) {
result.addError("groupBy properties and non-groupBy properties (including timestamp) must be not be aggregated using the same BinaryOperator. " + "Selection tuple: " + Arrays.toString(selection) + ", is aggregated by: " + adaptedFunction.getBinaryOperator().getClass().getName());
break;
}
}
}
}
}
}
}
final Set<String> propertyNamesTmp = new HashSet<>(elementDef.getProperties());
propertyNamesTmp.removeAll(aggregatedProperties);
if (!propertyNamesTmp.isEmpty()) {
result.addError("No aggregator found for properties '" + propertyNamesTmp.toString() + "' in the supplied schema. " + "This framework requires that all of the defined properties have an aggregator function associated with them. " + "To disable aggregation for a group set the 'aggregate' field to false.");
}
return result;
}
use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class SchemaElementDefinitionValidator method validateFunctionArgumentTypes.
protected ValidationResult validateFunctionArgumentTypes(final ElementAggregator aggregator, 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 Signature inputSig = Signature.getInputSignature(adaptedFunction.getBinaryOperator());
result.add(inputSig.assignable(getTypeClasses(adaptedFunction.getSelection(), schemaElDef)));
final Signature outputSig = Signature.getOutputSignature(adaptedFunction.getBinaryOperator());
result.add(outputSig.assignable(getTypeClasses(adaptedFunction.getSelection(), schemaElDef)));
}
}
}
return result;
}
use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class ViewValidator method validate.
/**
* Checks all {@link java.util.function.Predicate}s and {@link java.util.function.Function}s defined are
* compatible with the identifiers and properties in the {@link Schema}
* and transient properties in the {@link View}.
*
* @param view the {@link View} to validate
* @param schema the {@link Schema} to validate the view against
* @param storeTraits the store traits
* @return true if the element definition is valid, otherwise false and an error is logged
*/
public ValidationResult validate(final View view, final Schema schema, final Set<StoreTrait> storeTraits) {
final boolean isStoreOrdered = storeTraits.contains(StoreTrait.ORDERED);
final ValidationResult result = new ValidationResult();
if (null != view) {
validateEntities(view, schema, storeTraits, isStoreOrdered, result);
validateEdge(view, schema, storeTraits, isStoreOrdered, result);
}
return result;
}
use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class ViewValidator method validateGroupBy.
protected ValidationResult validateGroupBy(final boolean isStoreOrdered, final String group, final ViewElementDefinition viewElDef, final SchemaElementDefinition schemaElDef) {
final ValidationResult result = new ValidationResult();
final Set<String> viewGroupBy = viewElDef.getGroupBy();
if (null != viewGroupBy && !viewGroupBy.isEmpty()) {
final Set<String> schemaGroupBy = schemaElDef.getGroupBy();
if (null != schemaGroupBy && schemaGroupBy.containsAll(viewGroupBy)) {
if (isStoreOrdered) {
final LinkedHashSet<String> schemaGroupBySubset = Sets.newLinkedHashSet(Iterables.limit(schemaGroupBy, viewGroupBy.size()));
if (!viewGroupBy.equals(schemaGroupBySubset)) {
result.addError("Group by properties for group " + group + " are not in the same order as the group by properties in the schema. View groupBy:" + viewGroupBy + ". Schema groupBy:" + schemaGroupBy);
}
}
} else {
result.addError("Group by properties for group " + group + " in the view are not all included in the group by field in the schema. View groupBy:" + viewGroupBy + ". Schema groupBy:" + schemaGroupBy);
}
}
return result;
}
Aggregations