use of uk.gov.gchq.gaffer.named.operation.AddNamedOperation in project gaffer-doc by gchq.
the class ScoreOperationChainExample method runExamples.
@Override
protected void runExamples() {
final AddNamedOperation addNamedOp = new AddNamedOperation.Builder().operationChain(new OperationChain.Builder().first(new GetElements()).build()).name("1-hop").description("a 1-hop operation").overwrite().score(3).build();
try {
getGraph().execute(addNamedOp, createContext());
} catch (final OperationException e) {
throw new RuntimeException(e);
}
scoreOperationChain();
scoreOperationChainWithCustomNamedScore();
try {
getGraph().execute(new DeleteNamedOperation.Builder().name("1-hop").build(), createContext());
} catch (final OperationException e) {
throw new RuntimeException(e);
}
}
use of uk.gov.gchq.gaffer.named.operation.AddNamedOperation in project Gaffer by gchq.
the class NamedOperationCacheIT method shouldAllowUpdatingOfNamedOperationsWithAllowedUsers.
private void shouldAllowUpdatingOfNamedOperationsWithAllowedUsers() throws OperationException {
// given
final Store store = mock(Store.class);
given(store.getProperties()).willReturn(properties);
new AddNamedOperationHandler().doOperation(add, context, store);
AddNamedOperation update = new AddNamedOperation.Builder().name(add.getOperationName()).description("a different operation").operationChain(add.getOperationChainAsString()).overwrite().score(0).build();
GetAllNamedOperations get = new GetAllNamedOperations();
// when
new AddNamedOperationHandler().doOperation(add, context, store);
List<NamedOperationDetail> results = Lists.newArrayList(getAllNamedOperationsHandler.doOperation(get, context, store));
NamedOperationDetail expectedNamedOp = new NamedOperationDetail.Builder().operationName(update.getOperationName()).operationChain(update.getOperationChainAsString()).description(update.getDescription()).creatorId(user.getUserId()).score(0).parameters(null).build();
ArrayList<NamedOperationDetail> expected = Lists.newArrayList(expectedNamedOp);
// then
assertThat(results).hasSameSizeAs(expected).isEqualTo(expected);
}
use of uk.gov.gchq.gaffer.named.operation.AddNamedOperation in project Gaffer by gchq.
the class NamedOperationCacheIT method shouldAllowUpdatingOfNamedOperations.
private void shouldAllowUpdatingOfNamedOperations() throws OperationException {
// given
final Store store = mock(Store.class);
final StoreProperties storeProps = mock(StoreProperties.class);
given(store.getProperties()).willReturn(storeProps);
new AddNamedOperationHandler().doOperation(add, context, store);
AddNamedOperation update = new AddNamedOperation.Builder().name(add.getOperationName()).description("a different operation").operationChain(add.getOperationChainAsString()).overwrite().score(0).build();
GetAllNamedOperations get = new GetAllNamedOperations();
// when
new AddNamedOperationHandler().doOperation(add, context, store);
List<NamedOperationDetail> results = Lists.newArrayList(getAllNamedOperationsHandler.doOperation(get, context, store));
NamedOperationDetail expectedNamedOp = new NamedOperationDetail.Builder().operationName(update.getOperationName()).operationChain(update.getOperationChainAsString()).description(update.getDescription()).creatorId(user.getUserId()).score(0).parameters(null).build();
ArrayList<NamedOperationDetail> expected = Lists.newArrayList(expectedNamedOp);
// then
assertThat(results).hasSameSizeAs(expected).isEqualTo(expected);
}
use of uk.gov.gchq.gaffer.named.operation.AddNamedOperation in project Gaffer by gchq.
the class NamedOperationCacheIT method shouldAllowUpdatingOfNamedOperationsUsingAdminAuth.
private void shouldAllowUpdatingOfNamedOperationsUsingAdminAuth() throws OperationException {
// given
Context contextWithAuthorisedUser = new Context(authorisedUser);
Context contextWithAdminUser = new Context(adminAuthUser);
addNamedOperationHandler.doOperation(add, contextWithAuthorisedUser, store);
AddNamedOperation update = new AddNamedOperation.Builder().name(add.getOperationName()).description("a different operation").operationChain(add.getOperationChainAsString()).overwrite().score(0).build();
NamedOperationDetail expectedNamedOp = new NamedOperationDetail.Builder().operationName(update.getOperationName()).operationChain(update.getOperationChainAsString()).description(update.getDescription()).creatorId(adminAuthUser.getUserId()).score(0).parameters(null).build();
ArrayList<NamedOperationDetail> expected = Lists.newArrayList(expectedNamedOp);
// when / then
assertThatExceptionOfType(OperationException.class).isThrownBy(() -> addNamedOperationHandler.doOperation(update, context, store)).withMessageContaining("User UNKNOWN does not have permission to overwrite");
// when
addNamedOperationHandler.doOperation(update, contextWithAdminUser, store);
List<NamedOperationDetail> results = Lists.newArrayList(getAllNamedOperationsHandler.doOperation(get, contextWithAdminUser, store));
// then
assertThat(results).hasSameSizeAs(expected).isEqualTo(expected);
}
use of uk.gov.gchq.gaffer.named.operation.AddNamedOperation in project Gaffer by gchq.
the class OperationAuthoriserTest method shouldAcceptOperationChainWhenUserHasAllOpAuthsForAddNamedOperation.
@Test
public void shouldAcceptOperationChainWhenUserHasAllOpAuthsForAddNamedOperation() {
// Given
final OperationAuthoriser hook = fromJson(OP_AUTHS_PATH);
final AddNamedOperation addNamedOperation = new AddNamedOperation.Builder().operationChain("{\"operations\":[{\"class\": \"uk.gov.gchq.gaffer.operation.impl.get.GetElements\", \"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("SuperUser", "ReadUser", "User").build();
// When
hook.preExecute(opChain, new Context(user));
// Then - no exceptions
}
Aggregations