use of uk.gov.gchq.gaffer.operation.data.EdgeSeed in project Gaffer by gchq.
the class EdgeSeedExtractorTest method shouldGetIdentifierFromEdge.
@Test
public void shouldGetIdentifierFromEdge() {
// Given
final EdgeSeedExtractor extractor = new EdgeSeedExtractor();
final Edge edge = new Edge(TestGroups.EDGE, "source", "destination", true);
// When
final EdgeSeed seed = extractor.getObject(edge);
// Then
assertEquals("source", seed.getSource());
assertEquals("destination", seed.getDestination());
assertTrue(seed.isDirected());
}
use of uk.gov.gchq.gaffer.operation.data.EdgeSeed in project Gaffer by gchq.
the class GafferResultCacheExporter method get.
public CloseableIterable<?> get(final String key) throws OperationException {
final GetEdges<EdgeSeed> getEdges = new GetEdges.Builder<EdgeSeed>().addSeed(new EdgeSeed(jobId, key, true)).view(new View.Builder().edge("result", new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select("opAuths").execute(new AreIn(userOpAuths)).build()).build()).build()).build();
final CloseableIterable<Edge> edges = resultCache.execute(getEdges, user);
if (null == edges) {
return new WrappedCloseableIterable<>(Collections.emptyList());
}
return new TransformJsonResult(edges, jsonSerialiser);
}
use of uk.gov.gchq.gaffer.operation.data.EdgeSeed 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.data.EdgeSeed 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));
}
use of uk.gov.gchq.gaffer.operation.data.EdgeSeed in project Gaffer by gchq.
the class ArrayListStoreTest method shouldAddAndGetRelatedEntities.
@Test
public void shouldAddAndGetRelatedEntities() throws OperationException {
final Graph graph = createGraph();
addElementsToGraph(graph);
//set up the operation to fetch the entities
final OperationChain<CloseableIterable<SimpleEntityDataObject>> opChain = new OperationChain.Builder().first(new GetEntities.Builder<>().addSeed(new EdgeSeed(2, 1, false)).view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.INT).execute(new IsLessThan(2)).build()).build()).build()).build()).then(new GenerateObjects.Builder<Entity, SimpleEntityDataObject>().generator(new SimpleEntityGenerator()).build()).build();
//now do the hop
final CloseableIterable<SimpleEntityDataObject> results = graph.execute(opChain, new User());
//check the results by converting our edges back into SimpleDataObjects
if (!results.iterator().hasNext()) {
fail("No results returned");
} else {
for (final SimpleEntityDataObject obj : results) {
LOGGER.info(obj.toString());
}
final List<SimpleEntityDataObject> resultList = Lists.newArrayList(results);
int index = 0;
SimpleEntityDataObject obj = resultList.get(index++);
assertEquals(1, obj.getId());
assertEquals(1, obj.getVisibility());
assertEquals("Red", obj.getProperties());
obj = resultList.get(index);
assertEquals(2, obj.getId());
assertEquals(1, obj.getVisibility());
assertEquals("Orange", obj.getProperties());
}
results.close();
}
Aggregations