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);
}
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.");
}
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());
}
}
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));
}
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);
}
Aggregations