Search in sources :

Example 6 with GetAllElements

use of uk.gov.gchq.gaffer.operation.impl.get.GetAllElements in project Gaffer by gchq.

the class GetAllElementsIT method shouldGetAllElements.

protected void shouldGetAllElements(boolean includeEntities, final IncludeEdgeType includeEdgeType) throws Exception {
    // Given
    final List<Element> expectedElements = new ArrayList<>();
    if (includeEntities) {
        expectedElements.addAll(getEntities().values());
    }
    for (final Edge edge : getEdges().values()) {
        if (IncludeEdgeType.ALL == includeEdgeType || (edge.isDirected() && IncludeEdgeType.DIRECTED == includeEdgeType) || (!edge.isDirected() && IncludeEdgeType.UNDIRECTED == includeEdgeType)) {
            expectedElements.add(edge);
        }
    }
    final GetAllElements<Element> op = new GetAllElements.Builder<>().includeEntities(includeEntities).includeEdges(includeEdgeType).populateProperties(true).view(new View.Builder().entity(TestGroups.ENTITY).edge(TestGroups.EDGE).build()).build();
    // When
    final CloseableIterable<? extends Element> results = graph.execute(op, getUser());
    // Then
    final List<Element> expectedElementsCopy = Lists.newArrayList(expectedElements);
    for (final Element result : results) {
        final ElementSeed seed = ElementSeed.createSeed(result);
        if (result instanceof Entity) {
            Entity entity = (Entity) result;
            assertTrue("Entity was not expected: " + entity, expectedElements.contains(entity));
        } else {
            Edge edge = (Edge) result;
            if (edge.isDirected()) {
                assertTrue("Edge was not expected: " + edge, expectedElements.contains(edge));
            } else {
                final Edge edgeReversed = new Edge(TestGroups.EDGE, edge.getDestination(), edge.getSource(), edge.isDirected());
                expectedElementsCopy.remove(edgeReversed);
                assertTrue("Edge was not expected: " + seed, expectedElements.contains(result) || expectedElements.contains(edgeReversed));
            }
        }
        expectedElementsCopy.remove(result);
    }
    assertEquals("The number of elements returned was not as expected. Missing elements: " + expectedElementsCopy, expectedElements.size(), Lists.newArrayList(results).size());
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View)

Example 7 with GetAllElements

use of uk.gov.gchq.gaffer.operation.impl.get.GetAllElements in project Gaffer by gchq.

the class GetAllElementsIT method shouldGetAllElementsFilteredOnGroup.

@TraitRequirement({ StoreTrait.PRE_AGGREGATION_FILTERING, StoreTrait.STORE_AGGREGATION })
@Test
public void shouldGetAllElementsFilteredOnGroup() throws Exception {
    final GetAllElements<Element> op = new GetAllElements.Builder<>().populateProperties(true).view(new View.Builder().entity(TestGroups.ENTITY).build()).build();
    // When
    final CloseableIterable<? extends Element> results = graph.execute(op, getUser());
    // Then
    final List<Element> resultList = Lists.newArrayList(results);
    assertEquals(getEntities().size(), resultList.size());
    for (final Element element : resultList) {
        assertEquals(TestGroups.ENTITY, element.getGroup());
    }
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Example 8 with GetAllElements

use of uk.gov.gchq.gaffer.operation.impl.get.GetAllElements in project Gaffer by gchq.

the class OperationServiceIT method shouldReturnChunkedGroupCounts.

@Test
public void shouldReturnChunkedGroupCounts() throws IOException {
    // Given
    RestApiTestUtil.addElements(DEFAULT_ELEMENTS);
    // When
    final Response response = RestApiTestUtil.executeOperationChainChunked(new OperationChain.Builder().first(new GetAllElements<>()).then(new CountGroups()).build());
    // Then
    final List<GroupCounts> results = readChunkedResults(response, new GenericType<ChunkedInput<GroupCounts>>() {
    });
    assertEquals(1, results.size());
    final GroupCounts groupCounts = results.get(0);
    verifyGroupCounts(groupCounts);
}
Also used : Response(javax.ws.rs.core.Response) ChunkedInput(org.glassfish.jersey.client.ChunkedInput) CountGroups(uk.gov.gchq.gaffer.operation.impl.CountGroups) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) GroupCounts(uk.gov.gchq.gaffer.data.GroupCounts) Test(org.junit.Test)

