Search in sources :

Example 11 with NamedOperationDetail

use of uk.gov.gchq.gaffer.named.operation.NamedOperationDetail in project Gaffer by gchq.

the class NamedOperationCacheBackwardCompatibilityTest method shouldReturnExpectedNamedOperationDetailUsingCacheDataFromVersion1_12.

@Test
public void shouldReturnExpectedNamedOperationDetailUsingCacheDataFromVersion1_12() throws Exception {
    final NamedOperationDetail namedOperationDetail = new NamedOperationDetail.Builder().operationName(OPERATION_NAME).description("standard operation").creatorId(ADDING_USER.getUserId()).readers(asList("readerAuth1", "readerAuth2")).writers(asList("writerAuth1", "writerAuth2")).operationChain(new OperationChain.Builder().first(new AddElements()).build()).build();
    final NamedOperationDetail namedOperationDetailFromCacheVersion1_12 = operationCache.getNamedOperation(OPERATION_NAME, ADDING_USER);
    assertEquals(namedOperationDetail.getReadAccessPredicate(), namedOperationDetailFromCacheVersion1_12.getReadAccessPredicate());
    assertEquals(namedOperationDetail.getWriteAccessPredicate(), namedOperationDetailFromCacheVersion1_12.getWriteAccessPredicate());
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) Test(org.junit.jupiter.api.Test)

Example 12 with NamedOperationDetail

use of uk.gov.gchq.gaffer.named.operation.NamedOperationDetail in project Gaffer by gchq.

the class NamedOperationCacheTest method shouldAllowUsersReadAccessToTheirOwnNamedOperations.

@Test
public void shouldAllowUsersReadAccessToTheirOwnNamedOperations() throws CacheOperationFailedException {
    NamedOperationDetail op = new NamedOperationDetail.Builder().operationName(OPERATION_NAME).creatorId(standardUser.getUserId()).operationChain(standardOpChain).readers(new ArrayList<>()).writers(writers).build();
    cache.addNamedOperation(op, false, standardUser);
    assertEquals(op, cache.getNamedOperation(OPERATION_NAME, standardUser));
}
Also used : NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) Test(org.junit.jupiter.api.Test)

Example 13 with NamedOperationDetail

use of uk.gov.gchq.gaffer.named.operation.NamedOperationDetail in project Gaffer by gchq.

the class NamedOperationCacheTest method shouldAllowUsersWriteAccessToTheirOwnOperations.

@Test
public void shouldAllowUsersWriteAccessToTheirOwnOperations() throws CacheOperationFailedException {
    NamedOperationDetail op = new NamedOperationDetail.Builder().operationName(OPERATION_NAME).creatorId(standardUser.getUserId()).operationChain(standardOpChain).readers(readers).writers(new ArrayList<>()).build();
    cache.addNamedOperation(op, false, standardUser);
    cache.addNamedOperation(standard, true, standardUser);
    assertEquals(standard, cache.getNamedOperation(OPERATION_NAME, standardUser));
}
Also used : ArrayList(java.util.ArrayList) NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) Test(org.junit.jupiter.api.Test)

Example 14 with NamedOperationDetail

use of uk.gov.gchq.gaffer.named.operation.NamedOperationDetail in project Gaffer by gchq.

the class OperationServiceIT method shouldReturnNamedOpDetailWithLabelWhenLabelIsAddedToNamedOp.

