Search in sources :

Example 21 with AddNamedOperation

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

the class NamedOperationExample method addNamedOperation.

public void addNamedOperation() {
    // ---------------------------------------------------------
    final AddNamedOperation operation = new AddNamedOperation.Builder().operationChain(new OperationChain.Builder().first(new GetAdjacentIds.Builder().inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING).build()).then(new GetAdjacentIds.Builder().inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING).build()).build()).description("2 hop query").name("2-hop").readAccessRoles("read-user").writeAccessRoles("write-user").overwrite().build();
    // ---------------------------------------------------------
    runExampleNoResult(operation, null);
}
Also used : GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation)

Example 22 with AddNamedOperation

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

the class GetAllNamedOperationsHandlerTest method shouldReturnNamedOperationWithInputType.

@Test
public void shouldReturnNamedOperationWithInputType() throws Exception {
    // Given
    AddNamedOperation addNamedOperation = new AddNamedOperation.Builder().name(expectedOperationDetailWithInputType.getOperationName()).description(expectedOperationDetailWithInputType.getDescription()).operationChain(expectedOperationDetailWithInputType.getOperationChainWithDefaultParams()).build();
    addNamedOperationHandler.doOperation(addNamedOperation, context, store);
    // When
    CloseableIterable<NamedOperationDetail> allNamedOperationsList = getAllNamedOperationsHandler.doOperation(new GetAllNamedOperations(), context, store);
    // Then
    assertEquals(1, Iterables.size(allNamedOperationsList));
    assertTrue(Iterables.contains(allNamedOperationsList, expectedOperationDetailWithInputType));
}
Also used : GetAllNamedOperations(uk.gov.gchq.gaffer.named.operation.GetAllNamedOperations) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) Test(org.junit.jupiter.api.Test)

Example 23 with AddNamedOperation

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

the class GetAllNamedOperationsHandlerTest method shouldReturnNullLabelWhenLabelIsNullFromAddNamedOperationRequest.

@Test
public void shouldReturnNullLabelWhenLabelIsNullFromAddNamedOperationRequest() throws Exception {
    final AddNamedOperation addNamedOperationWithNullLabel = new AddNamedOperation.Builder().name("My Operation With Label").labels(null).operationChain("{\"operations\":[{\"class\":\"uk.gov.gchq.gaffer.operation.impl.add.AddElements\",\"skipInvalidElements\":false,\"validate\":true}]}").build();
    addNamedOperationHandler.doOperation(addNamedOperationWithNullLabel, context, store);
    final CloseableIterable<NamedOperationDetail> allNamedOperations = getAllNamedOperationsHandler.doOperation(new GetAllNamedOperations(), context, store);
    assertThat(allNamedOperations.iterator().next().getLabels()).isNull();
}
Also used : GetAllNamedOperations(uk.gov.gchq.gaffer.named.operation.GetAllNamedOperations) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) Test(org.junit.jupiter.api.Test)

Example 24 with AddNamedOperation

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

the class GetAllNamedOperationsHandlerTest method shouldReturnLabelWhenNamedOperationHasLabel.

@Test
public void shouldReturnLabelWhenNamedOperationHasLabel() throws Exception {
    final AddNamedOperation addNamedOperationWithLabel = new AddNamedOperation.Builder().name("My Operation With Label").labels(Arrays.asList("test label")).operationChain("{\"operations\":[{\"class\":\"uk.gov.gchq.gaffer.operation.impl.add.AddElements\",\"skipInvalidElements\":false,\"validate\":true}]}").build();
    addNamedOperationHandler.doOperation(addNamedOperationWithLabel, context, store);
    final CloseableIterable<NamedOperationDetail> allNamedOperations = getAllNamedOperationsHandler.doOperation(new GetAllNamedOperations(), context, store);
    assertEquals(Arrays.asList("test label"), allNamedOperations.iterator().next().getLabels());
}
Also used : GetAllNamedOperations(uk.gov.gchq.gaffer.named.operation.GetAllNamedOperations) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) Test(org.junit.jupiter.api.Test)

Example 25 with AddNamedOperation

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

the class OperationAuthoriserTest method shouldRejectOperationChainWhenUserDoesntHaveSuperAuthForAddNamedOperation.

@Test
public void shouldRejectOperationChainWhenUserDoesntHaveSuperAuthForAddNamedOperation() {
    // Given
    final OperationAuthoriser hook = fromJson(OP_AUTHS_PATH);
    final AddNamedOperation addNamedOperation = new AddNamedOperation.Builder().operationChain("{\"operations\":[{\"class\": \"uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds\", \"options\": {\"optionKey\": \"${testParameter}\"}}]}").description("Test Named Operation").name("Test").overwrite(false).parameter("testParameter", new ParameterDetail.Builder().description("the seed").defaultValue("seed1").valueClass(String.class).required(false).build()).score(2).build();
    final OperationChain opChain = new OperationChain.Builder().first(addNamedOperation).build();
    final User user = new User.Builder().opAuths("ReadUser", "User").build();
    // When/Then
    assertThatExceptionOfType(UnauthorisedException.class).isThrownBy(() -> hook.preExecute(opChain, new Context(user))).extracting("message").isNotNull();
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) UnauthorisedException(uk.gov.gchq.gaffer.commonutil.exception.UnauthorisedException) Test(org.junit.jupiter.api.Test)

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