use of uk.gov.gchq.gaffer.example.gettingstarted.generator.DataGenerator5 in project Gaffer by gchq.
the class LoadAndQuery5 method run.
public CloseableIterable<Edge> run() throws OperationException {
// [user] Create a user
// ---------------------------------------------------------
final User basicUser = new User("basicUser");
// ---------------------------------------------------------
// [generate] create some edges from the data file using our data generator class
// ---------------------------------------------------------
final List<Element> elements = new ArrayList<>();
final DataGenerator5 dataGenerator = new DataGenerator5();
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, basicUser);
// ---------------------------------------------------------
log("The elements have been added.\n");
log("\nNow run a simple query to get edges\n");
// [get simple] get all the edges that contain the vertex "1"
// ---------------------------------------------------------
final GetEdges<EntitySeed> getEdges = new GetEdges.Builder<EntitySeed>().addSeed(new EntitySeed("1")).build();
final CloseableIterable<Edge> resultsWithBasicUser = graph.execute(getEdges, basicUser);
// ---------------------------------------------------------
for (final Element e : resultsWithBasicUser) {
log("GET_RELATED_EDGES_RESULT", e.toString());
}
log("We get nothing back");
log("\nGet edges with the public visibility. We shouldn't see any of the private ones.\n");
// [get public] get all the edges that contain the vertex "1"
// ---------------------------------------------------------
final User publicUser = new User.Builder().userId("publicUser").dataAuth("public").build();
final GetEdges<EntitySeed> getPublicRelatedEdges = new GetEdges.Builder<EntitySeed>().addSeed(new EntitySeed("1")).build();
final CloseableIterable<Edge> publicResults = graph.execute(getPublicRelatedEdges, publicUser);
// ---------------------------------------------------------
for (final Element e : publicResults) {
log("GET_PUBLIC_RELATED_EDGES_RESULT", e.toString());
}
log("\nGet edges with the private visibility. We should get the public edges too.\n");
// [get private] get all the edges that contain the vertex "1"
// ---------------------------------------------------------
final User privateUser = new User.Builder().userId("privateUser").dataAuth("private").build();
final GetEdges<EntitySeed> getPrivateRelatedEdges = new GetEdges.Builder<EntitySeed>().addSeed(new EntitySeed("1")).build();
final CloseableIterable<Edge> privateResults = graph.execute(getPrivateRelatedEdges, privateUser);
// ---------------------------------------------------------
for (final Element e : privateResults) {
log("GET_PRIVATE_RELATED_EDGES_RESULT", e.toString());
}
return publicResults;
}
Aggregations