Search in sources :

Example 1 with NamedViewDetail

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);
}
Also used : NamedViewDetail(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail) Test(org.junit.jupiter.api.Test)

Example 2 with NamedViewDetail

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);
}
Also used : NamedViewDetail(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.jupiter.api.Test)

Example 3 with NamedViewDetail

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);
}
Also used : WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) CacheOperationFailedException(uk.gov.gchq.gaffer.named.operation.cache.exception.CacheOperationFailedException) NamedViewDetail(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail) HashSet(java.util.HashSet)

Example 4 with NamedViewDetail

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);
}
Also used : CacheOperationFailedException(uk.gov.gchq.gaffer.named.operation.cache.exception.CacheOperationFailedException) NamedViewDetail(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail)

Example 5 with NamedViewDetail

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;
}
Also used : CacheOperationFailedException(uk.gov.gchq.gaffer.named.operation.cache.exception.CacheOperationFailedException) NamedViewDetail(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Aggregations

NamedViewDetail (uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail)22 Test (org.junit.jupiter.api.Test)16 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)10 NamedView (uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView)9 OperationView (uk.gov.gchq.gaffer.operation.graph.OperationView)7 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)7 CacheOperationFailedException (uk.gov.gchq.gaffer.named.operation.cache.exception.CacheOperationFailedException)5 ViewParameterDetail (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewParameterDetail)4 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)3 AccessPredicate (uk.gov.gchq.gaffer.access.predicate.AccessPredicate)2 UnrestrictedAccessPredicate (uk.gov.gchq.gaffer.access.predicate.UnrestrictedAccessPredicate)2 NamedViewWriteAccessPredicate (uk.gov.gchq.gaffer.data.elementdefinition.view.access.predicate.NamedViewWriteAccessPredicate)2 ExampleFilterFunction (uk.gov.gchq.gaffer.function.ExampleFilterFunction)2 GetAllNamedViews (uk.gov.gchq.gaffer.named.view.GetAllNamedViews)2 HashSet (java.util.HashSet)1 CustomUserPredicate (uk.gov.gchq.gaffer.access.predicate.user.CustomUserPredicate)1 WrappedCloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable)1 RoadAndRoadUseWithTimesAndCardinalitiesElementGenerator (uk.gov.gchq.gaffer.doc.user.generator.RoadAndRoadUseWithTimesAndCardinalitiesElementGenerator)1 Graph (uk.gov.gchq.gaffer.graph.Graph)1 AddNamedView (uk.gov.gchq.gaffer.named.view.AddNamedView)1