Search in sources :

Example 1 with UnwrapEntityId

use of uk.gov.gchq.gaffer.data.element.function.UnwrapEntityId in project Gaffer by gchq.

the class GetWalksHandler method executeWhileOperation.

private List<?> executeWhileOperation(final OperationChain<Iterable<Element>> operation, final List<?> seeds, final Integer resultLimit, final Context context, final Store store, final int hops, final AdjacencyMaps adjacencyMaps, final EntityMaps entityMaps) throws OperationException {
    List<?> resultSeeds = seeds;
    final While whileOp = (While) operation.getOperations().get(0);
    if (null != whileOp.getOperation()) {
        validateWhileOperation(whileOp);
        final OperationHandler opHandler = store.getOperationHandler(While.class);
        if (null == opHandler) {
            throw new UnsupportedOperationException("While operations are not supported by this store");
        }
        if (!(opHandler instanceof WhileHandler)) {
            throw new UnsupportedOperationException("To use While operations within GetWalks, the While handler must be a " + WhileHandler.class.getName());
        }
        final WhileHandler whileHandler = (WhileHandler) opHandler;
        whileHandler.validateMaxRepeats(whileOp);
        // Change the transform to unwrap entity ids first.
        if (null != whileOp.getConditional() && null != whileOp.getConditional().getTransform()) {
            whileOp.getConditional().setTransform(new OperationChain<>(new Map.Builder<>().first(new IterableFunction.Builder<>().first(new UnwrapEntityId()).build()).build(), whileOp.getConditional().getTransform()));
        }
        for (int repeatCount = 0; repeatCount < whileOp.getMaxRepeats(); repeatCount++) {
            final While whileOpClone = whileOp.shallowClone();
            if (!whileHandler.isSatisfied(resultSeeds, whileOpClone, context, store)) {
                break;
            }
            resultSeeds = executeOperation((Output) whileOpClone.getOperation(), resultSeeds, resultLimit, context, store, hops, adjacencyMaps, entityMaps);
        }
    }
    return resultSeeds;
}
Also used : Output(uk.gov.gchq.gaffer.operation.io.Output) While(uk.gov.gchq.gaffer.operation.impl.While) UnwrapEntityId(uk.gov.gchq.gaffer.data.element.function.UnwrapEntityId)

Aggregations

UnwrapEntityId (uk.gov.gchq.gaffer.data.element.function.UnwrapEntityId)1 While (uk.gov.gchq.gaffer.operation.impl.While)1 Output (uk.gov.gchq.gaffer.operation.io.Output)1