Search in sources :

Example 11 with CacheOperationFailedException

use of uk.gov.gchq.gaffer.named.operation.cache.exception.CacheOperationFailedException in project Gaffer by gchq.

the class NamedOperationScoreResolver method getScore.

@Override
public Integer getScore(final NamedOperation operation, final ScoreResolver defaultScoreResolver) {
    Integer namedOpScore = null;
    NamedOperationDetail namedOpDetail = null;
    if (null == operation) {
        return 0;
    }
    try {
        namedOpDetail = cache.getFromCache(operation.getOperationName());
    } catch (final CacheOperationFailedException e) {
        LOGGER.warn("Error accessing cache for Operation '{}': " + e.getMessage(), operation.getClass().getName());
    }
    if (null != namedOpDetail) {
        namedOpScore = namedOpDetail.getScore();
        if (null == namedOpScore && null != defaultScoreResolver) {
            namedOpScore = defaultScoreResolver.getScore(namedOpDetail.getOperationChain(operation.getParameters()));
        }
    }
    if (null != defaultScoreResolver) {
        if (null == namedOpScore) {
            namedOpScore = 0;
        }
        List parameterOperations = operation.getOperations();
        if (null != parameterOperations) {
            for (final Object objectOperation : parameterOperations) {
                Operation op = (Operation) objectOperation;
                Integer parameterOpScore = defaultScoreResolver.getScore(op);
                namedOpScore += parameterOpScore;
            }
        }
    }
    return namedOpScore;
}
Also used : NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) List(java.util.List) Operation(uk.gov.gchq.gaffer.operation.Operation) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) CacheOperationFailedException(uk.gov.gchq.gaffer.named.operation.cache.exception.CacheOperationFailedException)

Example 12 with CacheOperationFailedException

use of uk.gov.gchq.gaffer.named.operation.cache.exception.CacheOperationFailedException in project Gaffer by gchq.

the class NamedOperationCache method getAll.

private CloseableIterable<NamedOperationDetail> getAll(final User user, final String adminAuth) {
    final Set<String> keys = CacheServiceLoader.getService().getAllKeysFromCache(CACHE_NAME);
    final Set<NamedOperationDetail> executables = new HashSet<>();
    for (final String key : keys) {
        try {
            NamedOperationDetail op = getFromCache(key);
            if (op.hasReadAccess(user, adminAuth)) {
                executables.add(op);
            }
        } catch (final CacheOperationFailedException e) {
            LOGGER.error(e.getMessage(), e);
        }
    }
    return new WrappedCloseableIterable<>(executables);
}
Also used : WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) CacheOperationFailedException(uk.gov.gchq.gaffer.named.operation.cache.exception.CacheOperationFailedException) HashSet(java.util.HashSet)

Example 13 with CacheOperationFailedException

use of uk.gov.gchq.gaffer.named.operation.cache.exception.CacheOperationFailedException in project Gaffer by gchq.

the class NamedViewCache method add.

private void add(final NamedViewDetail namedViewDetail, final boolean overwrite, final User user, final String adminAuth) throws CacheOperationFailedException {
    if (null != namedViewDetail.getName()) {
        namedViewDetail.getName();
    } else {
        throw new CacheOperationFailedException("NamedView name cannot be null");
    }
    if (!overwrite) {
        addToCache(namedViewDetail, false);
        return;
    }
    NamedViewDetail existing;
    try {
        existing = getFromCache(namedViewDetail.getName());
    } catch (final CacheOperationFailedException e) {
        // if there is no existing NamedView add one
        addToCache(namedViewDetail, false);
        return;
    }
    if (user != null) {
        if (existing.hasWriteAccess(user, adminAuth)) {
            addToCache(namedViewDetail, true);
        } else {
            throw new CacheOperationFailedException("User " + user.getUserId() + " does not have permission to overwrite");
        }
    }
    addToCache(namedViewDetail, true);
}
Also used : CacheOperationFailedException(uk.gov.gchq.gaffer.named.operation.cache.exception.CacheOperationFailedException) NamedViewDetail(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail)

Aggregations

CacheOperationFailedException (uk.gov.gchq.gaffer.named.operation.cache.exception.CacheOperationFailedException)13 NamedOperationDetail (uk.gov.gchq.gaffer.named.operation.NamedOperationDetail)7 NamedViewDetail (uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail)5 HashSet (java.util.HashSet)2 Test (org.junit.jupiter.api.Test)2 WrappedCloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable)2 NamedView (uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView)2 OperationException (uk.gov.gchq.gaffer.operation.OperationException)2 List (java.util.List)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 NoAccessPredicate (uk.gov.gchq.gaffer.access.predicate.NoAccessPredicate)1 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)1 NamedOperation (uk.gov.gchq.gaffer.named.operation.NamedOperation)1 Operation (uk.gov.gchq.gaffer.operation.Operation)1 OperationView (uk.gov.gchq.gaffer.operation.graph.OperationView)1 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)1 User (uk.gov.gchq.gaffer.user.User)1