use of uk.gov.gchq.gaffer.operation.GetOperation.IncludeEdgeType in project Gaffer by gchq.
the class ClassicIteratorSettingsFactory method getEdgeEntityDirectionFilterIteratorSetting.
@Override
public IteratorSetting getEdgeEntityDirectionFilterIteratorSetting(final GetElementsOperation<?, ?> operation) {
final boolean includeEntities = operation.isIncludeEntities();
final IncludeEdgeType includeEdgeType = operation.getIncludeEdges();
final IncludeIncomingOutgoingType includeIncomingOutgoingType = operation.getIncludeIncomingOutGoing();
final boolean deduplicateUndirectedEdges = operation instanceof GetAllElements;
if (includeIncomingOutgoingType == IncludeIncomingOutgoingType.BOTH && includeEdgeType == IncludeEdgeType.ALL && !deduplicateUndirectedEdges) {
return null;
}
return new IteratorSettingBuilder(AccumuloStoreConstants.EDGE_ENTITY_DIRECTED_UNDIRECTED_INCOMING_OUTGOING_FILTER_ITERATOR_PRIORITY, AccumuloStoreConstants.EDGE_ENTITY_DIRECTED_UNDIRECTED_INCOMING_OUTGOING_FILTER_ITERATOR_NAME, EDGE_DIRECTED_UNDIRECTED_FILTER).includeIncomingOutgoing(includeIncomingOutgoingType).includeEdges(includeEdgeType).includeEntities(includeEntities).deduplicateUndirectedEdges(deduplicateUndirectedEdges).build();
}
use of uk.gov.gchq.gaffer.operation.GetOperation.IncludeEdgeType in project Gaffer by gchq.
the class ClassicRangeFactory method getRange.
@Override
protected <T extends GetElementsOperation<?, ?>> List<Range> getRange(final Object vertex, final T operation, final IncludeEdgeType includeEdgesParam) throws RangeFactoryException {
final IncludeEdgeType includeEdges;
final boolean includeEntities;
if (SeedMatchingType.EQUAL.equals(operation.getSeedMatching())) {
includeEdges = IncludeEdgeType.NONE;
includeEntities = true;
} else {
includeEdges = includeEdgesParam;
includeEntities = operation.isIncludeEntities();
}
byte[] serialisedVertex;
try {
serialisedVertex = ByteArrayEscapeUtils.escape(schema.getVertexSerialiser().serialise(vertex));
} catch (final SerialisationException e) {
throw new RangeFactoryException("Failed to serialise identifier", e);
}
final boolean returnEdges = includeEdges != IncludeEdgeType.NONE;
if (!includeEntities && !returnEdges) {
throw new IllegalArgumentException("Need to include either Entities or Edges or both when getting Range from a type and value");
}
if (includeEntities && returnEdges) {
return Collections.singletonList(getRange(serialisedVertex));
} else if (includeEntities) {
return Collections.singletonList(getEntityRangeFromVertex(serialisedVertex));
} else {
return Collections.singletonList(getEdgeRangeFromVertex(serialisedVertex));
}
}
use of uk.gov.gchq.gaffer.operation.GetOperation.IncludeEdgeType in project Gaffer by gchq.
the class GetElementsHandler method isSeedRelated.
private boolean isSeedRelated(final GetElements<ElementSeed, Element> operation, final Edge edge) {
final Matches seedMatches = isSeedRelated(ElementSeed.createSeed(edge), operation.getSeeds());
final IncludeEdgeType includeEdgeType = operation.getIncludeEdges();
final IncludeIncomingOutgoingType inOutType = operation.getIncludeIncomingOutGoing();
if (IncludeEdgeType.ALL == includeEdgeType) {
if (IncludeIncomingOutgoingType.BOTH == inOutType) {
return seedMatches.isMatch();
}
if (IncludeIncomingOutgoingType.INCOMING == inOutType) {
if (edge.isDirected()) {
return seedMatches.isDestination();
}
return seedMatches.isMatch();
}
if (IncludeIncomingOutgoingType.OUTGOING == inOutType) {
if (edge.isDirected()) {
return seedMatches.isSource();
}
return seedMatches.isMatch();
}
}
if (IncludeEdgeType.DIRECTED == includeEdgeType) {
if (!edge.isDirected()) {
return false;
}
if (IncludeIncomingOutgoingType.BOTH == inOutType) {
return seedMatches.isMatch();
}
if (IncludeIncomingOutgoingType.INCOMING == inOutType) {
return seedMatches.isDestination();
}
if (IncludeIncomingOutgoingType.OUTGOING == inOutType) {
return seedMatches.isSource();
}
}
if (IncludeEdgeType.UNDIRECTED == includeEdgeType) {
if (edge.isDirected()) {
return false;
}
if (IncludeIncomingOutgoingType.BOTH == inOutType) {
return seedMatches.isMatch();
}
if (IncludeIncomingOutgoingType.INCOMING == inOutType) {
return seedMatches.isMatch();
}
if (IncludeIncomingOutgoingType.OUTGOING == inOutType) {
return seedMatches.isMatch();
}
}
return false;
}
use of uk.gov.gchq.gaffer.operation.GetOperation.IncludeEdgeType in project Gaffer by gchq.
the class ByteEntityIteratorSettingsFactory method getElementPropertyRangeQueryFilter.
@Override
public IteratorSetting getElementPropertyRangeQueryFilter(final GetElementsOperation<?, ?> operation) {
final boolean includeEntities = operation.isIncludeEntities();
final IncludeEdgeType includeEdgeType = operation.getIncludeEdges();
final IncludeIncomingOutgoingType includeIncomingOutgoingType = operation.getIncludeIncomingOutGoing();
final boolean deduplicateUndirectedEdges = operation instanceof GetAllElements;
if (includeEdgeType == IncludeEdgeType.ALL && includeIncomingOutgoingType == IncludeIncomingOutgoingType.BOTH && includeEntities && !deduplicateUndirectedEdges) {
return null;
}
return new IteratorSettingBuilder(AccumuloStoreConstants.RANGE_ELEMENT_PROPERTY_FILTER_ITERATOR_PRIORITY, AccumuloStoreConstants.RANGE_ELEMENT_PROPERTY_FILTER_ITERATOR_NAME, RANGE_ELEMENT_PROPERTY_FILTER_ITERATOR).all().includeIncomingOutgoing(includeIncomingOutgoingType).includeEdges(includeEdgeType).includeEntities(includeEntities).deduplicateUndirectedEdges(deduplicateUndirectedEdges).build();
}
use of uk.gov.gchq.gaffer.operation.GetOperation.IncludeEdgeType in project Gaffer by gchq.
the class ByteEntityRangeFactory method getRange.
@Override
protected <T extends GetElementsOperation<?, ?>> List<Range> getRange(final Object vertex, final T operation, final IncludeEdgeType includeEdgesParam) throws RangeFactoryException {
final IncludeIncomingOutgoingType inOutType = operation.getIncludeIncomingOutGoing();
final IncludeEdgeType includeEdges;
final boolean includeEntities;
if (SeedMatchingType.EQUAL.equals(operation.getSeedMatching())) {
includeEdges = IncludeEdgeType.NONE;
includeEntities = true;
} else {
includeEdges = includeEdgesParam;
includeEntities = operation.isIncludeEntities();
}
byte[] serialisedVertex;
try {
serialisedVertex = ByteArrayEscapeUtils.escape(schema.getVertexSerialiser().serialise(vertex));
} catch (final SerialisationException e) {
throw new RangeFactoryException("Failed to serialise identifier", e);
}
if (!includeEntities && includeEdges == IncludeEdgeType.NONE) {
throw new IllegalArgumentException("Need to include either Entities or Edges or both when getting Range");
}
if (includeEdges == IncludeEdgeType.NONE) {
// return only entities
return Collections.singletonList(new Range(getEntityKey(serialisedVertex, false), true, getEntityKey(serialisedVertex, true), true));
} else {
if (includeEntities) {
if (includeEdges == IncludeEdgeType.DIRECTED) {
// return onlyDirectedEdges and entities
if (inOutType == IncludeIncomingOutgoingType.INCOMING) {
return Arrays.asList(new Range(getEntityKey(serialisedVertex, false), true, getEntityKey(serialisedVertex, true), true), new Range(getDirectedEdgeKeyDestinationFirst(serialisedVertex, false), true, getDirectedEdgeKeyDestinationFirst(serialisedVertex, true), true));
} else if (inOutType == IncludeIncomingOutgoingType.OUTGOING) {
return Collections.singletonList(new Range(getEntityKey(serialisedVertex, false), true, getDirectedEdgeKeySourceFirst(serialisedVertex, true), true));
} else {
return Collections.singletonList(new Range(getEntityKey(serialisedVertex, false), false, getDirectedEdgeKeyDestinationFirst(serialisedVertex, true), false));
}
} else if (includeEdges == IncludeEdgeType.UNDIRECTED) {
// Entity only range and undirected only range
return Arrays.asList(new Range(getUnDirectedEdgeKey(serialisedVertex, false), true, getUnDirectedEdgeKey(serialisedVertex, true), true), new Range(getEntityKey(serialisedVertex, false), true, getEntityKey(serialisedVertex, true), true));
} else {
// Return everything
if (inOutType == IncludeIncomingOutgoingType.INCOMING) {
return Arrays.asList(new Range(getEntityKey(serialisedVertex, false), true, getEntityKey(serialisedVertex, true), true), new Range(getDirectedEdgeKeyDestinationFirst(serialisedVertex, false), true, getUnDirectedEdgeKey(serialisedVertex, true), true));
} else if (inOutType == IncludeIncomingOutgoingType.OUTGOING) {
return Arrays.asList(new Range(getEntityKey(serialisedVertex, false), true, getDirectedEdgeKeySourceFirst(serialisedVertex, true), true), new Range(getUnDirectedEdgeKey(serialisedVertex, false), true, getUnDirectedEdgeKey(serialisedVertex, true), true));
} else {
return Collections.singletonList(new Range(getEntityKey(serialisedVertex, false), true, getUnDirectedEdgeKey(serialisedVertex, true), true));
}
}
} else if (includeEdges == IncludeEdgeType.DIRECTED) {
if (inOutType == IncludeIncomingOutgoingType.INCOMING) {
return Collections.singletonList(new Range(getDirectedEdgeKeyDestinationFirst(serialisedVertex, false), true, getDirectedEdgeKeyDestinationFirst(serialisedVertex, true), true));
} else if (inOutType == IncludeIncomingOutgoingType.OUTGOING) {
return Collections.singletonList(new Range(getDirectedEdgeKeySourceFirst(serialisedVertex, false), true, getDirectedEdgeKeySourceFirst(serialisedVertex, true), true));
} else {
return Collections.singletonList(new Range(getDirectedEdgeKeySourceFirst(serialisedVertex, false), true, getDirectedEdgeKeyDestinationFirst(serialisedVertex, true), true));
}
} else if (includeEdges == IncludeEdgeType.UNDIRECTED) {
return Collections.singletonList(new Range(getUnDirectedEdgeKey(serialisedVertex, false), true, getUnDirectedEdgeKey(serialisedVertex, true), true));
} else {
// return all edges
if (inOutType == IncludeIncomingOutgoingType.INCOMING) {
return Collections.singletonList(new Range(getDirectedEdgeKeyDestinationFirst(serialisedVertex, false), true, getUnDirectedEdgeKey(serialisedVertex, true), true));
} else if (inOutType == IncludeIncomingOutgoingType.OUTGOING) {
return Arrays.asList(new Range(getDirectedEdgeKeySourceFirst(serialisedVertex, false), true, getDirectedEdgeKeySourceFirst(serialisedVertex, true), true), new Range(getUnDirectedEdgeKey(serialisedVertex, false), true, getUnDirectedEdgeKey(serialisedVertex, true), true));
} else {
final Pair<Key> keys = getAllEdgeOnlyKeys(serialisedVertex);
return Collections.singletonList(new Range(keys.getFirst(), false, keys.getSecond(), false));
}
}
}
}
Aggregations