use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.
the class ToEntityIdTest method shouldReturnEntitySeedIfInputIsAnObject.
@Test
public void shouldReturnEntitySeedIfInputIsAnObject() {
// Given
final Object input = "item";
final ToEntityId function = new ToEntityId();
// When
final EntityId output = function.apply(input);
// Then
assertEquals(new EntitySeed(input), output);
}
use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.
the class Queries method runFullExample.
private void runFullExample(final Graph graph, final User user) throws OperationException {
final OperationChain<Iterable<? extends String>> opChain = new OperationChain.Builder().first(new GetAdjacentIds.Builder().input(new EntitySeed("South West")).view(new View.Builder().edge("RegionContainsLocation").build()).build()).then(new GetAdjacentIds.Builder().view(new View.Builder().edge("LocationContainsRoad").build()).build()).then(new ToSet<>()).then(new GetAdjacentIds.Builder().view(new View.Builder().edge("RoadHasJunction").build()).build()).then(new GetElements.Builder().view(new View.Builder().globalElements(new GlobalViewElementDefinition.Builder().groupBy().build()).entity("JunctionUse", new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select("startDate", "endDate").execute(new InDateRangeDual.Builder().start("2000/01/01").end("2001/01/01").build()).build()).postAggregationFilter(new ElementFilter.Builder().select("countByVehicleType").execute(new PredicateMap<>("BUS", new IsMoreThan(1000L))).build()).transientProperty("busCount", Long.class).transformer(new ElementTransformer.Builder().select("countByVehicleType").execute(new FreqMapExtractor("BUS")).project("busCount").build()).build()).build()).inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING).build()).then(new Sort.Builder().comparators(new ElementPropertyComparator.Builder().groups("JunctionUse").property("busCount").reverse(true).build()).resultLimit(2).deduplicate(true).build()).then(new ToCsv.Builder().generator(new CsvGenerator.Builder().vertex("Junction").property("busCount", "Bus Count").build()).build()).build();
final Iterable<? extends String> results = graph.execute(opChain, user);
System.out.println("Full example results:");
for (final String result : results) {
System.out.println(result);
}
}
use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.
the class AbstractLoaderIT method shouldGetElementsWithMatchedVertex.
@TraitRequirement({ StoreTrait.MATCHED_VERTEX, StoreTrait.QUERY_AGGREGATION })
@Test
public void shouldGetElementsWithMatchedVertex() throws Exception {
// Then
final View view = new Builder().edge(TestGroups.EDGE).build();
final GetElements op = new GetElements.Builder().input(new EntitySeed(SOURCE_DIR_1), new EntitySeed(DEST_DIR_2), new EntitySeed(SOURCE_DIR_3)).view(view).build();
final CloseableIterable<? extends Element> results = graph.execute(op, getUser());
assertElementEquals(getQuerySummarisedEdges(view).stream().filter(Edge::isDirected).filter(edge -> {
final List<String> vertices = Lists.newArrayList(SOURCE_DIR_1, SOURCE_DIR_2, SOURCE_DIR_3);
return vertices.contains(edge.getMatchedVertexValue());
}).collect(toList()), results);
}
use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.
the class AbstractLoaderIT method shouldGetElementsWithMatchedVertexFilter.
@TraitRequirement({ StoreTrait.MATCHED_VERTEX, StoreTrait.QUERY_AGGREGATION })
@Test
public void shouldGetElementsWithMatchedVertexFilter() throws Exception {
// Then
final View view = new Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(IdentifierType.ADJACENT_MATCHED_VERTEX.name()).execute(new IsIn(DEST_DIR_1, DEST_DIR_2, DEST_DIR_3)).build()).build()).build();
final GetElements op = new GetElements.Builder().input(new EntitySeed(SOURCE_DIR_1), new EntitySeed(DEST_DIR_2), new EntitySeed(SOURCE_DIR_3)).view(view).build();
// When
final CloseableIterable<? extends Element> results = graph.execute(op, getUser());
// Then
assertElementEquals(getQuerySummarisedEdges(view).stream().filter(Edge::isDirected).filter(edge -> {
final List<String> vertices = Lists.newArrayList(SOURCE_DIR_1, DEST_DIR_2, SOURCE_DIR_3);
return vertices.contains(edge.getMatchedVertexValue());
}).filter(edge -> {
final List<String> vertices = Lists.newArrayList(DEST_DIR_1, DEST_DIR_2, DEST_DIR_3);
return vertices.contains(edge.getAdjacentMatchedVertexValue());
}).collect(toList()), results);
}
use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.
the class VisibilityIT method shouldAccessMissingVisibilityGroups.
@Test
@TraitRequirement(StoreTrait.VISIBILITY)
public void shouldAccessMissingVisibilityGroups() throws OperationException {
final Set<Element> elements = new HashSet<>();
final Entity entity1 = new Entity(TestGroups.ENTITY, "A");
// Do NOT add an explicit visibility property
// entity1.putProperty(AccumuloPropertyNames.VISIBILITY, "");
elements.add(entity1);
final AddElements addElements = new AddElements.Builder().input(elements).build();
graph.execute(addElements, getUser());
final GetElements get = new GetElements.Builder().input(new EntitySeed("A")).build();
final CloseableIterable<? extends Element> iterable = graph.execute(get, getUser());
final List<Element> results = Lists.newArrayList(iterable);
// Check for all entities which should be visible
assertThat(results).withFailMessage("Results do not contain all expected entities.").hasSize(1);
for (final Element e : results) {
// Check that all visible entities contain the visibility property
assertThat(e.getProperties()).as("Visibility property should be visible.").containsKey(TestTypes.VISIBILITY);
assertThat(e.getProperties().get(TestTypes.VISIBILITY).toString()).withFailMessage("Visibility property should contain an empty String.").isEmpty();
}
iterable.close();
}
Aggregations