use of com.baidu.hugegraph.traversal.algorithm.CollectionPathsTraverser in project incubator-hugegraph by apache.
the class PathsAPI method post.
@POST
@Timed
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String post(@Context GraphManager manager, @PathParam("graph") String graph, Request request) {
E.checkArgumentNotNull(request, "The request body can't be null");
E.checkArgumentNotNull(request.sources, "The sources of request can't be null");
E.checkArgumentNotNull(request.targets, "The targets of request can't be null");
E.checkArgumentNotNull(request.step, "The step of request can't be null");
E.checkArgument(request.depth > 0 && request.depth <= DEFAULT_MAX_DEPTH, "The depth of request must be in (0, %s], " + "but got: %s", DEFAULT_MAX_DEPTH, request.depth);
LOG.debug("Graph [{}] get paths from source vertices '{}', target " + "vertices '{}', with step '{}', max depth '{}', " + "capacity '{}', limit '{}' and with_vertex '{}'", graph, request.sources, request.targets, request.step, request.depth, request.capacity, request.limit, request.withVertex);
HugeGraph g = graph(manager, graph);
Iterator<Vertex> sources = request.sources.vertices(g);
Iterator<Vertex> targets = request.targets.vertices(g);
EdgeStep step = step(g, request.step);
CollectionPathsTraverser traverser = new CollectionPathsTraverser(g);
Collection<HugeTraverser.Path> paths;
paths = traverser.paths(sources, targets, step, request.depth, request.nearest, request.capacity, request.limit);
if (!request.withVertex) {
return manager.serializer(g).writePaths("paths", paths, false);
}
Set<Id> ids = new HashSet<>();
for (HugeTraverser.Path p : paths) {
ids.addAll(p.vertices());
}
Iterator<Vertex> iter = QueryResults.emptyIterator();
if (!ids.isEmpty()) {
iter = g.vertices(ids.toArray());
}
return manager.serializer(g).writePaths("paths", paths, false, iter);
}
Aggregations