Search in sources :

Example 6 with NamedOperation

use of uk.gov.gchq.gaffer.named.operation.NamedOperation in project Gaffer by gchq.

the class AddNamedOperationHandlerTest method shouldNotAllowUpdateToNamedOperationIfItCausesRecursion.

@Test
public void shouldNotAllowUpdateToNamedOperationIfItCausesRecursion() throws OperationException {
    String innocentOpName = "innocent";
    OperationChain innocent = new OperationChain.Builder().first(new GetElements<>()).build();
    addNamedOperation.setOperationName(innocentOpName);
    addNamedOperation.setOperationChain(innocent);
    handler.doOperation(addNamedOperation, context, store);
    OperationChain parent = new OperationChain.Builder().first(new NamedOperation(innocentOpName, "call down to currently innocent named op")).build();
    addNamedOperation.setOperationChain(parent);
    addNamedOperation.setOperationName(OPERATION_NAME);
    handler.doOperation(addNamedOperation, context, store);
    OperationChain recursive = new OperationChain.Builder().first(new NamedOperation(OPERATION_NAME, "")).build();
    addNamedOperation.setOperationName(innocentOpName);
    addNamedOperation.setOperationChain(recursive);
    addNamedOperation.setOverwriteFlag(true);
    exception.expect(OperationException.class);
    handler.doOperation(addNamedOperation, context, store);
}
Also used : OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) 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)

Example 7 with NamedOperation

use of uk.gov.gchq.gaffer.named.operation.NamedOperation 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 8 with NamedOperation

use of uk.gov.gchq.gaffer.named.operation.NamedOperation 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 9 with NamedOperation

use of uk.gov.gchq.gaffer.named.operation.NamedOperation in project Gaffer by gchq.

the class NamedOperationHandler method exposeNamedOperations.

private List<Operation> exposeNamedOperations(final OperationChain<?> opChain, final User user, final INamedOperationCache cache) throws CacheOperationFailedException {
    ArrayList<Operation> operations = new ArrayList<>();
    for (final Operation operation : opChain.getOperations()) {
        if (operation instanceof NamedOperation) {
            final NamedOperation namedOp = ((NamedOperation) operation);
            OperationChain<?> innerChain = cache.getNamedOperation(namedOp.getOperationName(), user).getOperationChain();
            updateOperationInput(innerChain.getOperations().get(0), namedOp.getSeeds());
            operations.addAll(exposeNamedOperations(innerChain, user, cache));
        } else {
            operations.add(operation);
        }
    }
    return operations;
}
Also used : ArrayList(java.util.ArrayList) ExtendedNamedOperation(uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Operation(uk.gov.gchq.gaffer.operation.Operation) ExtendedNamedOperation(uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation)

Example 10 with NamedOperation

use of uk.gov.gchq.gaffer.named.operation.NamedOperation 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)10 NamedOperation (uk.gov.gchq.gaffer.named.operation.NamedOperation)10 Test (org.junit.Test)7 AddNamedOperation (uk.gov.gchq.gaffer.named.operation.AddNamedOperation)5 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)4 CacheOperationFailedException (uk.gov.gchq.gaffer.named.operation.cache.CacheOperationFailedException)2 Operation (uk.gov.gchq.gaffer.operation.Operation)2 OperationException (uk.gov.gchq.gaffer.operation.OperationException)2 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ExpectedException (org.junit.rules.ExpectedException)1 WrappedCloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable)1 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)1 GetEntities (uk.gov.gchq.gaffer.operation.impl.get.GetEntities)1