use of uk.gov.gchq.gaffer.named.operation.AddNamedOperation in project Gaffer by gchq.
the class AddNamedOperationHandlerTest method shouldAllowForNonRecursiveNamedOperationsToBeNested.
@Test
public void shouldAllowForNonRecursiveNamedOperationsToBeNested() {
try {
OperationChain child = new OperationChain.Builder().first(new AddElements()).build();
addNamedOperation.setOperationChain(child);
addNamedOperation.setOperationName("child");
handler.doOperation(addNamedOperation, context, store);
OperationChain parent = new OperationChain.Builder().first(new NamedOperation("child", "")).then(new GetElements<>()).build();
addNamedOperation.setOperationChain(parent);
addNamedOperation.setOperationName("parent");
handler.doOperation(addNamedOperation, context, store);
OperationChain grandparent = new OperationChain.Builder().first(new AddElements()).then(new NamedOperation("parent", "")).then(new NamedOperation("child", "")).then(new GetEntities<>()).build();
addNamedOperation.setOperationChain(grandparent);
addNamedOperation.setOperationName("grandparent");
handler.doOperation(addNamedOperation, context, store);
assert (cacheContains("grandparent"));
} catch (final Exception e) {
fail("Expected test to pass without error");
}
}
use of uk.gov.gchq.gaffer.named.operation.AddNamedOperation in project Gaffer by gchq.
the class AddNamedOperationHandlerTest method shouldNotAllowNamedOperationToBeAddedContainingANamedOperationThatDoesNotExist.
@Test
public void shouldNotAllowNamedOperationToBeAddedContainingANamedOperationThatDoesNotExist() throws OperationException {
NamedOperation op = new NamedOperation("parent", "this is the parent which has not yet been created");
OperationChain opChain = new OperationChain.Builder().first(op).build();
addNamedOperation.setOperationChain(opChain);
addNamedOperation.setOperationName(OPERATION_NAME);
exception.expect(OperationException.class);
handler.doOperation(addNamedOperation, context, store);
}
use of uk.gov.gchq.gaffer.named.operation.AddNamedOperation in project Gaffer by gchq.
the class NamedOperationExample method addNamedOperation.
public void addNamedOperation() {
// ---------------------------------------------------------
final AddNamedOperation operation = new AddNamedOperation.Builder().operationChain(new OperationChain.Builder().first(new GetAdjacentEntitySeeds.Builder().inOutType(GetOperation.IncludeIncomingOutgoingType.OUTGOING).build()).then(new GetAdjacentEntitySeeds.Builder().inOutType(GetOperation.IncludeIncomingOutgoingType.OUTGOING).deduplicate(true).build()).build()).description("2 hop query").name("2-hop").readAccessRoles("read-user").writeAccessRoles("write-user").overwrite().build();
// ---------------------------------------------------------
runExampleNoResult(operation);
}
use of uk.gov.gchq.gaffer.named.operation.AddNamedOperation 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.AddNamedOperation 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.");
}
Aggregations