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));
}
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")));
}
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();
}
Aggregations