Search in sources :

Example 11 with ExtendedNamedOperation

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

Example 12 with ExtendedNamedOperation

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

Example 13 with ExtendedNamedOperation

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;
}
Also used : ExtendedNamedOperation(uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation) CacheOperationFailedException(uk.gov.gchq.gaffer.named.operation.cache.CacheOperationFailedException) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Example 14 with ExtendedNamedOperation

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);
}
Also used : OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ExtendedNamedOperation(uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) ExtendedNamedOperation(uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) 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