use of uk.gov.gchq.gaffer.named.operation.NamedOperation in project Gaffer by gchq.
the class NamedOperationJCSCache method getAllNamedOperations.
/**
* Gets all the keys from the cache and iterates through each ExtendedNamedOperation stored in the cache. Assuming
* the user has read permission (therefore can execute the NamedOperation) it either adds a NamedOperation or
* ExtendedNamedOperation to a set, depending on the simple flag which would ordinarily be set to true.
*
* @param user The user making the request
* @param simple flag determining whether to return a set of NamedOperations with a basic name and description or
* the full ExtendedNamedOperation with details of the opChain, and access controls
* @return a set of NamedOperations
*/
@Override
public CloseableIterable<NamedOperation> getAllNamedOperations(final User user, final boolean simple) {
Set keys = getCache().getGroupKeys(CACHE_GROUP);
Set<NamedOperation> executables = new HashSet<>();
for (final Object key : keys) {
try {
ExtendedNamedOperation op = getFromCache((String) key);
if (op.hasReadAccess(user)) {
if (simple) {
executables.add(op.getBasic());
} else {
executables.add(op);
}
}
} catch (CacheOperationFailedException e) {
LOGGER.error(e.getMessage(), e);
}
}
return new WrappedCloseableIterable<>(executables);
}
use of uk.gov.gchq.gaffer.named.operation.NamedOperation in project Gaffer by gchq.
the class NamedOperationJCSCacheTest method shouldBeAbleToReturnFullExtendedOperationChain.
@Test
public void shouldBeAbleToReturnFullExtendedOperationChain() 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, false));
assert (actual.contains(standard));
assert (actual.contains(alt));
assert (actual.size() == 2);
}
use of uk.gov.gchq.gaffer.named.operation.NamedOperation in project Gaffer by gchq.
the class AddNamedOperationHandler method validate.
private void validate(final User user, final List<String> parentOperations, final OperationChain<?> operationChain, final INamedOperationCache cache) throws CacheOperationFailedException, OperationException {
for (final Operation op : operationChain.getOperations()) {
if (op instanceof NamedOperation) {
if (parentOperations.contains(((NamedOperation) op).getOperationName())) {
throw new OperationException("The Operation Chain must not be recursive");
}
ExtendedNamedOperation operation = cache.getNamedOperation(((NamedOperation) op).getOperationName(), user);
if (operation == null) {
throw new OperationException("The Operation " + ((NamedOperation) op).getOperationName() + " references an operation which doesn't exist. Unable to create operation");
}
parentOperations.add(((NamedOperation) op).getOperationName());
validate(user, parentOperations, operation.getOperationChain(), cache);
parentOperations.remove(((NamedOperation) op).getOperationName());
}
}
}
use of uk.gov.gchq.gaffer.named.operation.NamedOperation in project Gaffer by gchq.
the class AddNamedOperationHandlerTest method shouldAllowForNonRecursiveNamedOperationsToBeNested.
@Test
public void shouldAllowForNonRecursiveNamedOperationsToBeNested() {
try {
OperationChain child = new OperationChain.Builder().first(new AddElements()).build();
addNamedOperation.setOperationChain(child);
addNamedOperation.setOperationName("child");
handler.doOperation(addNamedOperation, context, store);
OperationChain parent = new OperationChain.Builder().first(new NamedOperation("child", "")).then(new GetElements<>()).build();
addNamedOperation.setOperationChain(parent);
addNamedOperation.setOperationName("parent");
handler.doOperation(addNamedOperation, context, store);
OperationChain grandparent = new OperationChain.Builder().first(new AddElements()).then(new NamedOperation("parent", "")).then(new NamedOperation("child", "")).then(new GetEntities<>()).build();
addNamedOperation.setOperationChain(grandparent);
addNamedOperation.setOperationName("grandparent");
handler.doOperation(addNamedOperation, context, store);
assert (cacheContains("grandparent"));
} catch (final Exception e) {
fail("Expected test to pass without error");
}
}
use of uk.gov.gchq.gaffer.named.operation.NamedOperation in project Gaffer by gchq.
the class AddNamedOperationHandlerTest method shouldNotAllowNamedOperationToBeAddedContainingANamedOperationThatDoesNotExist.
@Test
public void shouldNotAllowNamedOperationToBeAddedContainingANamedOperationThatDoesNotExist() throws OperationException {
NamedOperation op = new NamedOperation("parent", "this is the parent which has not yet been created");
OperationChain opChain = new OperationChain.Builder().first(op).build();
addNamedOperation.setOperationChain(opChain);
addNamedOperation.setOperationName(OPERATION_NAME);
exception.expect(OperationException.class);
handler.doOperation(addNamedOperation, context, store);
}
Aggregations