Search in sources :

Example 1 with ParameterDetail

use of uk.gov.gchq.gaffer.named.operation.ParameterDetail in project gaffer-doc by gchq.

the class NamedOperationExample method addNamedOperationWithParameter.

public void addNamedOperationWithParameter() {
    // ---------------------------------------------------------
    final String opChainString = "{" + "    \"operations\" : [ {" + "      \"class\" : \"uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds\"," + "      \"includeIncomingOutGoing\" : \"OUTGOING\"" + "    }, {" + "      \"class\" : \"uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds\"," + "      \"includeIncomingOutGoing\" : \"OUTGOING\"" + "    }, {" + "      \"class\" : \"uk.gov.gchq.gaffer.operation.impl.Limit\"," + "      \"resultLimit\" : \"${param1}\"" + "    }" + " ]" + "}";
    ParameterDetail param = new ParameterDetail.Builder().defaultValue(1L).description("Limit param").valueClass(Long.class).build();
    Map<String, ParameterDetail> paramMap = Maps.newHashMap();
    paramMap.put("param1", param);
    final AddNamedOperation operation = new AddNamedOperation.Builder().operationChain(opChainString).description("2 hop query with settable limit").name("2-hop-with-limit").readAccessRoles("read-user").writeAccessRoles("write-user").parameters(paramMap).overwrite().score(3).build();
    // ---------------------------------------------------------
    runExampleNoResult(operation, null);
}
Also used : ParameterDetail(uk.gov.gchq.gaffer.named.operation.ParameterDetail) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation)

Example 2 with ParameterDetail

use of uk.gov.gchq.gaffer.named.operation.ParameterDetail in project gaffer-doc by gchq.

the class IfExample method addNamedOperationContainingIfOperationWithParameter.

public void addNamedOperationContainingIfOperationWithParameter() {
    // ---------------------------------------------------------
    final String opChainString = "{" + "\"operations\" : [ {\n" + "      \"class\" : \"uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds\"\n" + "    }, {\n" + "      \"class\" : \"uk.gov.gchq.gaffer.operation.impl.If\",\n" + "      \"condition\" : \"${enableFiltering}\",\n" + "      \"then\" : {\n" + "        \"class\" : \"uk.gov.gchq.gaffer.operation.impl.get.GetElements\",\n" + "        \"view\" : {\n" + "          \"entities\" : {\n" + "            \"entity\" : {\n" + "              \"preAggregationFilterFunctions\" : [ {\n" + "                \"selection\" : [ \"count\" ],\n" + "                \"predicate\" : {\n" + "                  \"class\" : \"uk.gov.gchq.koryphe.impl.predicate.IsLessThan\",\n" + "                  \"orEqualTo\" : true,\n" + "                  \"value\" : 10\n" + "                }\n" + "              } ]\n" + "            }\n" + "          }\n" + "        }\n" + "      }\n" + "    }, {\n" + "      \"class\" : \"uk.gov.gchq.gaffer.operation.impl.get.GetElements\"\n" + "    } ]" + "}";
    ParameterDetail param = new ParameterDetail.Builder().defaultValue(true).description("Flag for enabling filtering").valueClass(boolean.class).build();
    java.util.Map<String, ParameterDetail> parameterMap = Maps.newHashMap();
    parameterMap.put("enableFiltering", param);
    final AddNamedOperation operation = new AddNamedOperation.Builder().operationChain(opChainString).description("2 hop query with optional filtering by count").name("2-hop-with-optional-filtering").readAccessRoles("read-user").writeAccessRoles("write-user").parameters(parameterMap).overwrite().score(4).build();
    // ---------------------------------------------------------
    runExampleNoResult(operation, "Here we create and add a NamedOperation, " + "containing an If operation with a parameter. " + "This parameter can be configured so that the optional GetElements with the filter can be executed, " + "otherwise it will just continue to the next GetElements.");
}
Also used : ParameterDetail(uk.gov.gchq.gaffer.named.operation.ParameterDetail) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation)

Example 3 with ParameterDetail

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

the class AddNamedOperationHandlerTest method shouldAllowForOperationChainJSONWithParameter.

