use of uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail in project Gaffer by gchq.
the class NamedViewCacheTest method shouldAllowUserToDeleteViewWithNoPermissionsSet.
@Test
public void shouldAllowUserToDeleteViewWithNoPermissionsSet() throws CacheOperationFailedException {
// Given
NamedViewDetail namedViewDetailWithUsersAllowedToWrite = new NamedViewDetail.Builder().name(ALTERNATIVE_VIEW_NAME).description("alternative View").view(alternativeView).build();
cache.addNamedView(namedViewDetailWithUsersAllowedToWrite, false);
// When / Then - no exceptions
cache.deleteNamedView(ALTERNATIVE_VIEW_NAME, standardUser, EMPTY_ADMIN_AUTH);
}
use of uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail in project Gaffer by gchq.
the class NamedViewCacheTest method shouldAllowUserToAddWithAdminAuth.
@Test
public void shouldAllowUserToAddWithAdminAuth() throws CacheOperationFailedException {
// Given
cache.addNamedView(alternative, false, advancedUser, EMPTY_ADMIN_AUTH);
NamedViewDetail alternativeWithADifferentView = new NamedViewDetail.Builder().name(ALTERNATIVE_VIEW_NAME).description("alternative View").creatorId(standardUser.getUserId()).view(new View()).build();
// When / Then - no exceptions
cache.addNamedView(alternativeWithADifferentView, true, userWithAdminAuth, ADMIN_AUTH);
}
use of uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail in project Gaffer by gchq.
the class NamedViewCache method getAllNamedViews.
/**
* Gets all the {@link uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail}s from the cache for a user.
*
* @param user {@link uk.gov.gchq.gaffer.user.User} user requesting views
* @param adminAuth admin auths
* @return a {@link CloseableIterable} containing all of the {@link uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail}s in the cache
* @throws CacheOperationFailedException if the get operation fails
*/
public CloseableIterable<NamedViewDetail> getAllNamedViews(final User user, final String adminAuth) throws CacheOperationFailedException {
final Set<String> keys = CacheServiceLoader.getService().getAllKeysFromCache(CACHE_NAME);
final Set<NamedViewDetail> views = new HashSet<>();
for (final String key : keys) {
try {
final NamedViewDetail namedViewDetail = getFromCache(key);
if (namedViewDetail.hasReadAccess(user, adminAuth)) {
views.add(namedViewDetail);
}
} catch (final CacheOperationFailedException e) {
throw e;
}
}
return new WrappedCloseableIterable<>(views);
}
use of uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail in project Gaffer by gchq.
the class NamedViewCache method remove.
private void remove(final String name, final User user, final String adminAuth) throws CacheOperationFailedException {
if (null == name) {
throw new IllegalArgumentException("NamedView name cannot be null");
}
NamedViewDetail existing;
try {
existing = getFromCache(name);
} catch (final CacheOperationFailedException e) {
return;
}
if (user != null) {
if (existing.hasWriteAccess(user, adminAuth)) {
deleteFromCache(name);
} else {
throw new CacheOperationFailedException("User " + user + " does not have permission to delete named view: " + name);
}
}
deleteFromCache(name);
}
use of uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail in project Gaffer by gchq.
the class AddNamedViewHandler method doOperation.
/**
* Adds a {@link uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail} to the NamedViewCache. If no cache is specified it will created a new {@link NamedViewCache}.
* The {@link AddNamedView} name field must be set and cannot be left empty, or the build() method will fail and a runtime exception will be
* thrown. The handler then adds/overwrites the {@link uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail} according to an overwrite flag.
*
* @param operation the {@link uk.gov.gchq.gaffer.operation.Operation} containing the {@link uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView} to be added to cache
* @param context the {@link Context}
* @param store the {@link Store} the operation should be run on
* @return null (since the output is void)
* @throws OperationException if the addition to the cache fails
*/
@Override
public Object doOperation(final AddNamedView operation, final Context context, final Store store) throws OperationException {
if (null == operation.getName() || operation.getName().isEmpty()) {
throw new IllegalArgumentException("NamedView name must be set and not empty");
}
final NamedViewDetail namedViewDetail = new NamedViewDetail.Builder().name(operation.getName()).view(operation.getViewAsString()).description(operation.getDescription()).creatorId(context.getUser().getUserId()).writers(operation.getWriteAccessRoles()).parameters(operation.getParameters()).readAccessPredicate(operation.getReadAccessPredicate()).writeAccessPredicate(operation.getWriteAccessPredicate()).build();
validate(namedViewDetail.getViewWithDefaultParams(), namedViewDetail);
try {
cache.addNamedView(namedViewDetail, operation.isOverwriteFlag(), context.getUser(), store.getProperties().getAdminAuth());
} catch (final CacheOperationFailedException e) {
throw new OperationException(e.getMessage(), e);
}
return null;
}
Aggregations