Search in sources :

Example 31 with NamedOperationDetail

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

the class NamedOperationCacheTest method shouldReturnSetOfNamedOperationsThatAUserCanExecute.

@Test
public void shouldReturnSetOfNamedOperationsThatAUserCanExecute() throws CacheOperationFailedException {
    cache.addNamedOperation(standard, false, standardUser);
    NamedOperationDetail alt = new NamedOperationDetail.Builder().operationName("different operation").description("alt").creatorId(advancedUser.getUserId()).readers(readers).writers(writers).operationChain(alternativeOpChain).build();
    cache.addNamedOperation(alt, false, advancedUser);
    Set<NamedOperationDetail> actual = Sets.newHashSet(cache.getAllNamedOperations(standardUser));
    assert actual.contains(standard);
    assert actual.contains(alt);
    assert actual.size() == 2;
}
Also used : NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) Test(org.junit.jupiter.api.Test)

Example 32 with NamedOperationDetail

use of uk.gov.gchq.gaffer.named.operation.NamedOperationDetail 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();
}
Also used : NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) CacheOperationFailedException(uk.gov.gchq.gaffer.named.operation.cache.exception.CacheOperationFailedException)

Example 33 with NamedOperationDetail

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

the class NamedOperationScoreResolverTest method shouldGetScore.

@Test
public void shouldGetScore() throws CacheOperationFailedException {
    // Given
    final Integer expectedScore = 5;
    final String opName = "otherOp";
    final NamedOperation<Element, Iterable<? extends Element>> namedOp = mock(NamedOperation.class);
    namedOp.setOperationName(opName);
    final NamedOperationDetail namedOpDetail = mock(NamedOperationDetail.class);
    final NamedOperationCache cache = mock(NamedOperationCache.class);
    final NamedOperationScoreResolver resolver = new NamedOperationScoreResolver(cache);
    given(cache.getFromCache(namedOpDetail.getOperationName())).willReturn(namedOpDetail);
    given(namedOpDetail.getOperationName()).willReturn(opName);
    given(namedOpDetail.getScore()).willReturn(expectedScore);
    // When
    final Integer result = resolver.getScore(namedOp);
    // Then
    assertEquals(expectedScore, result);
}
Also used : NamedOperationCache(uk.gov.gchq.gaffer.store.operation.handler.named.cache.NamedOperationCache) Element(uk.gov.gchq.gaffer.data.element.Element) NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) Test(org.junit.jupiter.api.Test)

Example 34 with NamedOperationDetail

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

the class NamedOperationCacheIT method shouldBeAbleToDeleteNamedOperationFromCache.

private void shouldBeAbleToDeleteNamedOperationFromCache() throws OperationException {
    // given
    final Store store = mock(Store.class);
    given(store.getProperties()).willReturn(properties);
    new AddNamedOperationHandler().doOperation(add, context, store);
    DeleteNamedOperation del = new DeleteNamedOperation.Builder().name("op").build();
    GetAllNamedOperations get = new GetAllNamedOperations();
    // when
    deleteNamedOperationHandler.doOperation(del, context, store);
    List<NamedOperationDetail> results = Lists.newArrayList(getAllNamedOperationsHandler1.doOperation(get, context, store));
    // then
    assertThat(results).isEmpty();
}
Also used : GetAllNamedOperations(uk.gov.gchq.gaffer.named.operation.GetAllNamedOperations) Store(uk.gov.gchq.gaffer.store.Store) NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) AddNamedOperationHandler(uk.gov.gchq.gaffer.store.operation.handler.named.AddNamedOperationHandler) DeleteNamedOperation(uk.gov.gchq.gaffer.named.operation.DeleteNamedOperation)

Example 35 with NamedOperationDetail

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

the class NamedOperationResolverTest method shouldNotExecuteNamedOperationWithParameterOfWrongType.

@Test
public void shouldNotExecuteNamedOperationWithParameterOfWrongType() throws OperationException, CacheOperationFailedException {
    // Given
    final String opName = "opName";
    final NamedOperationCache cache = mock(NamedOperationCache.class);
    final NamedOperationResolver resolver = new NamedOperationResolver(cache);
    final User user = mock(User.class);
    Map<String, Object> paramMap = Maps.newHashMap();
    // A parameter of the wrong type
    paramMap.put("param1", new ArrayList());
    ParameterDetail param = new ParameterDetail.Builder().defaultValue(1L).description("Limit param").valueClass(Long.class).build();
    Map<String, ParameterDetail> paramDetailMap = Maps.newHashMap();
    paramDetailMap.put("param1", param);
    // Make a real NamedOperationDetail with a parameter
    final NamedOperationDetail extendedNamedOperation = new NamedOperationDetail.Builder().operationName(opName).description("standard operation").operationChain("{ \"operations\": [ { \"class\":\"uk.gov.gchq.gaffer.operation.impl.get.GetAllElements\" }, { \"class\":\"uk.gov.gchq.gaffer.operation.impl.Limit\", \"resultLimit\": \"${param1}\" } ] }").parameters(paramDetailMap).build();
    given(cache.getNamedOperation(opName, user)).willReturn(extendedNamedOperation);
    // When
    assertThatIllegalArgumentException().isThrownBy(() -> resolver.preExecute(new OperationChain.Builder().first(new NamedOperation.Builder<>().name(opName).parameters(paramMap).build()).build(), new Context(user)));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) NamedOperationCache(uk.gov.gchq.gaffer.store.operation.handler.named.cache.NamedOperationCache) ArrayList(java.util.ArrayList) ParameterDetail(uk.gov.gchq.gaffer.named.operation.ParameterDetail) NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Test(org.junit.jupiter.api.Test)

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