@Test
public void shouldAllowForOperationChainJSONWithParameter() {
    try {
        final String opChainJSON = "{ \"operations\": [ { \"class\":\"uk.gov.gchq.gaffer.operation.impl.get.GetAllElements\" }, { \"class\":\"uk.gov.gchq.gaffer.operation.impl.Limit\", \"resultLimit\": \"${param1}\" } ] }";
        addNamedOperation.setOperationChain(opChainJSON);
        addNamedOperation.setOperationName("namedop");
        ParameterDetail param = new ParameterDetail.Builder().defaultValue(1L).description("Limit param").valueClass(Long.class).build();
        Map<String, ParameterDetail> paramMap = Maps.newHashMap();
        paramMap.put("param1", param);
        addNamedOperation.setParameters(paramMap);
        handler.doOperation(addNamedOperation, context, store);
        assert cacheContains("namedop");
    } catch (final Exception e) {
        fail("Expected test to pass without error. Exception " + e.getMessage());
    }
}
Also used : ParameterDetail(uk.gov.gchq.gaffer.named.operation.ParameterDetail) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) CacheOperationFailedException(uk.gov.gchq.gaffer.named.operation.cache.exception.CacheOperationFailedException) OperationException(uk.gov.gchq.gaffer.operation.OperationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Test(org.junit.jupiter.api.Test)

Example 4 with ParameterDetail

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

the class AddNamedOperationHandlerTest method shouldNotAllowForOperationChainWithParameterNotInOperationString.

@Test
public void shouldNotAllowForOperationChainWithParameterNotInOperationString() throws OperationException {
    final String opChainJSON = "{ \"operations\": [ { \"class\":\"uk.gov.gchq.gaffer.operation.impl.get.GetAllElements\" }, { \"class\":\"uk.gov.gchq.gaffer.operation.impl.export.set.ExportToSet\", \"key\": \"${param1}\" } ] }";
    addNamedOperation.setOperationChain(opChainJSON);
    addNamedOperation.setOperationName("namedop");
    // Note the param is String class to get past type checking which will also catch a param
    // with an unknown name if its not a string.
    ParameterDetail param = new ParameterDetail.Builder().defaultValue("setKey").description("key param").valueClass(String.class).build();
    Map<String, ParameterDetail> paramMap = Maps.newHashMap();
    paramMap.put("param2", param);
    addNamedOperation.setParameters(paramMap);
    assertThatExceptionOfType(OperationException.class).isThrownBy(() -> handler.doOperation(addNamedOperation, context, store));
}
Also used : ParameterDetail(uk.gov.gchq.gaffer.named.operation.ParameterDetail) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) OperationException(uk.gov.gchq.gaffer.operation.OperationException) Test(org.junit.jupiter.api.Test)

Example 5 with ParameterDetail

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

the class NamedOperationResolverTest method shouldResolveNamedOperationWithParameter.

@Test
public void shouldResolveNamedOperationWithParameter() 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();
    paramMap.put("param1", 1L);
    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);
    final OperationChain<Object> opChain = new OperationChain.Builder().first(new NamedOperation.Builder<>().name(opName).parameters(paramMap).build()).build();
    // When
    resolver.preExecute(opChain, new Context(user));
    // Then
    assertEquals(opChain.getOperations().get(0).getClass(), GetAllElements.class);
    assertEquals(opChain.getOperations().get(1).getClass(), Limit.class);
    // Check the parameter has been inserted
    assertEquals((long) ((Limit) opChain.getOperations().get(1)).getResultLimit(), 1L);
}
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) ParameterDetail(uk.gov.gchq.gaffer.named.operation.ParameterDetail) NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Test(org.junit.jupiter.api.Test)

Aggregations

ParameterDetail (uk.gov.gchq.gaffer.named.operation.ParameterDetail)9 Test (org.junit.jupiter.api.Test)6 NamedOperation (uk.gov.gchq.gaffer.named.operation.NamedOperation)5 NamedOperationDetail (uk.gov.gchq.gaffer.named.operation.NamedOperationDetail)5 User (uk.gov.gchq.gaffer.user.User)5 Context (uk.gov.gchq.gaffer.store.Context)4 NamedOperationCache (uk.gov.gchq.gaffer.store.operation.handler.named.cache.NamedOperationCache)4 AddNamedOperation (uk.gov.gchq.gaffer.named.operation.AddNamedOperation)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 OperationException (uk.gov.gchq.gaffer.operation.OperationException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)1 Element (uk.gov.gchq.gaffer.data.element.Element)1 EntityId (uk.gov.gchq.gaffer.data.element.id.EntityId)1 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)1 RoadAndRoadUseWithTimesAndCardinalitiesElementGenerator (uk.gov.gchq.gaffer.doc.user.generator.RoadAndRoadUseWithTimesAndCardinalitiesElementGenerator)1 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)1 Graph (uk.gov.gchq.gaffer.graph.Graph)1 GetAllNamedOperations (uk.gov.gchq.gaffer.named.operation.GetAllNamedOperations)1