Search in sources :

Example 26 with GetElements

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

the class AccumuloSingleIDRetrieverTest method testEntitySeedQueryEntitiesOnly.

private void testEntitySeedQueryEntitiesOnly(final AccumuloStore store) throws AccumuloException, StoreException {
    setupGraph(store, numEntries);
    final User user = new User();
    // Create set to query for
    final Set<ElementSeed> ids = new HashSet<>();
    for (int i = 0; i < numEntries; i++) {
        ids.add(new EntitySeed("" + i));
    }
    final View view = new View.Builder().edge(TestGroups.EDGE).entity(TestGroups.ENTITY).build();
    AccumuloSingleIDRetriever retriever = null;
    final GetElements<ElementSeed, ?> operation = new GetElements<>(view, ids);
    operation.setIncludeEntities(true);
    operation.setIncludeEdges(IncludeEdgeType.NONE);
    try {
        retriever = new AccumuloSingleIDRetriever(store, operation, user);
    } catch (IteratorSettingException e) {
        e.printStackTrace();
    }
    //Should find only the entities i
    assertEquals(numEntries, Iterables.size(retriever));
}
Also used : User(uk.gov.gchq.gaffer.user.User) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) IteratorSettingException(uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) HashSet(java.util.HashSet)

Example 27 with GetElements

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

the class FilteringIT method testPostAggregationFilteringProperties.

@Test
@TraitRequirement({ StoreTrait.POST_AGGREGATION_FILTERING, StoreTrait.STORE_AGGREGATION })
public void testPostAggregationFilteringProperties() throws OperationException {
    // Given
    final List<ElementSeed> seeds = Arrays.asList(new EntitySeed("A3"), new EdgeSeed("A5", "B5", false));
    final GetElements<ElementSeed, Element> getElementsWithoutFiltering = new GetElements.Builder<>().seeds(seeds).build();
    final GetElements<ElementSeed, Element> getElementsWithFiltering = new GetElements.Builder<>().seeds(seeds).view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select(IdentifierType.VERTEX.name()).execute(new IsEqual("A5")).build()).build()).edge(TestGroups.EDGE, new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.INT).execute(new IsLessThan(2)).build()).build()).build()).build();
    // When - without filtering
    final List<Element> resultsWithoutFiltering = Lists.newArrayList(graph.execute(getElementsWithoutFiltering, getUser()));
    // When - with filtering
    final List<Element> resultsWithFiltering = Lists.newArrayList(graph.execute(getElementsWithFiltering, getUser()));
    // Then - without filtering
    assertNotNull(resultsWithoutFiltering);
    assertEquals(8, resultsWithoutFiltering.size());
    assertThat(resultsWithoutFiltering, IsCollectionContaining.hasItems(getEdge("A3", "A3", false), getEdge("A3", "B3", false), getEdge("A3", "C3", false), getEdge("A3", "D3", false), getEdge("A5", "B5", false), getEntity("A5"), getEntity("B5")));
    // Then - with filtering
    assertNotNull(resultsWithFiltering);
    assertEquals(6, resultsWithFiltering.size());
    assertThat(resultsWithFiltering, IsCollectionContaining.hasItems(getEdge("A3", "A3", false), getEdge("A3", "B3", false), getEdge("A5", "B5", false), getEdge("A3", "D3", false), getEdge("A3", "C3", false), getEntity("A5")));
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) IsEqual(uk.gov.gchq.gaffer.function.filter.IsEqual) IsLessThan(uk.gov.gchq.gaffer.function.filter.IsLessThan) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Example 28 with GetElements

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

the class VisibilityIT method shouldAccessSingleVisibilityGroup.

@Test
@TraitRequirement(StoreTrait.VISIBILITY)
public void shouldAccessSingleVisibilityGroup() throws OperationException {
    final Set<Element> elements = new HashSet<>();
    final Entity entity1 = new Entity(TestGroups.ENTITY, "A");
    entity1.putProperty(TestTypes.VISIBILITY, "vis1");
    final Entity entity2 = new Entity(TestGroups.ENTITY, "B");
    entity2.putProperty(TestTypes.VISIBILITY, "vis1");
    elements.add(entity1);
    elements.add(entity2);
    final AddElements addElements = new AddElements.Builder().elements(elements).build();
    graph.execute(addElements, USER_VIS_1);
    final GetElements<EntitySeed, Element> get = new GetElements.Builder<EntitySeed, Element>().addSeed(new EntitySeed("A")).addSeed(new EntitySeed("B")).build();
    final CloseableIterable<Element> userVis1Iterable = graph.execute(get, USER_VIS_1);
    final CloseableIterable<Element> userVis2Iterable = graph.execute(get, USER_VIS_2);
    final List<Element> userVis1Results = Lists.newArrayList(userVis1Iterable);
    final List<Element> userVis2Results = Lists.newArrayList(userVis2Iterable);
    assertThat(userVis1Results, hasSize(2));
    assertThat(userVis2Results, is(empty()));
    for (final Element e : userVis1Results) {
        // Check that all visible entities contain the visibility property
        assertTrue("Missing visibility property.", e.getProperties().containsKey(TestTypes.VISIBILITY));
        // Check that the visibility key contai
        // ns the correct value
        assertEquals("Visibility property should be \"vis1\"", e.getProperties().get(TestTypes.VISIBILITY).toString(), "vis1");
    }
    userVis1Iterable.close();
    userVis2Iterable.close();
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Entity(uk.gov.gchq.gaffer.data.element.Entity) Element(uk.gov.gchq.gaffer.data.element.Element) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) HashSet(java.util.HashSet) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Aggregations

GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)28 Element (uk.gov.gchq.gaffer.data.element.Element)19 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)19 User (uk.gov.gchq.gaffer.user.User)16 HashSet (java.util.HashSet)15 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)14 Test (org.junit.Test)12 ElementSeed (uk.gov.gchq.gaffer.operation.data.ElementSeed)12 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)8 IteratorSettingException (uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException)7 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)5 TraitRequirement (uk.gov.gchq.gaffer.integration.TraitRequirement)4 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)4 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)3 Edge (uk.gov.gchq.gaffer.data.element.Edge)3 Entity (uk.gov.gchq.gaffer.data.element.Entity)3 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)3 GetAdjacentEntitySeeds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentEntitySeeds)3 ByteSequence (org.apache.accumulo.core.data.ByteSequence)2 Range (org.apache.accumulo.core.data.Range)2