Search in sources :

Example 41 with AddElements

use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.

the class NamedOperationCacheBackwardCompatibilityTest method shouldReturnExpectedNamedOperationDetailUsingCacheDataFromVersion1_12.

@Test
public void shouldReturnExpectedNamedOperationDetailUsingCacheDataFromVersion1_12() throws Exception {
    final NamedOperationDetail namedOperationDetail = new NamedOperationDetail.Builder().operationName(OPERATION_NAME).description("standard operation").creatorId(ADDING_USER.getUserId()).readers(asList("readerAuth1", "readerAuth2")).writers(asList("writerAuth1", "writerAuth2")).operationChain(new OperationChain.Builder().first(new AddElements()).build()).build();
    final NamedOperationDetail namedOperationDetailFromCacheVersion1_12 = operationCache.getNamedOperation(OPERATION_NAME, ADDING_USER);
    assertEquals(namedOperationDetail.getReadAccessPredicate(), namedOperationDetailFromCacheVersion1_12.getReadAccessPredicate());
    assertEquals(namedOperationDetail.getWriteAccessPredicate(), namedOperationDetailFromCacheVersion1_12.getWriteAccessPredicate());
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) Test(org.junit.jupiter.api.Test)

Example 42 with AddElements

use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.

the class ExamplesService method addElements.

@Override
public AddElements addElements() {
    final AddElements op = new AddElements();
    List<Element> elements = new ArrayList<>();
    if (hasEntities()) {
        elements.add(getEntity(1));
        elements.add(getEntity(2));
    }
    if (hasEdges()) {
        elements.add(getEdge(1, 2));
    }
    op.setInput(elements);
    populateOperation(op);
    return op;
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList)

Example 43 with AddElements

use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.

the class AddElementsHandlerTest method shouldThrowNoExceptionsWhenValidateFlagSetToFalse.

@Test
public void shouldThrowNoExceptionsWhenValidateFlagSetToFalse() throws OperationException, StoreException {
    final AddElements addElements = new AddElements.Builder().input(new Edge("Unknown group", "source", "dest", true)).validate(false).build();
    final AddElementsHandler handler = new AddElementsHandler();
    final Context context = mock(Context.class);
    final HBaseStore store = mock(HBaseStore.class);
    final Table table = mock(Table.class);
    given(store.getTable()).willReturn(table);
    final HBaseProperties properties = HBaseProperties.loadStoreProperties(StreamUtil.storeProps(getClass()));
    given(store.getProperties()).willReturn(properties);
    given(store.getSchema()).willReturn(SCHEMA);
    // When / Then - no exceptions
    handler.doOperation(addElements, context, store);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Context(uk.gov.gchq.gaffer.store.Context) HTable(org.apache.hadoop.hbase.client.HTable) Table(org.apache.hadoop.hbase.client.Table) HBaseStore(uk.gov.gchq.gaffer.hbasestore.HBaseStore) HBaseProperties(uk.gov.gchq.gaffer.hbasestore.HBaseProperties) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.jupiter.api.Test)

Example 44 with AddElements

use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.

the class AddElementsHandlerTest method shouldDoNothingIfNoElementsProvided.

@Test
public void shouldDoNothingIfNoElementsProvided() throws OperationException, StoreException, IOException {
    // Given
    final AddElementsHandler handler = new AddElementsHandler();
    final AddElements addElements = new AddElements();
    final Context context = mock(Context.class);
    final HBaseStore store = mock(HBaseStore.class);
    final Table table = mock(Table.class);
    given(store.getTable()).willReturn(table);
    final HBaseProperties properties = HBaseProperties.loadStoreProperties(StreamUtil.storeProps(getClass()));
    given(store.getProperties()).willReturn(properties);
    given(store.getSchema()).willReturn(SCHEMA);
    // When
    handler.doOperation(addElements, context, store);
    // Then
    verify(table, never()).put(any(Put.class));
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Context(uk.gov.gchq.gaffer.store.Context) HTable(org.apache.hadoop.hbase.client.HTable) Table(org.apache.hadoop.hbase.client.Table) HBaseStore(uk.gov.gchq.gaffer.hbasestore.HBaseStore) HBaseProperties(uk.gov.gchq.gaffer.hbasestore.HBaseProperties) Put(org.apache.hadoop.hbase.client.Put) Test(org.junit.jupiter.api.Test)

Example 45 with AddElements

use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.

the class GetAllElementsHandlerTest method testGetAllElementsWithViewRestrictedByGroupAndAPreAggregationFilter.

@Test
public void testGetAllElementsWithViewRestrictedByGroupAndAPreAggregationFilter() throws OperationException {
    // Given
    final Graph graph = getGraph();
    final AddElements addElements = new AddElements.Builder().input(getElements()).build();
    graph.execute(addElements, new User());
    // When
    final GetAllElements getAllElements = new GetAllElements.Builder().view(new View.Builder().edge(BASIC_EDGE1, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(COUNT).execute(new IsMoreThan(5)).build()).build()).build()).build();
    final CloseableIterable<? extends Element> results = graph.execute(getAllElements, new User());
    // Then
    final Set<Element> resultsSet = new HashSet<>();
    Streams.toStream(results).forEach(resultsSet::add);
    final Set<Element> expectedResults = new HashSet<>();
    getElements().stream().filter(e -> e.getGroup().equals(BASIC_EDGE1) && ((int) e.getProperty(COUNT)) > 5).forEach(expectedResults::add);
    assertEquals(expectedResults, resultsSet);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) IntStream(java.util.stream.IntStream) StoreException(uk.gov.gchq.gaffer.store.StoreException) User(uk.gov.gchq.gaffer.user.User) HashMap(java.util.HashMap) GraphConfig(uk.gov.gchq.gaffer.graph.GraphConfig) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Graph(uk.gov.gchq.gaffer.graph.Graph) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Map(java.util.Map) Edge(uk.gov.gchq.gaffer.data.element.Edge) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) TestGroups(uk.gov.gchq.gaffer.commonutil.TestGroups) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) StreamUtil(uk.gov.gchq.gaffer.commonutil.StreamUtil) DirectedType(uk.gov.gchq.gaffer.data.element.id.DirectedType) MapStoreProperties(uk.gov.gchq.gaffer.mapstore.MapStoreProperties) Set(java.util.Set) Entity(uk.gov.gchq.gaffer.data.element.Entity) Test(org.junit.jupiter.api.Test) List(java.util.List) Stream(java.util.stream.Stream) Schema(uk.gov.gchq.gaffer.store.schema.Schema) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) OperationException(uk.gov.gchq.gaffer.operation.OperationException) Streams(uk.gov.gchq.gaffer.commonutil.stream.Streams) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) Graph(uk.gov.gchq.gaffer.graph.Graph) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)157 Graph (uk.gov.gchq.gaffer.graph.Graph)99 User (uk.gov.gchq.gaffer.user.User)98 Element (uk.gov.gchq.gaffer.data.element.Element)88 Test (org.junit.jupiter.api.Test)74 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)72 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)63 Edge (uk.gov.gchq.gaffer.data.element.Edge)62 Entity (uk.gov.gchq.gaffer.data.element.Entity)51 ArrayList (java.util.ArrayList)49 HashSet (java.util.HashSet)47 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)47 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)47 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)39 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)37 OperationException (uk.gov.gchq.gaffer.operation.OperationException)36 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)35 IsMoreThan (uk.gov.gchq.koryphe.impl.predicate.IsMoreThan)35 Test (org.junit.Test)30 Set (java.util.Set)28