Search in sources :

Example 1 with ExtendedNamedOperation

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);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) ExtendedNamedOperation(uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation) CacheOperationFailedException(uk.gov.gchq.gaffer.named.operation.cache.CacheOperationFailedException) ExtendedNamedOperation(uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) HashSet(java.util.HashSet)

Example 2 with ExtendedNamedOperation

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);
}
Also used : ExtendedNamedOperation(uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation) Test(org.junit.Test)

Example 3 with ExtendedNamedOperation

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));
}
Also used : ExtendedNamedOperation(uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation) Test(org.junit.Test)

Example 4 with ExtendedNamedOperation

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));
}
Also used : ArrayList(java.util.ArrayList) ExtendedNamedOperation(uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation) Test(org.junit.Test)

Example 5 with ExtendedNamedOperation

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);
}
Also used : ExtendedNamedOperation(uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation) Test(org.junit.Test)

Aggregations

ExtendedNamedOperation (uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation)14 Test (org.junit.Test)8 NamedOperation (uk.gov.gchq.gaffer.named.operation.NamedOperation)6 CacheOperationFailedException (uk.gov.gchq.gaffer.named.operation.cache.CacheOperationFailedException)4 OperationException (uk.gov.gchq.gaffer.operation.OperationException)3 AddNamedOperation (uk.gov.gchq.gaffer.named.operation.AddNamedOperation)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 WrappedCloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable)1 Operation (uk.gov.gchq.gaffer.operation.Operation)1 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)1