use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class GetElementsBetweenSetsHandlerTest method shouldHaveNoIncomingEdges.
private void shouldHaveNoIncomingEdges(final AccumuloStore store) throws OperationException {
final View view = new View.Builder(defaultView).entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().groupBy().build()).edge(TestGroups.EDGE, new ViewElementDefinition.Builder().groupBy().build()).build();
final GetElementsBetweenSets<Element> op = new GetElementsBetweenSets<>(seedsA, seedsB, view);
op.setIncludeIncomingOutGoing(IncludeIncomingOutgoingType.INCOMING);
final GetElementsBetweenSetsHandler handler = new GetElementsBetweenSetsHandler();
final CloseableIterable<Element> elements = handler.doOperation(op, user, store);
//The result size should be 1
assertEquals(1, Iterables.size(elements));
assertThat(elements, IsCollectionContaining.hasItem(expectedEntity1));
elements.close();
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class GetElementsWithinSetHandlerTest method shouldSummarise.
private void shouldSummarise(final AccumuloStore store) throws OperationException {
final View view = new View.Builder(defaultView).entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().groupBy().build()).edge(TestGroups.EDGE, new ViewElementDefinition.Builder().groupBy().build()).edge(TestGroups.EDGE_2, new ViewElementDefinition.Builder().groupBy().build()).build();
final GetElementsWithinSet<Element> operation = new GetElementsWithinSet<>(view, seeds);
final GetElementsWithinSetHandler handler = new GetElementsWithinSetHandler();
final CloseableIterable<Element> elements = handler.doOperation(operation, user, store);
//After query compaction the result size should be 3
assertEquals(3, Iterables.size(elements));
assertThat(elements, IsCollectionContaining.hasItems(expectedSummarisedEdge, expectedEntity1, expectedEntity2));
elements.close();
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class GetElementsinRangesHandlerTest method shouldReturnNothingWhenNoEdgesSet.
private void shouldReturnNothingWhenNoEdgesSet(final AccumuloStore store) throws OperationException {
// Create set to query for
final Set<Pair<ElementSeed>> simpleEntityRanges = new HashSet<>();
//get Everything between 0 and 1 (Note we are using strings and string serialisers, with this ordering 0999 is before 1)
simpleEntityRanges.add(new Pair<ElementSeed>(new EntitySeed("0"), new EntitySeed("1")));
final View view = new View.Builder(defaultView).entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().groupBy().build()).edge(TestGroups.EDGE, new ViewElementDefinition.Builder().groupBy().build()).build();
final GetElementsInRanges<Pair<ElementSeed>, Element> operation = new GetElementsInRanges<>(view, simpleEntityRanges);
//All Edges stored should be outgoing from our provided seeds.
operation.setIncludeEdges(IncludeEdgeType.UNDIRECTED);
final GetElementsInRangesHandler handler = new GetElementsInRangesHandler();
final CloseableIterable<Element> elements = handler.doOperation(operation, user, store);
final int count = Iterables.size(elements);
//There should be no incoming edges to the provided range
assertEquals(0, count);
elements.close();
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class GetElementsinRangesHandlerTest method shouldHaveNoIncomingEdges.
private void shouldHaveNoIncomingEdges(final AccumuloStore store) throws OperationException {
// Create set to query for
final Set<Pair<ElementSeed>> simpleEntityRanges = new HashSet<>();
final User user = new User();
//get Everything between 0 and 1 (Note we are using strings and string serialisers, with this ordering 0999 is before 1)
simpleEntityRanges.add(new Pair<ElementSeed>(new EntitySeed("0"), new EntitySeed("1")));
final View view = new View.Builder(defaultView).entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().groupBy().build()).edge(TestGroups.EDGE, new ViewElementDefinition.Builder().groupBy().build()).build();
final GetElementsInRanges<Pair<ElementSeed>, Element> operation = new GetElementsInRanges<>(view, simpleEntityRanges);
//All Edges stored should be outgoing from our provided seeds.
operation.setIncludeIncomingOutGoing(IncludeIncomingOutgoingType.INCOMING);
final GetElementsInRangesHandler handler = new GetElementsInRangesHandler();
final CloseableIterable<Element> elements = handler.doOperation(operation, user, store);
final int count = Iterables.size(elements);
//There should be no incoming edges to the provided range
assertEquals(0, count);
elements.close();
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class CountGroupsHandler method doOperation.
@Override
public GroupCounts doOperation(final CountGroups operation, final Context context, final Store store) throws OperationException {
int count = 0;
final GroupCounts groupCounts = new GroupCounts();
if (null != operation.getElements()) {
for (final Element element : operation.getElements()) {
if (null != operation.getLimit()) {
count++;
if (count > operation.getLimit()) {
groupCounts.setLimitHit(true);
break;
}
}
if (element instanceof Entity) {
groupCounts.addEntityGroup(element.getGroup());
} else {
groupCounts.addEdgeGroup(element.getGroup());
}
}
}
return groupCounts;
}
Aggregations