Search in sources :

Example 6 with AddNamedOperation

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

Example 7 with AddNamedOperation

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);
}
Also used : GetAllNamedOperations(uk.gov.gchq.gaffer.named.operation.GetAllNamedOperations) Store(uk.gov.gchq.gaffer.store.Store) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) AddNamedOperationHandler(uk.gov.gchq.gaffer.store.operation.handler.named.AddNamedOperationHandler)

Example 8 with AddNamedOperation

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);
}
Also used : GetAllNamedOperations(uk.gov.gchq.gaffer.named.operation.GetAllNamedOperations) Store(uk.gov.gchq.gaffer.store.Store) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) AddNamedOperationHandler(uk.gov.gchq.gaffer.store.operation.handler.named.AddNamedOperationHandler) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties)

Example 9 with AddNamedOperation

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

Example 10 with AddNamedOperation

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
}
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) 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