use of uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation 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.ExtendedNamedOperation in project Gaffer by gchq.
the class NamedOperationJCSCacheTest method shouldThrowExceptionWhenAddingIfKeyIsNull.
@Test
public void shouldThrowExceptionWhenAddingIfKeyIsNull() throws CacheOperationFailedException {
ExtendedNamedOperation op = standard;
op.setOperationName(null);
exception.expect(CacheOperationFailedException.class);
cache.addNamedOperation(op, false, standardUser);
}
use of uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation in project Gaffer by gchq.
the class NamedOperationJCSCacheTest method shouldAllowUsersReadAccessToTheirOwnNamedOperations.
@Test
public void shouldAllowUsersReadAccessToTheirOwnNamedOperations() throws CacheOperationFailedException {
ExtendedNamedOperation op = new ExtendedNamedOperation.Builder().operationName(OPERATION_NAME).creatorId(standardUser.getUserId()).operationChain(standardOpChain).readers(new ArrayList<>()).writers(writers).build();
cache.addNamedOperation(op, false, standardUser);
assertEquals(op, cache.getNamedOperation(OPERATION_NAME, standardUser));
}
use of uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation in project Gaffer by gchq.
the class NamedOperationJCSCacheTest method shouldAllowUsersWriteAccessToTheirOwnOperations.
@Test
public void shouldAllowUsersWriteAccessToTheirOwnOperations() throws CacheOperationFailedException {
ExtendedNamedOperation op = new ExtendedNamedOperation.Builder().operationName(OPERATION_NAME).creatorId(standardUser.getUserId()).operationChain(standardOpChain).readers(readers).writers(new ArrayList<>()).build();
cache.addNamedOperation(op, false, standardUser);
cache.addNamedOperation(standard, true, standardUser);
assertEquals(standard, cache.getNamedOperation(OPERATION_NAME, standardUser));
}
use of uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation in project Gaffer by gchq.
the class NamedOperationJCSCacheTest method shouldAddNamedOperation.
@Test
public void shouldAddNamedOperation() throws CacheOperationFailedException {
cache.addNamedOperation(standard, false, standardUser);
ExtendedNamedOperation namedOperation = cache.getNamedOperation(OPERATION_NAME, standardUser);
assertEquals(standard, namedOperation);
}
Aggregations