Search in sources :

Example 1 with AddNamedOperation

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");
    }
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) ExtendedNamedOperation(uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) CacheOperationFailedException(uk.gov.gchq.gaffer.named.operation.cache.CacheOperationFailedException) OperationException(uk.gov.gchq.gaffer.operation.OperationException) ExpectedException(org.junit.rules.ExpectedException) GetEntities(uk.gov.gchq.gaffer.operation.impl.get.GetEntities) Test(org.junit.Test)

Example 2 with AddNamedOperation

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);
}
Also used : OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) ExtendedNamedOperation(uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Test(org.junit.Test)

Example 3 with AddNamedOperation

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);
}
Also used : AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation)

Example 4 with AddNamedOperation

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);
}
Also used : ParameterDetail(uk.gov.gchq.gaffer.named.operation.ParameterDetail) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation)

Example 5 with AddNamedOperation

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.");
}
Also used : ParameterDetail(uk.gov.gchq.gaffer.named.operation.ParameterDetail) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation)

Aggregations

AddNamedOperation (uk.gov.gchq.gaffer.named.operation.AddNamedOperation)25 Test (org.junit.jupiter.api.Test)10 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)10 NamedOperationDetail (uk.gov.gchq.gaffer.named.operation.NamedOperationDetail)9 GetAllNamedOperations (uk.gov.gchq.gaffer.named.operation.GetAllNamedOperations)8 NamedOperation (uk.gov.gchq.gaffer.named.operation.NamedOperation)7 Test (org.junit.Test)5 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)5 Context (uk.gov.gchq.gaffer.store.Context)5 User (uk.gov.gchq.gaffer.user.User)5 ExtendedNamedOperation (uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation)4 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)4 UnauthorisedException (uk.gov.gchq.gaffer.commonutil.exception.UnauthorisedException)3 ParameterDetail (uk.gov.gchq.gaffer.named.operation.ParameterDetail)3 OperationException (uk.gov.gchq.gaffer.operation.OperationException)3 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)2 Element (uk.gov.gchq.gaffer.data.element.Element)2 EntityId (uk.gov.gchq.gaffer.data.element.id.EntityId)2 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)2 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)2