use of uk.gov.gchq.gaffer.named.operation.NamedOperation in project Gaffer by gchq.
the class AddNamedOperationHandlerTest method shouldNotAllowUpdateToNamedOperationIfItCausesRecursion.
@Test
public void shouldNotAllowUpdateToNamedOperationIfItCausesRecursion() throws OperationException {
String innocentOpName = "innocent";
OperationChain innocent = new OperationChain.Builder().first(new GetElements<>()).build();
addNamedOperation.setOperationName(innocentOpName);
addNamedOperation.setOperationChain(innocent);
handler.doOperation(addNamedOperation, context, store);
OperationChain parent = new OperationChain.Builder().first(new NamedOperation(innocentOpName, "call down to currently innocent named op")).build();
addNamedOperation.setOperationChain(parent);
addNamedOperation.setOperationName(OPERATION_NAME);
handler.doOperation(addNamedOperation, context, store);
OperationChain recursive = new OperationChain.Builder().first(new NamedOperation(OPERATION_NAME, "")).build();
addNamedOperation.setOperationName(innocentOpName);
addNamedOperation.setOperationChain(recursive);
addNamedOperation.setOverwriteFlag(true);
exception.expect(OperationException.class);
handler.doOperation(addNamedOperation, context, store);
}
use of uk.gov.gchq.gaffer.named.operation.NamedOperation in project Gaffer by gchq.
the class NamedOperationJCSCacheTest method shouldReturnSetOfNamedOperationsThatAUserCanExecute.
@Test
public void shouldReturnSetOfNamedOperationsThatAUserCanExecute() throws CacheOperationFailedException {
cache.addNamedOperation(standard, false, standardUser);
ExtendedNamedOperation alt = alternative;
alt.setOperationName("alt");
cache.addNamedOperation(alt, false, advancedUser);
Set<NamedOperation> actual = Sets.newHashSet(cache.getAllNamedOperations(standardUser, true));
assert (actual.contains(standard.getBasic()));
assert (actual.contains(alt.getBasic()));
assert (actual.size() == 2);
}
use of uk.gov.gchq.gaffer.named.operation.NamedOperation in project Gaffer by gchq.
the class NamedOperationJCSCacheTest method shouldNotReturnANamedOperationThatAUserCannotExecute.
@Test
public void shouldNotReturnANamedOperationThatAUserCannotExecute() throws CacheOperationFailedException {
cache.addNamedOperation(standard, false, standardUser);
ExtendedNamedOperation noReadAccess = new ExtendedNamedOperation.Builder().creatorId(advancedUser.getUserId()).description("an operation that a standard user cannot execute").operationName("test").readers(writers).writers(writers).operationChain(standardOpChain).build();
cache.addNamedOperation(noReadAccess, false, advancedUser);
Set<NamedOperation> actual = Sets.newHashSet(cache.getAllNamedOperations(standardUser, true));
assert (actual.contains(standard.getBasic()));
assert (actual.size() == 1);
}
use of uk.gov.gchq.gaffer.named.operation.NamedOperation in project Gaffer by gchq.
the class NamedOperationHandler method exposeNamedOperations.
private List<Operation> exposeNamedOperations(final OperationChain<?> opChain, final User user, final INamedOperationCache cache) throws CacheOperationFailedException {
ArrayList<Operation> operations = new ArrayList<>();
for (final Operation operation : opChain.getOperations()) {
if (operation instanceof NamedOperation) {
final NamedOperation namedOp = ((NamedOperation) operation);
OperationChain<?> innerChain = cache.getNamedOperation(namedOp.getOperationName(), user).getOperationChain();
updateOperationInput(innerChain.getOperations().get(0), namedOp.getSeeds());
operations.addAll(exposeNamedOperations(innerChain, user, cache));
} else {
operations.add(operation);
}
}
return operations;
}
use of uk.gov.gchq.gaffer.named.operation.NamedOperation in project Gaffer by gchq.
the class AddNamedOperationHandlerTest method shouldNotAddNamedOperationIfItContainsAnOperationWhichReferencesTheParent.
@Test
public void shouldNotAddNamedOperationIfItContainsAnOperationWhichReferencesTheParent() throws CacheOperationFailedException, OperationException {
NamedOperation op = new NamedOperation("parent", "this is the parent which has not yet been created");
OperationChain opChain = new OperationChain.Builder().first(op).build();
ExtendedNamedOperation child = new ExtendedNamedOperation.Builder().operationChain(opChain).operationName(OPERATION_NAME).build();
handler.getCache().addNamedOperation(child, false, context.getUser());
OperationChain parentOpChain = new OperationChain.Builder().first(operation).build();
addNamedOperation.setOperationName("parent");
addNamedOperation.setOperationChain(parentOpChain);
exception.expect(OperationException.class);
handler.doOperation(addNamedOperation, context, store);
}
Aggregations