@Test
public void shouldReturnNamedOpDetailWithLabelWhenLabelIsAddedToNamedOp() throws Exception {
    // Given
    final AddNamedOperation namedOperation = new AddNamedOperation.Builder().name("My Operation With Label").labels(Arrays.asList("test label")).operationChain("{\"operations\":[{\"class\":\"uk.gov.gchq.gaffer.operation.impl.add.AddElements\",\"skipInvalidElements\":false,\"validate\":true}]}").build();
    client.executeOperation(namedOperation);
    // When
    final Response response = client.executeOperation(new GetAllNamedOperations());
    final List<NamedOperationDetail> namedOperationDetails = response.readEntity(new GenericType<List<NamedOperationDetail>>() {
    });
    // Then
    final NamedOperationDetail expected = new NamedOperationDetail.Builder().operationName("My Operation With Label").labels(Arrays.asList("test label")).operationChain("{\"operations\":[{\"class\":\"uk.gov.gchq.gaffer.operation.impl.add.AddElements\",\"skipInvalidElements\":false,\"validate\":true}]}").inputType("uk.gov.gchq.gaffer.data.element.Element[]").creatorId("UNKNOWN").parameters(null).build();
    assertThat(namedOperationDetails.iterator().next()).isEqualTo(expected);
}
Also used : Response(javax.ws.rs.core.Response) GetAllNamedOperations(uk.gov.gchq.gaffer.named.operation.GetAllNamedOperations) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 15 with NamedOperationDetail

use of uk.gov.gchq.gaffer.named.operation.NamedOperationDetail in project Gaffer by gchq.

the class AddNamedOperationHandler method doOperation.

/**
 * Adds a NamedOperation to a cache which must be specified in the operation declarations file. An
 * NamedOperationDetail is built using the fields on the AddNamedOperation. The operation name and operation chain
 * fields 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 NamedOperation according toa an overwrite flag.
 *
 * @param operation the {@link Operation} to be executed
 * @param context   the operation chain context, containing the user who executed the operation
 * @param store     the {@link Store} the operation should be run on
 * @return null (since the output is void)
 * @throws OperationException if the operation on the cache fails
 */
@Override
public Void doOperation(final AddNamedOperation operation, final Context context, final Store store) throws OperationException {
    try {
        final NamedOperationDetail namedOperationDetail = new NamedOperationDetail.Builder().operationChain(operation.getOperationChainAsString()).operationName(operation.getOperationName()).labels(operation.getLabels()).creatorId(context.getUser().getUserId()).readers(operation.getReadAccessRoles()).writers(operation.getWriteAccessRoles()).description(operation.getDescription()).parameters(operation.getParameters()).score(operation.getScore()).readAccessPredicate(operation.getReadAccessPredicate()).writeAccessPredicate(operation.getWriteAccessPredicate()).build();
        validate(namedOperationDetail.getOperationChainWithDefaultParams(), namedOperationDetail);
        cache.addNamedOperation(namedOperationDetail, operation.isOverwriteFlag(), context.getUser(), store.getProperties().getAdminAuth());
    } catch (final CacheOperationFailedException e) {
        throw new OperationException(e.getMessage(), e);
    }
    return null;
}
Also used : NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) CacheOperationFailedException(uk.gov.gchq.gaffer.named.operation.cache.exception.CacheOperationFailedException) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Aggregations

NamedOperationDetail (uk.gov.gchq.gaffer.named.operation.NamedOperationDetail)40 Test (org.junit.jupiter.api.Test)27 User (uk.gov.gchq.gaffer.user.User)11 GetAllNamedOperations (uk.gov.gchq.gaffer.named.operation.GetAllNamedOperations)10 NamedOperation (uk.gov.gchq.gaffer.named.operation.NamedOperation)10 NamedOperationCache (uk.gov.gchq.gaffer.store.operation.handler.named.cache.NamedOperationCache)10 AddNamedOperation (uk.gov.gchq.gaffer.named.operation.AddNamedOperation)9 Context (uk.gov.gchq.gaffer.store.Context)9 CacheOperationFailedException (uk.gov.gchq.gaffer.named.operation.cache.exception.CacheOperationFailedException)7 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)7 ParameterDetail (uk.gov.gchq.gaffer.named.operation.ParameterDetail)5 ArrayList (java.util.ArrayList)4 Element (uk.gov.gchq.gaffer.data.element.Element)4 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)4 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)4 Store (uk.gov.gchq.gaffer.store.Store)4 GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)3 AddNamedOperationHandler (uk.gov.gchq.gaffer.store.operation.handler.named.AddNamedOperationHandler)3 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2