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;
}
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);
}
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);
}
Aggregations