use of uk.gov.gchq.gaffer.doc.dev.generator.RoadAndRoadUseWithSecurityElementGenerator in project gaffer-doc by gchq.
the class Visibilities method run.
public CloseableIterable<? extends Element> run() throws OperationException, IOException {
// / [graph] create a graph using our schema and store properties
// ---------------------------------------------------------
final Graph graph = new Graph.Builder().config(getDefaultGraphConfig()).addSchemas(StreamUtil.openStreams(getClass(), schemaPath)).storeProperties(getDefaultStoreProperties()).build();
// ---------------------------------------------------------
// [user] Create a user
// ---------------------------------------------------------
final User basicUser = new User("user01");
// ---------------------------------------------------------
// [add] Create a data generator and add the edges to the graph using an operation chain consisting of:
// generateElements - generating edges from the data (note these are directed edges)
// addElements - add the edges to the graph
// ---------------------------------------------------------
final OperationChain<Void> addOpChain = new OperationChain.Builder().first(new GenerateElements.Builder<String>().generator(new RoadAndRoadUseWithSecurityElementGenerator()).input(IOUtils.readLines(StreamUtil.openStream(getClass(), "RoadAndRoadUseWithSecurity/data.txt"))).build()).then(new AddElements()).build();
graph.execute(addOpChain, basicUser);
// ---------------------------------------------------------
print("\nNow run a simple query to get edges\n");
// [get simple] get all the edges that contain the vertex "10" or "23"
// ---------------------------------------------------------
final GetElements getEdges = new GetElements.Builder().input(new EntitySeed("10"), new EntitySeed("23")).view(new View.Builder().edge("RoadUse").build()).build();
final CloseableIterable<? extends Element> resultsWithBasicUser = graph.execute(getEdges, basicUser);
// ---------------------------------------------------------
for (final Element e : resultsWithBasicUser) {
print("GET_ELEMENTS_RESULT", e.toString());
}
print("We get nothing back");
print("\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 "10" or "23"
// ---------------------------------------------------------
final User publicUser = new User.Builder().userId("publicUser").dataAuth("public").build();
final GetElements getPublicRelatedEdges = new GetElements.Builder().input(new EntitySeed("10"), new EntitySeed("23")).view(new View.Builder().edge("RoadUse").build()).build();
final CloseableIterable<? extends Element> publicResults = graph.execute(getPublicRelatedEdges, publicUser);
// ---------------------------------------------------------
for (final Element e : publicResults) {
print("GET_PUBLIC_EDGES_RESULT", e.toString());
}
print("\nGet edges with the private visibility. We should get the public edges too.\n");
// [get private] get all the edges that contain the vertex "10" or "23"
// ---------------------------------------------------------
final User privateUser = new User.Builder().userId("privateUser").dataAuth("private").build();
final GetElements getPrivateRelatedEdges = new GetElements.Builder().input(new EntitySeed("10"), new EntitySeed("23")).view(new View.Builder().edge("RoadUse").build()).build();
final CloseableIterable<? extends Element> privateResults = graph.execute(getPrivateRelatedEdges, privateUser);
// ---------------------------------------------------------
for (final Element e : privateResults) {
print("GET_PRIVATE_EDGES_RESULT", e.toString());
}
return publicResults;
}
Aggregations