Search in sources :

Example 86 with Operation

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

the class GraphTest method shouldFillSchemaViewAndManipulateViewRemovingBlacklistedEdgeLeavingEmptyViewUsingUpdateViewHook.

@Test
public void shouldFillSchemaViewAndManipulateViewRemovingBlacklistedEdgeLeavingEmptyViewUsingUpdateViewHook() throws OperationException {
    // Given
    operation = new GetElements.Builder().build();
    final UpdateViewHook updateViewHook = new UpdateViewHook.Builder().blackListElementGroups(Collections.singleton(TestGroups.EDGE)).build();
    given(opChain.getOperations()).willReturn(Lists.newArrayList(operation));
    given(opChain.shallowClone()).willReturn(clonedOpChain);
    given(clonedOpChain.getOperations()).willReturn(Lists.newArrayList(operation));
    given(clonedOpChain.flatten()).willReturn(Arrays.asList(operation));
    final Store store = mock(Store.class);
    given(store.getSchema()).willReturn(new Schema.Builder().edge(TestGroups.EDGE_5, new SchemaEdgeDefinition()).edge(TestGroups.EDGE, new SchemaEdgeDefinition()).build());
    given(store.getProperties()).willReturn(new StoreProperties());
    final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).addHook(updateViewHook).build()).storeProperties(StreamUtil.storeProps(getClass())).store(store).build();
    final ArgumentCaptor<OperationChain> captor = ArgumentCaptor.forClass(OperationChain.class);
    final ArgumentCaptor<Context> contextCaptor1 = ArgumentCaptor.forClass(Context.class);
    given(store.execute(captor.capture(), contextCaptor1.capture())).willReturn(new ArrayList<>());
    // When / Then
    graph.execute(opChain, user);
    final List<Operation> ops = captor.getValue().getOperations();
    JsonAssert.assertEquals(new View.Builder().edge(TestGroups.EDGE_5).build().toCompactJson(), ((GetElements) ops.get(0)).getView().toCompactJson());
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Store(uk.gov.gchq.gaffer.store.Store) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Operation(uk.gov.gchq.gaffer.operation.Operation) UpdateViewHook(uk.gov.gchq.gaffer.graph.hook.UpdateViewHook) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 87 with Operation

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

the class AddOperationsToChain method addOperationsToChain.

private List<Operation> addOperationsToChain(final Operations<?> operations, final AdditionalOperations additionalOperations) {
    final List<Operation> opList = new ArrayList<>();
    if (null != operations && !operations.getOperations().isEmpty()) {
        final Class<? extends Operation> operationsClass = operations.getOperationsClass();
        for (final Operation originalOp : operations.getOperations()) {
            final List<Operation> beforeOps = additionalOperations.getBefore().get(originalOp.getClass().getName());
            addOps(beforeOps, operationsClass, opList);
            if (originalOp instanceof Operations) {
                final List<Operation> nestedOpList = addOperationsToChain((Operations) originalOp, additionalOperations);
                try {
                    ((Operations) originalOp).updateOperations(nestedOpList);
                } catch (final Exception e) {
                // ignore exception - this would be caused by the operation list not allowing modifications
                }
            }
            opList.add(originalOp);
            final List<Operation> afterOps = additionalOperations.getAfter().get(originalOp.getClass().getName());
            addOps(afterOps, operationsClass, opList);
        }
    }
    return opList;
}
Also used : ArrayList(java.util.ArrayList) Operation(uk.gov.gchq.gaffer.operation.Operation) Operations(uk.gov.gchq.gaffer.operation.Operations)

Example 88 with Operation

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

the class NamedOperationResolver method resolveNamedOperations.

private void resolveNamedOperations(final Operations<?> operations, final User user) {
    final List<Operation> updatedOperations = new ArrayList<>(operations.getOperations().size());
    for (final Operation operation : operations.getOperations()) {
        if (operation instanceof NamedOperation) {
            updatedOperations.addAll(resolveNamedOperation((NamedOperation) operation, user));
        } else {
            if (operation instanceof Operations) {
                resolveNamedOperations(((Operations<?>) operation), user);
            }
            updatedOperations.add(operation);
        }
    }
    operations.updateOperations((List) updatedOperations);
}
Also used : ArrayList(java.util.ArrayList) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Operation(uk.gov.gchq.gaffer.operation.Operation) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Operations(uk.gov.gchq.gaffer.operation.Operations)

Example 89 with Operation

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

the class UpdateViewHook method updateView.

private void updateView(final OperationChain<?> opChain) {
    for (final Operation operation : opChain.flatten()) {
        if (operation instanceof OperationView) {
            final OperationView operationView = (OperationView) operation;
            final View.Builder viewBuilder = mergeView(operationView, getViewToMerge());
            if ((null != whiteListElementGroups && !whiteListElementGroups.isEmpty()) || (null != blackListElementGroups && !blackListElementGroups.isEmpty())) {
                viewBuilder.removeEntities(this::removeElementGroups);
                viewBuilder.removeEdges(this::removeElementGroups);
            }
            if (!addExtraGroups && null != operationView.getView()) {
                final Set<String> entityGroups = operationView.getView().getEntityGroups();
                viewBuilder.removeEntities(grp -> null == entityGroups || !entityGroups.contains(grp.getKey()));
                final Set<String> edgeGroups = operationView.getView().getEdgeGroups();
                viewBuilder.removeEdges(grp -> null == edgeGroups || !edgeGroups.contains(grp.getKey()));
            }
            viewBuilder.expandGlobalDefinitions();
            operationView.setView(viewBuilder.build());
        }
    }
}
Also used : OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView) Operation(uk.gov.gchq.gaffer.operation.Operation) NamedView(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView)

Example 90 with Operation

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

the class SchemaMigration method preExecute.

@Override
public void preExecute(final OperationChain<?> opChain, final Context context) {
    if (!edges.isEmpty() || !entities.isEmpty()) {
        final List<Operation> updatedOps = new ArrayList<>();
        for (final Operation op : new ArrayList<>(opChain.flatten())) {
            updatedOps.add(op);
            if (OperationView.hasView(op)) {
                updatedOps.addAll(migrateOperation(op));
            }
        }
        opChain.updateOperations(updatedOps);
    }
}
Also used : ArrayList(java.util.ArrayList) Operation(uk.gov.gchq.gaffer.operation.Operation)

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