Search in sources :

Example 21 with Operation

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());
}
Also used : OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Operation(uk.gov.gchq.gaffer.operation.Operation) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest) Test(org.junit.jupiter.api.Test)

Example 22 with Operation

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;
}
Also used : Operation(uk.gov.gchq.gaffer.operation.Operation)

Example 23 with Operation

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);
}
Also used : NamedOperationScoreResolver(uk.gov.gchq.gaffer.store.operation.resolver.named.NamedOperationScoreResolver) DefaultScoreResolver(uk.gov.gchq.gaffer.store.operation.resolver.DefaultScoreResolver) ScoreResolver(uk.gov.gchq.gaffer.store.operation.resolver.ScoreResolver) WhileScoreResolver(uk.gov.gchq.gaffer.store.operation.resolver.WhileScoreResolver) IfScoreResolver(uk.gov.gchq.gaffer.store.operation.resolver.IfScoreResolver) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IfScoreResolver(uk.gov.gchq.gaffer.store.operation.resolver.IfScoreResolver) NamedOperationScoreResolver(uk.gov.gchq.gaffer.store.operation.resolver.named.NamedOperationScoreResolver) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Operation(uk.gov.gchq.gaffer.operation.Operation) WhileScoreResolver(uk.gov.gchq.gaffer.store.operation.resolver.WhileScoreResolver)

Example 24 with Operation

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;
}
Also used : ArrayList(java.util.ArrayList) Operation(uk.gov.gchq.gaffer.operation.Operation) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Example 25 with Operation

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());
}
Also used : Operation(uk.gov.gchq.gaffer.operation.Operation) Predicate(java.util.function.Predicate)

Aggregations

Operation (uk.gov.gchq.gaffer.operation.Operation)136 Test (org.junit.jupiter.api.Test)88 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)49 NamedOperation (uk.gov.gchq.gaffer.named.operation.NamedOperation)44 Schema (uk.gov.gchq.gaffer.store.schema.Schema)41 Context (uk.gov.gchq.gaffer.store.Context)35 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)34 Store (uk.gov.gchq.gaffer.store.Store)28 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)26 LinkedHashMap (java.util.LinkedHashMap)21 GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)21 User (uk.gov.gchq.gaffer.user.User)21 ArrayList (java.util.ArrayList)18 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)18 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)17 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)16 HashSet (java.util.HashSet)15 HashMap (java.util.HashMap)13 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)13 OperationException (uk.gov.gchq.gaffer.operation.OperationException)13