Search in sources :

Example 1 with Input

use of uk.gov.gchq.gaffer.operation.io.Input in project Gaffer by gchq.

the class GetWalks method validate.

@Override
public ValidationResult validate() {
    final ValidationResult result = InputOutput.super.validate();
    final int getEdgeOperations = getNumberOfGetEdgeOperations();
    if (getEdgeOperations < 1) {
        result.addError("No hops were provided. " + HOP_DEFINITION);
    } else {
        int i = 0;
        for (final OperationChain<Iterable<Element>> operation : operations) {
            if (operation.getOperations().isEmpty()) {
                result.addError("Operation chain " + i + " contains no operations");
            } else {
                final Operation firstOp = operation.getOperations().get(0);
                if (firstOp instanceof Input) {
                    if (null != ((Input) firstOp).getInput()) {
                        result.addError("The input for operations must be null.");
                    }
                } else {
                    result.addError("The first operation in operation chain " + i + ": " + firstOp.getClass().getName() + " is not be able to accept the input seeds. It must implement " + Input.class.getName());
                }
            }
            if (getNumberOfGetEdgeOperationsWithoutRepeats(operation) < 1 && i < (operations.size() - 1)) {
                // An operation does not contain a hop
                result.addError("All operations must contain a single hop. Operation " + i + " does not contain a hop. The only exception is the last operation, which is allowed to just fetch Entities. " + HOP_DEFINITION);
            } else if (getNumberOfGetEdgeOperationsWithoutRepeats(operation) > 1) {
                // An operation does not contain a hop
                result.addError("All operations must contain a single hop. Operation " + i + " contains multiple hops.");
            }
            i++;
        }
    }
    return result;
}
Also used : Input(uk.gov.gchq.gaffer.operation.io.Input) MultiEntityIdInput(uk.gov.gchq.gaffer.operation.io.MultiEntityIdInput) Operation(uk.gov.gchq.gaffer.operation.Operation) ValidationResult(uk.gov.gchq.koryphe.ValidationResult)

Example 2 with Input

use of uk.gov.gchq.gaffer.operation.io.Input in project Gaffer by gchq.

the class OperationChainValidator method validateInputOutputTypes.

protected Class<? extends Output> validateInputOutputTypes(final Operation operation, final ValidationResult validationResult, final Store store, final Class<? extends Output> input) {
    Class<? extends Output> output = input;
    if (null == input) {
        if (operation instanceof Output) {
            output = ((Output) operation).getClass();
        }
    } else {
        final Operation firstOp = getFirstOperation(operation);
        if (firstOp instanceof Input) {
            final Class<?> outputType = OperationUtil.getOutputType(input);
            final Class<?> inputType = OperationUtil.getInputType(((Input) firstOp));
            validationResult.add(OperationUtil.isValid(outputType, inputType));
        } else {
            validationResult.addError("Invalid combination of operations: " + input.getName() + " -> " + firstOp.getClass().getName() + ". " + input.getClass().getSimpleName() + " has an output but " + firstOp.getClass().getSimpleName() + " does not take an input.");
        }
        if (operation instanceof Output) {
            output = ((Output) operation).getClass();
        } else {
            output = null;
        }
    }
    return output;
}
Also used : Input(uk.gov.gchq.gaffer.operation.io.Input) Output(uk.gov.gchq.gaffer.operation.io.Output) Operation(uk.gov.gchq.gaffer.operation.Operation)

Aggregations

Operation (uk.gov.gchq.gaffer.operation.Operation)2 Input (uk.gov.gchq.gaffer.operation.io.Input)2 MultiEntityIdInput (uk.gov.gchq.gaffer.operation.io.MultiEntityIdInput)1 Output (uk.gov.gchq.gaffer.operation.io.Output)1 ValidationResult (uk.gov.gchq.koryphe.ValidationResult)1