use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.
the class IfTest method shouldUpdateOperations.
@Test
public void shouldUpdateOperations() {
// Given
final GetElements getElements = new GetElements.Builder().input(new EntitySeed("A")).build();
final OperationChain opChain = new OperationChain.Builder().first(new GetAllElements()).then(new Limit<>(3)).build();
final If<Object, Object> ifOp = new If.Builder<>().condition(false).build();
final Collection<Operation> opList = Lists.newArrayList(new OperationChain<>(), getElements, opChain);
// When
ifOp.updateOperations(opList);
// Then
assertNotNull(ifOp.getThen());
assertNotNull(ifOp.getOtherwise());
assertEquals(getElements, ifOp.getThen());
assertEquals(opChain, ifOp.getOtherwise());
}
use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.
the class OperationChainHandler method doOperation.
@Override
public OUT doOperation(final OperationChain<OUT> operationChain, final Context context, final Store store) throws OperationException {
final OperationChain<OUT> preparedOperationChain = prepareOperationChain(operationChain, context, store);
Object result = null;
for (final Operation op : preparedOperationChain.getOperations()) {
updateOperationInput(op, result);
result = store.handleOperation(op, context);
}
return (OUT) result;
}
use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.
the class ScoreOperationChainHandler method addDefaultScoreResolvers.
/**
* Adds Gaffer's native {@link ScoreResolver} implementations to the list of available <code>ScoreResolver</code>s.
* Any new implementations should be added to the map in this method, along with their respective class.
*
* @return a map of Operation class to ScoreResolver implementation
*/
private static Map<Class<? extends Operation>, ScoreResolver> addDefaultScoreResolvers() {
final Map<Class<? extends Operation>, ScoreResolver> defaultResolvers = new HashMap<>();
defaultResolvers.put(NamedOperation.class, new NamedOperationScoreResolver());
defaultResolvers.put(If.class, new IfScoreResolver());
defaultResolvers.put(While.class, new WhileScoreResolver());
return Collections.unmodifiableMap(defaultResolvers);
}
use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.
the class ForEachHandler method doOperation.
@Override
public Iterable<? extends O> doOperation(final ForEach<I, O> forEach, final Context context, final Store store) throws OperationException {
if (null == forEach.getOperation()) {
throw new OperationException("Operation cannot be null");
}
if (null == forEach.getInput()) {
throw new OperationException("Inputs cannot be null");
}
final List<O> results = new ArrayList<>();
for (final I input : forEach.getInput()) {
final Operation clonedOperation = forEach.getOperation().shallowClone();
OperationHandlerUtil.updateOperationInput(clonedOperation, input);
results.add(executeOperation(clonedOperation, context, store));
}
return results;
}
use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.
the class GetWalksHandler method applyConditionalFiltering.
private List<Walk> applyConditionalFiltering(final Stream<Walk> walks, final GetWalks getWalks, final Context context, final Store store) {
if (null == getWalks.getConditional() || null == getWalks.getConditional().getPredicate()) {
return walks.collect(Collectors.toList());
}
final Operation transformOperation = getWalks.getConditional().getTransform();
final Predicate conditionalPredicate = getWalks.getConditional().getPredicate();
final WalkPredicate walkPredicate = new WalkPredicate(transformOperation, conditionalPredicate, context, store);
return walks.filter(walkPredicate::test).collect(Collectors.toList());
}
Aggregations