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());
}
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;
}
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);
}
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());
}
}
}
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);
}
}
Aggregations