use of uk.gov.gchq.gaffer.doc.user.generator.RoadUseElementGenerator in project gaffer-doc by gchq.
the class TheBasics method run.
@Override
public CloseableIterable<? extends Element> run() throws OperationException, IOException {
// [generate] Create some edges from the simple data file using our Road Use generator class
// ---------------------------------------------------------
final List<Element> elements = new ArrayList<>();
final RoadUseElementGenerator dataGenerator = new RoadUseElementGenerator();
for (final String line : IOUtils.readLines(StreamUtil.openStream(getClass(), dataPath))) {
elements.add(dataGenerator._apply(line));
}
// ---------------------------------------------------------
print("Elements generated from the data file.");
for (final Element element : elements) {
print("GENERATED_EDGES", element.toString());
}
print("");
Graph graph;
// [graph from files] Create a graph using config, schema and store properties files
// ---------------------------------------------------------
graph = new Graph.Builder().config(StreamUtil.openStream(getClass(), graphConfigPath)).addSchemas(StreamUtil.openStreams(getClass(), schemaPath)).storeProperties(StreamUtil.openStream(getClass(), storePropertiesPath)).build();
// ---------------------------------------------------------
// [graph] Create a graph using config, schema and store properties from java
// ---------------------------------------------------------
final GraphConfig config = new GraphConfig.Builder().graphId(getClass().getSimpleName()).build();
final Schema schema = new Schema.Builder().edge("RoadUse", new SchemaEdgeDefinition.Builder().description("A directed edge representing vehicles moving from junction A to junction B.").source("junction").destination("junction").directed("true").property("count", "count.long").build()).type("junction", new TypeDefinition.Builder().description("A road junction represented by a String.").clazz(String.class).build()).type("count.long", new TypeDefinition.Builder().description("A long count that must be greater than or equal to 0.").clazz(Long.class).validateFunctions(new IsMoreThan(0L, true)).aggregateFunction(new Sum()).build()).type("true", new TypeDefinition.Builder().description("A simple boolean that must always be true.").clazz(Boolean.class).validateFunctions(new IsTrue()).build()).build();
final AccumuloProperties properties = new AccumuloProperties();
properties.setStoreClass(SingleUseMockAccumuloStore.class);
properties.setInstance("instance1");
properties.setZookeepers("zookeeper1");
properties.setUser("user01");
properties.setPassword("password");
graph = new Graph.Builder().config(config).addSchema(schema).storeProperties(properties).build();
// ---------------------------------------------------------
// [user] Create a user
// ---------------------------------------------------------
final User user = new User("user01");
// ---------------------------------------------------------
// [add] Add the edges to the graph
// ---------------------------------------------------------
final AddElements addElements = new AddElements.Builder().input(elements).build();
graph.execute(addElements, user);
// ---------------------------------------------------------
print("The elements have been added.");
// [get] Get all the edges that contain the vertex "10"
// ---------------------------------------------------------
final GetElements query = new GetElements.Builder().input(new EntitySeed("10")).view(new View.Builder().edge("RoadUse").build()).build();
final CloseableIterable<? extends Element> results = graph.execute(query, user);
// ---------------------------------------------------------
print("\nAll edges containing the vertex 10. The counts have been aggregated.");
for (final Element e : results) {
print("GET_ELEMENTS_RESULT", e.toString());
}
return results;
}
Aggregations