use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class OperationServiceIT method shouldReturnNoChunkedElementsWhenNoElementsInGraph.
@Test
public void shouldReturnNoChunkedElementsWhenNoElementsInGraph() throws IOException {
// When
final Response response = RestApiTestUtil.executeOperationChainChunked(new OperationChain<>(new GetAllElements<>()));
// Then
final List<Element> results = readChunkedElements(response);
assertEquals(0, results.size());
}
use of uk.gov.gchq.gaffer.data.element.Element 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;
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class LoadAndQuery3 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 DataGenerator3 dataGenerator = new DataGenerator3();
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");
log("\nAll edges containing the vertex 1. The counts have been aggregated\n");
// [get simple] get all the edges that contain the vertex "1"
// ---------------------------------------------------------
final GetEdges<EntitySeed> getRelatedEdges = new GetEdges.Builder<EntitySeed>().addSeed(new EntitySeed("1")).build();
final CloseableIterable<Edge> results = graph.execute(getRelatedEdges, user);
// ---------------------------------------------------------
for (final Element e : results) {
log("GET_RELATED_EDGES_RESULT", e.toString());
}
// [get] rerun previous query with a filter to return only edges with a count more than 3
// ---------------------------------------------------------
final View view = new View.Builder().edge("data", new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select("count").execute(new IsMoreThan(3)).build()).build()).build();
final GetEdges<EntitySeed> getRelatedEdgesWithCountMoreThan3 = new GetEdges.Builder<EntitySeed>().addSeed(new EntitySeed("1")).view(view).build();
final CloseableIterable<Edge> filteredResults = graph.execute(getRelatedEdgesWithCountMoreThan3, user);
// ---------------------------------------------------------
log("\nAll edges containing the vertex 1 with an aggregated count more than than 3\n");
for (final Element e : filteredResults) {
log("GET_RELATED_ELEMENTS_WITH_COUNT_MORE_THAN_3_RESULT", e.toString());
}
return filteredResults;
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class LoadAndQuery4 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 DataGenerator4 dataGenerator = new DataGenerator4();
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 that contain the vertex "1"
// ---------------------------------------------------------
final GetEdges<EntitySeed> getRelatedEdges = new GetEdges.Builder<EntitySeed>().addSeed(new EntitySeed("1")).build();
final CloseableIterable<Edge> results = graph.execute(getRelatedEdges, user);
// ---------------------------------------------------------
log("\nAll edges containing the vertex 1. The counts and 'things' have been aggregated\n");
for (final Element e : results) {
log("GET_RELATED_EDGES_RESULT", e.toString());
}
// rerun previous query but calculate a mean
// [transform] Create a mean transient property using an element transformer
// ---------------------------------------------------------
final ElementTransformer mean = new ElementTransformer.Builder().select("thing", "count").project("mean").execute(new MeanTransform()).build();
// ---------------------------------------------------------
// [get] Add the element transformer to the view and run the query
// ---------------------------------------------------------
final View view = new View.Builder().edge("data", new ViewElementDefinition.Builder().transientProperty("mean", Float.class).transformer(mean).build()).build();
final GetEdges<EntitySeed> getRelatedEdgesWithMean = new GetEdges.Builder<EntitySeed>().addSeed(new EntitySeed("1")).view(view).build();
final CloseableIterable<Edge> transientResults = graph.execute(getRelatedEdgesWithMean, user);
// ---------------------------------------------------------
log("\nWe can add a new property to the edges that is calculated from the aggregated values of other properties\n");
for (final Element e : transientResults) {
log("GET_RELATED_ELEMENTS_WITH_MEAN_RESULT", e.toString());
}
return transientResults;
}
use of uk.gov.gchq.gaffer.data.element.Element 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