Search in sources :

Example 1 with NamedOperation

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

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

the class NamedOperationJCSCacheTest method shouldBeAbleToReturnFullExtendedOperationChain.

@Test
public void shouldBeAbleToReturnFullExtendedOperationChain() 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, false));
    assert (actual.contains(standard));
    assert (actual.contains(alt));
    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 3 with NamedOperation

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

the class AddNamedOperationHandler method validate.

private void validate(final User user, final List<String> parentOperations, final OperationChain<?> operationChain, final INamedOperationCache cache) throws CacheOperationFailedException, OperationException {
    for (final Operation op : operationChain.getOperations()) {
        if (op instanceof NamedOperation) {
            if (parentOperations.contains(((NamedOperation) op).getOperationName())) {
                throw new OperationException("The Operation Chain must not be recursive");
            }
            ExtendedNamedOperation operation = cache.getNamedOperation(((NamedOperation) op).getOperationName(), user);
            if (operation == null) {
                throw new OperationException("The Operation " + ((NamedOperation) op).getOperationName() + " references an operation which doesn't exist. Unable to create operation");
            }
            parentOperations.add(((NamedOperation) op).getOperationName());
            validate(user, parentOperations, operation.getOperationChain(), cache);
            parentOperations.remove(((NamedOperation) op).getOperationName());
        }
    }
}
Also used : AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) 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) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) ExtendedNamedOperation(uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Example 4 with NamedOperation

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

the class AddNamedOperationHandlerTest method shouldAllowForNonRecursiveNamedOperationsToBeNested.

@Test
public void shouldAllowForNonRecursiveNamedOperationsToBeNested() {
    try {
        OperationChain child = new OperationChain.Builder().first(new AddElements()).build();
        addNamedOperation.setOperationChain(child);
        addNamedOperation.setOperationName("child");
        handler.doOperation(addNamedOperation, context, store);
        OperationChain parent = new OperationChain.Builder().first(new NamedOperation("child", "")).then(new GetElements<>()).build();
        addNamedOperation.setOperationChain(parent);
        addNamedOperation.setOperationName("parent");
        handler.doOperation(addNamedOperation, context, store);
        OperationChain grandparent = new OperationChain.Builder().first(new AddElements()).then(new NamedOperation("parent", "")).then(new NamedOperation("child", "")).then(new GetEntities<>()).build();
        addNamedOperation.setOperationChain(grandparent);
        addNamedOperation.setOperationName("grandparent");
        handler.doOperation(addNamedOperation, context, store);
        assert (cacheContains("grandparent"));
    } catch (final Exception e) {
        fail("Expected test to pass without error");
    }
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) 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) CacheOperationFailedException(uk.gov.gchq.gaffer.named.operation.cache.CacheOperationFailedException) OperationException(uk.gov.gchq.gaffer.operation.OperationException) ExpectedException(org.junit.rules.ExpectedException) GetEntities(uk.gov.gchq.gaffer.operation.impl.get.GetEntities) Test(org.junit.Test)

Example 5 with NamedOperation

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

the class AddNamedOperationHandlerTest method shouldNotAllowNamedOperationToBeAddedContainingANamedOperationThatDoesNotExist.

@Test
public void shouldNotAllowNamedOperationToBeAddedContainingANamedOperationThatDoesNotExist() throws OperationException {
    NamedOperation op = new NamedOperation("parent", "this is the parent which has not yet been created");
    OperationChain opChain = new OperationChain.Builder().first(op).build();
    addNamedOperation.setOperationChain(opChain);
    addNamedOperation.setOperationName(OPERATION_NAME);
    exception.expect(OperationException.class);
    handler.doOperation(addNamedOperation, context, store);
}
Also used : OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) 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

NamedOperation (uk.gov.gchq.gaffer.named.operation.NamedOperation)25 Operation (uk.gov.gchq.gaffer.operation.Operation)14 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)12 ExtendedNamedOperation (uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation)10 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)10 Test (org.junit.jupiter.api.Test)9 Element (uk.gov.gchq.gaffer.data.element.Element)9 LinkedHashMap (java.util.LinkedHashMap)8 Test (org.junit.Test)8 AddNamedOperation (uk.gov.gchq.gaffer.named.operation.AddNamedOperation)8 HashMap (java.util.HashMap)7 NamedOperationScoreResolver (uk.gov.gchq.gaffer.store.operation.resolver.named.NamedOperationScoreResolver)7 HashSet (java.util.HashSet)5 Limit (uk.gov.gchq.gaffer.operation.impl.Limit)5 ScoreOperationChain (uk.gov.gchq.gaffer.operation.impl.ScoreOperationChain)5 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)5 GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)5 DefaultScoreResolver (uk.gov.gchq.gaffer.store.operation.resolver.DefaultScoreResolver)5 ScoreResolver (uk.gov.gchq.gaffer.store.operation.resolver.ScoreResolver)5 User (uk.gov.gchq.gaffer.user.User)5