Example 9 with GetAllElements

use of uk.gov.gchq.gaffer.operation.impl.get.GetAllElements in project Gaffer by gchq.

the class CountGroupsIT method shouldCountGroupsOfElementsWhenLessElementsThanLimit.

@Test
public void shouldCountGroupsOfElementsWhenLessElementsThanLimit() throws OperationException, InterruptedException {
    // Given
    final User user = new User();
    final Integer limit = getEntities().size() + getEdges().size() + 1;
    final Entity entity = new Entity(TestGroups.ENTITY_2, VERTEX);
    entity.putProperty(TestPropertyNames.INT, 100);
    // When
    final GroupCounts counts = graph.execute(new Builder().first(new GetAllElements<>()).then(new CountGroups(limit)).build(), user);
    // Then
    assertEquals(1, counts.getEntityGroups().size());
    assertEquals(getEntities().size(), (int) counts.getEntityGroups().get(TestGroups.ENTITY));
    assertEquals(1, counts.getEdgeGroups().size());
    assertEquals(getEdges().size(), (int) counts.getEdgeGroups().get(TestGroups.EDGE));
    assertFalse(counts.isLimitHit());
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) User(uk.gov.gchq.gaffer.user.User) CountGroups(uk.gov.gchq.gaffer.operation.impl.CountGroups) Builder(uk.gov.gchq.gaffer.operation.OperationChain.Builder) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) GroupCounts(uk.gov.gchq.gaffer.data.GroupCounts) Test(org.junit.Test)

Example 10 with GetAllElements

use of uk.gov.gchq.gaffer.operation.impl.get.GetAllElements in project Gaffer by gchq.

the class CountGroupsIT method shouldCountGroupsOfElements.

@Test
public void shouldCountGroupsOfElements() throws OperationException, InterruptedException {
    // Given
    final User user = new User();
    final Entity entity = new Entity(TestGroups.ENTITY_2, VERTEX);
    entity.putProperty(TestPropertyNames.INT, 100);
    // When
    final GroupCounts counts = graph.execute(new Builder().first(new GetAllElements<>()).then(new CountGroups()).build(), user);
    // Then
    assertEquals(1, counts.getEntityGroups().size());
    assertEquals(getEntities().size(), (int) counts.getEntityGroups().get(TestGroups.ENTITY));
    assertEquals(1, counts.getEdgeGroups().size());
    assertEquals(getEdges().size(), (int) counts.getEdgeGroups().get(TestGroups.EDGE));
    assertFalse(counts.isLimitHit());
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) User(uk.gov.gchq.gaffer.user.User) CountGroups(uk.gov.gchq.gaffer.operation.impl.CountGroups) Builder(uk.gov.gchq.gaffer.operation.OperationChain.Builder) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) GroupCounts(uk.gov.gchq.gaffer.data.GroupCounts) Test(org.junit.Test)

Aggregations

GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)11 Test (org.junit.Test)8 GroupCounts (uk.gov.gchq.gaffer.data.GroupCounts)5 CountGroups (uk.gov.gchq.gaffer.operation.impl.CountGroups)5 Response (javax.ws.rs.core.Response)4 Element (uk.gov.gchq.gaffer.data.element.Element)4 Entity (uk.gov.gchq.gaffer.data.element.Entity)4 Builder (uk.gov.gchq.gaffer.operation.OperationChain.Builder)3 User (uk.gov.gchq.gaffer.user.User)3 IteratorSettingBuilder (uk.gov.gchq.gaffer.accumulostore.utils.IteratorSettingBuilder)2 IncludeEdgeType (uk.gov.gchq.gaffer.operation.GetOperation.IncludeEdgeType)2 IncludeIncomingOutgoingType (uk.gov.gchq.gaffer.operation.GetOperation.IncludeIncomingOutgoingType)2 ArrayList (java.util.ArrayList)1 ChunkedInput (org.glassfish.jersey.client.ChunkedInput)1 Edge (uk.gov.gchq.gaffer.data.element.Edge)1 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)1 TraitRequirement (uk.gov.gchq.gaffer.integration.TraitRequirement)1 ElementSeed (uk.gov.gchq.gaffer.operation.data.ElementSeed)1