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