use of uk.gov.gchq.gaffer.data.element.id.DirectedType in project Gaffer by gchq.
the class ByteEntityIteratorSettingsFactory method getElementPropertyRangeQueryFilter.
@Override
public IteratorSetting getElementPropertyRangeQueryFilter(final GraphFilters operation) {
final boolean includeEntities = operation.getView().hasEntities();
final boolean includeEdges = operation.getView().hasEdges();
final DirectedType directedType = operation.getDirectedType();
final SeededGraphFilters.IncludeIncomingOutgoingType inOutType;
if (operation instanceof SeededGraphFilters) {
inOutType = ((SeededGraphFilters) operation).getIncludeIncomingOutGoing();
} else {
inOutType = SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING;
}
final boolean deduplicateUndirectedEdges = operation instanceof GetAllElements;
if (includeEdges && DirectedType.isEither(directedType) && (null == inOutType || inOutType == SeededGraphFilters.IncludeIncomingOutgoingType.EITHER) && includeEntities && !deduplicateUndirectedEdges) {
LOGGER.debug("Returning null from getElementPropertyRangeQueryFilter (" + "inOutType = {}, includeEdges = {}, " + "directedType = {}, deduplicateUndirectedEdges = {})", inOutType, includeEdges, directedType, deduplicateUndirectedEdges);
return null;
}
final IteratorSetting is = new IteratorSettingBuilder(AccumuloStoreConstants.RANGE_ELEMENT_PROPERTY_FILTER_ITERATOR_PRIORITY, AccumuloStoreConstants.RANGE_ELEMENT_PROPERTY_FILTER_ITERATOR_NAME, RANGE_ELEMENT_PROPERTY_FILTER_ITERATOR).all().includeIncomingOutgoing(inOutType).includeEdges(includeEdges).directedType(directedType).includeEntities(includeEntities).deduplicateUndirectedEdges(deduplicateUndirectedEdges).build();
LOGGER.debug("Creating IteratorSetting for iterator class {} with priority = {}, " + " includeIncomingOutgoing = {}, directedType = {}," + " includeEdges = {}, includeEntities = {}, deduplicateUndirectedEdges = {}", RANGE_ELEMENT_PROPERTY_FILTER_ITERATOR, AccumuloStoreConstants.RANGE_ELEMENT_PROPERTY_FILTER_ITERATOR_PRIORITY, inOutType, directedType, includeEdges, includeEntities, deduplicateUndirectedEdges);
return is;
}
use of uk.gov.gchq.gaffer.data.element.id.DirectedType in project Gaffer by gchq.
the class GetElementsHandlerTest method testGetElementsDirectedTypeOption.
@Test
public void testGetElementsDirectedTypeOption() throws OperationException {
// Given
final Graph graph = GetAllElementsHandlerTest.getGraph();
final AddElements addElements = new AddElements.Builder().input(getElements()).build();
graph.execute(addElements, new User());
// When directedType is EITHER
GetElements getElements = new GetElements.Builder().input(new EntitySeed("A"), new EntitySeed("X")).directedType(DirectedType.EITHER).build();
CloseableIterable<? extends Element> results = graph.execute(getElements, new User());
// Then
final Set<Element> resultsSet = new HashSet<>();
Streams.toStream(results).forEach(resultsSet::add);
final Set<Element> expectedResults = new HashSet<>();
getElements().stream().filter(element -> {
if (element instanceof Entity) {
final Entity entity = (Entity) element;
return entity.getVertex().equals("A") || entity.getVertex().equals("X");
} else {
final Edge edge = (Edge) element;
return edge.getSource().equals("A") || edge.getDestination().equals("A") || edge.getSource().equals("X") || edge.getDestination().equals("X");
}
}).forEach(expectedResults::add);
assertEquals(expectedResults, resultsSet);
// When view has no edges
getElements = new GetElements.Builder().input(new EntitySeed("A"), new EntitySeed("X")).view(new View.Builder().entity(TestGroups.ENTITY).build()).build();
results = graph.execute(getElements, new User());
// Then
resultsSet.clear();
Streams.toStream(results).forEach(resultsSet::add);
expectedResults.clear();
getElements().stream().filter(element -> {
if (element instanceof Entity) {
final Entity entity = (Entity) element;
return entity.getVertex().equals("A") || entity.getVertex().equals("X");
} else {
return false;
}
}).forEach(expectedResults::add);
assertEquals(expectedResults, resultsSet);
// When directedType is DIRECTED
getElements = new GetElements.Builder().input(new EntitySeed("A"), new EntitySeed("X")).directedType(DirectedType.DIRECTED).build();
results = graph.execute(getElements, new User());
// Then
resultsSet.clear();
Streams.toStream(results).forEach(resultsSet::add);
expectedResults.clear();
getElements().stream().filter(element -> {
if (element instanceof Entity) {
final Entity entity = (Entity) element;
return entity.getVertex().equals("A") || entity.getVertex().equals("X");
} else {
final Edge edge = (Edge) element;
return (edge.getSource().equals("A") || edge.getDestination().equals("A") || edge.getSource().equals("X") || edge.getDestination().equals("X")) && edge.isDirected();
}
}).forEach(expectedResults::add);
assertEquals(expectedResults, resultsSet);
// When directedType is UNDIRECTED
getElements = new GetElements.Builder().input(new EntitySeed("A"), new EntitySeed("X")).directedType(DirectedType.UNDIRECTED).build();
results = graph.execute(getElements, new User());
// Then
resultsSet.clear();
Streams.toStream(results).forEach(resultsSet::add);
expectedResults.clear();
getElements().stream().filter(element -> {
if (element instanceof Entity) {
final Entity entity = (Entity) element;
return entity.getVertex().equals("A") || entity.getVertex().equals("X");
} else {
final Edge edge = (Edge) element;
return (edge.getSource().equals("A") || edge.getDestination().equals("A") || edge.getSource().equals("X") || edge.getDestination().equals("X")) && !edge.isDirected();
}
}).forEach(expectedResults::add);
assertEquals(expectedResults, resultsSet);
}
use of uk.gov.gchq.gaffer.data.element.id.DirectedType in project Gaffer by gchq.
the class GetAllElementsHandlerTest method testGetAllElementsDirectedTypeOption.
@Test
public void testGetAllElementsDirectedTypeOption() throws OperationException {
// Given
final Graph graph = GetAllElementsHandlerTest.getGraph();
final AddElements addElements = new AddElements.Builder().input(getElements()).build();
graph.execute(addElements, new User());
// When directedType is ALL
GetAllElements getAllElements = new GetAllElements.Builder().directedType(DirectedType.EITHER).build();
CloseableIterable<? extends Element> results = graph.execute(getAllElements, new User());
// Then
final Set<Element> resultsSet = new HashSet<>();
Streams.toStream(results).forEach(resultsSet::add);
final Set<Element> expectedResults = new HashSet<>();
getElements().forEach(expectedResults::add);
assertEquals(expectedResults, resultsSet);
// When view has no edges
getAllElements = new GetAllElements.Builder().view(new View.Builder().entity(TestGroups.ENTITY).build()).build();
results = graph.execute(getAllElements, new User());
// Then
resultsSet.clear();
Streams.toStream(results).forEach(resultsSet::add);
expectedResults.clear();
getElements().stream().filter(element -> element instanceof Entity).forEach(expectedResults::add);
assertEquals(expectedResults, resultsSet);
// When directedType is DIRECTED
getAllElements = new GetAllElements.Builder().directedType(DirectedType.DIRECTED).build();
results = graph.execute(getAllElements, new User());
// Then
resultsSet.clear();
Streams.toStream(results).forEach(resultsSet::add);
expectedResults.clear();
getElements().stream().filter(element -> element instanceof Entity || ((Edge) element).isDirected()).forEach(expectedResults::add);
assertEquals(expectedResults, resultsSet);
// When directedType is UNDIRECTED
getAllElements = new GetAllElements.Builder().directedType(DirectedType.UNDIRECTED).build();
results = graph.execute(getAllElements, new User());
// Then
resultsSet.clear();
Streams.toStream(results).forEach(resultsSet::add);
expectedResults.clear();
getElements().stream().filter(element -> element instanceof Entity || !((Edge) element).isDirected()).forEach(expectedResults::add);
assertEquals(expectedResults, resultsSet);
}
use of uk.gov.gchq.gaffer.data.element.id.DirectedType in project Gaffer by gchq.
the class AbstractLoaderIT method getAllElements.
private void getAllElements() throws Exception {
for (final boolean includeEntities : Arrays.asList(true, false)) {
for (final boolean includeEdges : Arrays.asList(true, false)) {
if (!includeEntities && !includeEdges) {
// Cannot query for nothing!
continue;
}
for (final DirectedType directedType : DirectedType.values()) {
try {
final View.Builder viewBuilder = new View.Builder();
if (includeEntities) {
viewBuilder.entity(TestGroups.ENTITY);
}
if (includeEdges) {
viewBuilder.edge(TestGroups.EDGE);
}
getAllElements(includeEntities, includeEdges, directedType, viewBuilder.build());
} catch (final AssertionError e) {
throw new AssertionError("GetAllElements failed with parameters: includeEntities=" + includeEntities + ", includeEdges=" + includeEdges + ", directedType=" + directedType.name(), e);
}
}
}
}
}
use of uk.gov.gchq.gaffer.data.element.id.DirectedType in project Gaffer by gchq.
the class AbstractLoaderIT method getAllElements.
private void getAllElements(final boolean includeEntities, final boolean includeEdges, final DirectedType directedType, final View view) throws Exception {
// Given
List<Element> expectedElements = new ArrayList<>();
if (includeEntities) {
expectedElements.addAll(getQuerySummarisedEntities(view));
}
if (includeEdges) {
for (final Edge edge : getQuerySummarisedEdges(view)) {
if (DirectedType.EITHER == directedType || (edge.isDirected() && DirectedType.DIRECTED == directedType) || (!edge.isDirected() && DirectedType.UNDIRECTED == directedType)) {
expectedElements.add(edge);
}
}
}
if (!user.getDataAuths().isEmpty()) {
final String dataAuths = user.getDataAuths().stream().collect(Collectors.joining(","));
final List<Element> nonVisibleElements = expectedElements.stream().filter(e -> {
final String visibility = (String) e.getProperties().get(TestPropertyNames.VISIBILITY);
if (null != visibility) {
return !dataAuths.contains(visibility);
} else {
return false;
}
}).collect(toList());
expectedElements.removeAll(nonVisibleElements);
}
getAllElements(expectedElements, directedType, view);
}
Aggregations