use of uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation 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.ExtendedNamedOperation 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.ExtendedNamedOperation in project Gaffer by gchq.
the class AddNamedOperationHandler method doOperation.
/**
* Adds a NamedOperation to a cache which must be specified in the operation declarations file. An
* ExtendedNamedOperation is built using the fields on the AddNamedOperation. The operation name and operation chain
* fields must be set and cannot be left empty, or the build() method will fail and a runtime exception will be
* thrown. The handler then adds/overwrites the NamedOperation according toa an overwrite flag.
* @param operation the {@link uk.gov.gchq.gaffer.operation.Operation} to be executed
* @param context the operation chain context, containing the user who executed the operation
* @param store the {@link Store} the operation should be run on
* @return null (since the output is void)
* @throws OperationException if the operation on the cache fails
*/
@Override
public Void doOperation(final AddNamedOperation operation, final Context context, final Store store) throws OperationException {
try {
if (cache == null) {
throw new OperationException("Cache should be initialised in " + "resources/NamedOperationsDeclarations.json and referenced in store.properties");
}
validate(context.getUser(), operation.getOperationName(), operation.getOperationChain(), cache);
ExtendedNamedOperation extendedNamedOperation = new ExtendedNamedOperation.Builder().operationChain(operation.getOperationChain()).operationName(operation.getOperationName()).creatorId(context.getUser().getUserId()).readers(operation.getReadAccessRoles()).writers(operation.getWriteAccessRoles()).description(operation.getDescription()).build();
cache.addNamedOperation(extendedNamedOperation, operation.isOverwriteFlag(), context.getUser());
} catch (CacheOperationFailedException e) {
throw new OperationException(e.getMessage(), e);
}
return null;
}
use of uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation 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