use of uk.gov.gchq.gaffer.data.graph.entity.EntityMap in project Gaffer by gchq.
the class GetWalksHandler method executeOperation.
private List<?> executeOperation(final Output<Iterable<Element>> operation, final List<?> seeds, final Integer resultLimit, final Context context, final Store store, final int hops, final AdjacencyMaps adjacencyMaps, final EntityMaps entityMaps) throws OperationException {
final Iterable<Element> results = executeOperation(operation, seeds, resultLimit, context, store);
final AdjacencyMap adjacencyMap = new AdjacencyMap();
final EntityMap entityMap = new EntityMap();
final List<Object> nextSeeds = new ArrayList<>();
for (final Element e : results) {
if (e instanceof Edge) {
final Edge edge = (Edge) e;
final Object nextSeed = edge.getAdjacentMatchedVertexValue();
nextSeeds.add(nextSeed);
adjacencyMap.putEdge(edge.getMatchedVertexValue(), nextSeed, edge);
} else {
final Entity entity = (Entity) e;
entityMap.putEntity(entity.getVertex(), entity);
}
}
if (hops > adjacencyMaps.size()) {
adjacencyMaps.add(adjacencyMap);
}
entityMaps.add(entityMap);
return nextSeeds;
}
use of uk.gov.gchq.gaffer.data.graph.entity.EntityMap in project Gaffer by gchq.
the class GetWalksHandler method doOperation.
@Override
public Iterable<Walk> doOperation(final GetWalks getWalks, final Context context, final Store store) throws OperationException {
// Check input
if (null == getWalks.getInput()) {
return null;
}
// Check there are some operations
if (null == getWalks.getOperations()) {
return new EmptyClosableIterable<>();
}
final Integer resultLimit = getWalks.getResultsLimit();
final int hops = getWalks.getNumberOfGetEdgeOperations();
final LimitedCloseableIterable limitedInputItr = new LimitedCloseableIterable<>(getWalks.getInput(), 0, resultLimit, false);
final List<EntityId> originalInput = Lists.newArrayList(limitedInputItr);
// Check hops and maxHops (if set)
if (hops == 0) {
return new EmptyClosableIterable<>();
} else if (maxHops != null && hops > maxHops) {
throw new OperationException("GetWalks operation contains " + hops + " hops. The maximum number of hops is: " + maxHops);
}
final AdjacencyMaps adjacencyMaps = prune && !getWalks.isIncludePartial() ? new PrunedAdjacencyMaps() : new SimpleAdjacencyMaps();
final EntityMaps entityMaps = new SimpleEntityMaps();
List<?> seeds = originalInput;
// Execute the operations
for (final OperationChain<Iterable<Element>> operation : getWalks.getOperations()) {
if (isWhileOperation(operation)) {
seeds = executeWhileOperation(operation, seeds, resultLimit, context, store, hops, adjacencyMaps, entityMaps);
} else {
seeds = executeOperation(operation, seeds, resultLimit, context, store, hops, adjacencyMaps, entityMaps);
}
}
// requested by the user.
if (entityMaps.size() == adjacencyMaps.size()) {
entityMaps.add(new EntityMap());
}
final GraphWindow graphWindow = new GraphWindow(adjacencyMaps, entityMaps);
// Track/recombine the edge objects and convert to return type
final Stream<Walk> walks = Streams.toStream(originalInput).flatMap(seed -> walk(seed.getVertex(), null, graphWindow, new LinkedList<>(), new LinkedList<>(), hops, getWalks.isIncludePartial()).stream());
return applyConditionalFiltering(walks, getWalks, context, store);
}
Aggregations