use of uk.gov.gchq.gaffer.named.operation.cache.exception.CacheOperationFailedException in project Gaffer by gchq.
the class NamedOperationCache method add.
private void add(final NamedOperationDetail namedOperation, final boolean overwrite, final User user, final String adminAuth) throws CacheOperationFailedException {
String name;
try {
name = namedOperation.getOperationName();
} catch (final NullPointerException e) {
throw new CacheOperationFailedException("NamedOperation cannot be null", e);
}
if (null == name) {
throw new CacheOperationFailedException("NamedOperation name cannot be null");
}
if (!overwrite) {
addToCache(name, namedOperation, false);
return;
}
NamedOperationDetail existing;
try {
existing = getFromCache(name);
} catch (final CacheOperationFailedException e) {
// if there is no existing named Operation add one
addToCache(name, namedOperation, false);
return;
}
if (existing.hasWriteAccess(user, adminAuth)) {
addToCache(name, namedOperation, true);
} else {
throw new CacheOperationFailedException("User " + user.getUserId() + " does not have permission to overwrite");
}
}
use of uk.gov.gchq.gaffer.named.operation.cache.exception.CacheOperationFailedException in project Gaffer by gchq.
the class NamedViewResolverTest method shouldThrowExceptionWhenNamedViewToBeMergedIsNotInCache.
@Test
public void shouldThrowExceptionWhenNamedViewToBeMergedIsNotInCache() throws CacheOperationFailedException {
// Given
given(CACHE.getNamedView(NAMED_VIEW_NAME, CONTEXT.getUser())).willReturn(FULL_NAMED_VIEW_DETAIL);
given(CACHE.getNamedView(NAMED_VIEW_NAME + 1, CONTEXT.getUser())).willThrow(new CacheOperationFailedException("No NamedView with the name namedViewName1 exists in the cache"));
final OperationChain<?> opChain = new OperationChain.Builder().first(new GetElements.Builder().view(new NamedView.Builder().name(NAMED_VIEW_NAME).merge(new NamedView.Builder().name(NAMED_VIEW_NAME + 1).build()).build()).build()).build();
// When / Then
try {
RESOLVER.preExecute(opChain, CONTEXT);
fail("Exception expected");
} catch (final RuntimeException e) {
assert e.getMessage().contains("No NamedView with the name namedViewName1 exists in the cache");
}
}
use of uk.gov.gchq.gaffer.named.operation.cache.exception.CacheOperationFailedException in project Gaffer by gchq.
the class NamedViewResolver method resolveView.
private View resolveView(final String namedViewName, final Map<String, Object> parameters, final Context context) {
final NamedViewDetail cachedNamedView;
try {
cachedNamedView = cache.getNamedView(namedViewName, context.getUser());
} catch (final CacheOperationFailedException e) {
throw new RuntimeException(e);
}
View resolvedView;
if (null == cachedNamedView) {
resolvedView = new View();
} else {
resolvedView = cachedNamedView.getView(parameters);
if (resolvedView instanceof NamedView) {
((NamedView) resolvedView).setName(null);
if (CollectionUtils.isNotEmpty(((NamedView) resolvedView).getMergedNamedViewNames())) {
final View.Builder viewBuilder = new View.Builder();
viewBuilder.merge(resolvedView);
for (final String name : ((NamedView) resolvedView).getMergedNamedViewNames()) {
viewBuilder.merge(resolveView(name, parameters, context));
}
resolvedView = viewBuilder.build();
}
}
}
return resolvedView;
}
use of uk.gov.gchq.gaffer.named.operation.cache.exception.CacheOperationFailedException in project Gaffer by gchq.
the class NamedOperationCacheTest method shouldThrowExceptionTryingToDeleteOperationConfiguredWithWriteNoAccessPredicate.
@Test
public void shouldThrowExceptionTryingToDeleteOperationConfiguredWithWriteNoAccessPredicate() throws CacheOperationFailedException {
final NamedOperationDetail noWriteAccess = new NamedOperationDetail.Builder().creatorId(standardUser.getUserId()).description("an operation that does no allow read access").operationName("test").readers(readers).operationChain(standardOpChain).writeAccessPredicate(new NoAccessPredicate()).build();
cache.addNamedOperation(noWriteAccess, false, standardUser);
assertThatExceptionOfType(CacheOperationFailedException.class).isThrownBy(() -> cache.deleteNamedOperation("test", standardUser));
}
use of uk.gov.gchq.gaffer.named.operation.cache.exception.CacheOperationFailedException in project Gaffer by gchq.
the class NamedOperationResolver method resolveNamedOperation.
private List<Operation> resolveNamedOperation(final NamedOperation namedOp, final User user) {
final NamedOperationDetail namedOpDetail;
try {
namedOpDetail = cache.getNamedOperation(namedOp.getOperationName(), user);
} catch (final CacheOperationFailedException e) {
// Unable to find named operation - just return the original named operation
return Collections.singletonList(namedOp);
}
final OperationChain<?> namedOperationChain = namedOpDetail.getOperationChain(namedOp.getParameters());
updateOperationInput(namedOperationChain, namedOp.getInput());
// Call resolveNamedOperations again to check there are no nested named operations
resolveNamedOperations(namedOperationChain, user);
return namedOperationChain.getOperations();
}
Aggregations