use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.
the class VisibilityIT method shouldAccessNullVisibilityGroups.
@Test
@TraitRequirement(StoreTrait.VISIBILITY)
public void shouldAccessNullVisibilityGroups() throws OperationException, JsonProcessingException {
final Set<Element> elements = new HashSet<>();
final Entity entity1 = new Entity(TestGroups.ENTITY, "A");
entity1.putProperty(TestTypes.VISIBILITY, null);
elements.add(entity1);
final AddElements addElements = new AddElements.Builder().elements(elements).build();
graph.execute(addElements, USER_DEFAULT);
final GetElements<EntitySeed, Element> get = new GetElements.Builder<EntitySeed, Element>().addSeed(new EntitySeed("A")).addSeed(new EntitySeed("B")).build();
final CloseableIterable<Element> iterable = graph.execute(get, USER_DEFAULT);
final List<Element> results = Lists.newArrayList(iterable);
// Check for all entities which should be visible
assertThat("Results do not contain all expected entities.", results, hasSize(1));
for (final Element e : results) {
// Check that all visible entities contain the visibility property
assertTrue("Visibility property should be visible.", e.getProperties().containsKey(TestTypes.VISIBILITY));
assertThat("Visibility property should contain an empty String.", e.getProperties().get(TestTypes.VISIBILITY).toString(), isEmptyString());
}
iterable.close();
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.
the class FilteringIT method testFilteringProperties.
@Test
@TraitRequirement(StoreTrait.PRE_AGGREGATION_FILTERING)
public void testFilteringProperties() 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().preAggregationFilter(new ElementFilter.Builder().select(IdentifierType.VERTEX.name()).execute(new IsEqual("A5")).build()).build()).edge(TestGroups.EDGE, new ViewElementDefinition.Builder().preAggregationFilter(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 AccumuloSingleIDRetrieverTest method testUndirectedEdgeSeedQueries.
private void testUndirectedEdgeSeedQueries(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 EdgeSeed("" + i, "B", false));
ids.add(new EdgeSeed("" + i, "C", true));
}
final View view = new View.Builder().edge(TestGroups.EDGE).build();
AccumuloSingleIDRetriever retriever = null;
final GetElements<ElementSeed, ?> operation = new GetElements<>(view, ids);
operation.setIncludeEdges(IncludeEdgeType.UNDIRECTED);
try {
retriever = new AccumuloSingleIDRetriever(store, operation, user);
} catch (IteratorSettingException e) {
e.printStackTrace();
}
for (final Element element : retriever) {
Edge edge = (Edge) element;
assertEquals("B", edge.getDestination());
}
//We should have only 1000 returned the i-B edges that are undirected
assertEquals(numEntries, Iterables.size(retriever));
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.
the class AccumuloSingleIDRetrieverTest method testEntitySeedQueryEdgesOnly.
private void testEntitySeedQueryEdgesOnly(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(false);
try {
retriever = new AccumuloSingleIDRetriever(store, operation, user);
} catch (IteratorSettingException e) {
e.printStackTrace();
}
//Should find both i-B and i-C edges.
assertEquals(numEntries * 2, Iterables.size(retriever));
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.
the class AccumuloSingleIDRetrieverTest method testDirectedEdgeSeedQueries.
private void testDirectedEdgeSeedQueries(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 EdgeSeed("" + i, "B", false));
ids.add(new EdgeSeed("" + i, "C", true));
}
final View view = new View.Builder().edge(TestGroups.EDGE).build();
AccumuloSingleIDRetriever retriever = null;
final GetElements<ElementSeed, ?> operation = new GetElements<>(view, ids);
operation.setIncludeEdges(IncludeEdgeType.DIRECTED);
try {
retriever = new AccumuloSingleIDRetriever(store, operation, user);
} catch (IteratorSettingException e) {
e.printStackTrace();
}
for (final Element element : retriever) {
Edge edge = (Edge) element;
assertEquals("C", edge.getDestination());
}
//Should find 1000 only A-C
assertEquals(numEntries, Iterables.size(retriever));
}
Aggregations