use of uk.gov.gchq.gaffer.example.gettingstarted.generator.DataGenerator2 in project Gaffer by gchq.
the class LoadAndQuery2 method run.
public CloseableIterable<Edge> run() throws OperationException {
// [user] Create a user
// ---------------------------------------------------------
final User user = new User("user01");
// ---------------------------------------------------------
// [generate] Create some edges from the data file using our data generator class
// ---------------------------------------------------------
final List<Element> elements = new ArrayList<>();
final DataGenerator2 dataGenerator = new DataGenerator2();
for (final String s : DataUtils.loadData(getData())) {
elements.add(dataGenerator.getElement(s));
}
// ---------------------------------------------------------
log("Elements generated from the data file.");
for (final Element element : elements) {
log("GENERATED_EDGES", element.toString());
}
log("");
// [graph] Create a graph using our schema and store properties
// ---------------------------------------------------------
final Graph graph = new Graph.Builder().addSchemas(getSchemas()).storeProperties(getStoreProperties()).build();
// ---------------------------------------------------------
// [add] Add the edges to the graph
// ---------------------------------------------------------
final AddElements addElements = new AddElements.Builder().elements(elements).build();
graph.execute(addElements, user);
// ---------------------------------------------------------
log("The elements have been added.\n");
// [get simple] Get all the edges related to vertex 1
// ---------------------------------------------------------
final GetEdges<EntitySeed> getRelatedEdges = new GetEdges.Builder<EntitySeed>().addSeed(new EntitySeed("1")).build();
final CloseableIterable<Edge> allColoursResults = graph.execute(getRelatedEdges, user);
// ---------------------------------------------------------
log("\nAll edges containing vertex 1");
log("\nNotice that the edges are aggregated within their groups");
for (final Element e : allColoursResults) {
log("GET_RELATED_EDGES_RESULT", e.toString());
}
// [get] Rerun the previous query with a View to specify which subset of results we want
// ---------------------------------------------------------
final View view = new View.Builder().edge("red").build();
final GetEdges<EntitySeed> getRelatedRedEdges = new GetEdges.Builder<EntitySeed>().addSeed(new EntitySeed("1")).view(view).build();
final CloseableIterable<Edge> redResults = graph.execute(getRelatedRedEdges, user);
// ---------------------------------------------------------
log("\nAll red edges containing vertex 1\n");
for (final Element e : redResults) {
log("GET_RELATED_RED_EDGES_RESULT", e.toString());
}
return redResults;
}
Aggregations