use of uk.gov.gchq.koryphe.signature.Signature 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;
}
use of uk.gov.gchq.koryphe.signature.Signature in project gaffer-doc by gchq.
the class PropertiesWalkthrough method listAggregators.
protected boolean listAggregators(final Class<?> clazz) {
final List<String> aggregateClasses = new ArrayList<>();
for (final BinaryOperator function : AGGREGATE_FUNCTIONS) {
final Signature signature = Signature.getInputSignature(function);
if (signature.assignable(clazz).isValid()) {
aggregateClasses.add(WalkthroughStrSubstitutor.getJavaDocLink(function.getClass(), false));
}
}
if (!aggregateClasses.isEmpty()) {
print(AGGREGATORS_KEY, "\nAggregators:");
print(AGGREGATORS_KEY, "\n- " + StringUtils.join(aggregateClasses, "\n- "));
}
return !aggregateClasses.isEmpty();
}
use of uk.gov.gchq.koryphe.signature.Signature in project gaffer-doc by gchq.
the class PropertiesWalkthrough method listPredicates.
protected boolean listPredicates(final Class<?> clazz) {
final List<String> validateClasses = new ArrayList<>();
for (final Predicate function : PREDICATES) {
try {
final Signature signature = Signature.getInputSignature(function);
if (signature.assignable(clazz).isValid()) {
validateClasses.add(WalkthroughStrSubstitutor.getJavaDocLink(function.getClass(), false));
}
} catch (final Exception e) {
// just add the function.
validateClasses.add(WalkthroughStrSubstitutor.getJavaDocLink(function.getClass(), false));
}
}
if (!validateClasses.isEmpty()) {
print(PREDICATES_KEY, "\nPredicates:");
print(PREDICATES_KEY, "\n- " + StringUtils.join(validateClasses, "\n- "));
}
return !validateClasses.isEmpty();
}
use of uk.gov.gchq.koryphe.signature.Signature in project Gaffer by gchq.
the class SchemaElementDefinitionValidator method validateFunctionArgumentTypes.
protected ValidationResult validateFunctionArgumentTypes(final ElementFilter filter, final SchemaElementDefinition schemaElDef) {
final ValidationResult result = new ValidationResult();
if (null != filter && null != filter.getComponents()) {
for (final TupleAdaptedPredicate<String, ?> adaptedPredicate : filter.getComponents()) {
if (null == adaptedPredicate.getPredicate()) {
result.addError(filter.getClass().getSimpleName() + " contains a null function.");
} else {
final Signature inputSig = Signature.getInputSignature(adaptedPredicate.getPredicate());
result.add(inputSig.assignable(getTypeClasses(adaptedPredicate.getSelection(), schemaElDef)));
}
}
}
return result;
}
use of uk.gov.gchq.koryphe.signature.Signature in project Gaffer by gchq.
the class ViewValidator method validateFunctionArgumentTypes.
private ValidationResult validateFunctionArgumentTypes(final ElementFilter filter, final ViewElementDefinition viewElDef, final SchemaElementDefinition schemaElDef) {
final ValidationResult result = new ValidationResult();
if (null != filter && null != filter.getComponents()) {
for (final TupleAdaptedPredicate<String, ?> adaptedPredicate : filter.getComponents()) {
if (null == adaptedPredicate.getPredicate()) {
result.addError(filter.getClass().getSimpleName() + " contains a null function.");
} else {
final Class[] inputTypeClasses = getTypeClasses(adaptedPredicate.getSelection(), viewElDef, schemaElDef);
if (!ArrayUtils.contains(inputTypeClasses, null)) {
final Signature inputSig = Signature.getInputSignature(adaptedPredicate.getPredicate());
result.add(inputSig.assignable(inputTypeClasses));
}
}
}
}
return result;
}
Aggregations