use of org.apache.tinkerpop.gremlin.server.op.OpProcessorException in project cypher-for-gremlin by opencypher.
the class CypherOpProcessor method traversal.
private GraphTraversalSource traversal(Context context) throws OpProcessorException {
RequestMessage msg = context.getRequestMessage();
GraphManager graphManager = context.getGraphManager();
Optional<Map<String, String>> aliasesOptional = msg.optionalArgs(Tokens.ARGS_ALIASES);
String gAlias = aliasesOptional.map(aliases -> aliases.get(Tokens.VAL_TRAVERSAL_SOURCE_ALIAS)).orElse(null);
if (gAlias == null) {
return graphManager.getGraphNames().stream().findFirst().map(graphManager::getGraph).map(Graph::traversal).orElseThrow(() -> opProcessorException(msg, "No graphs found on the server"));
}
Graph graph = graphManager.getGraph(gAlias);
if (graph != null) {
return graph.traversal();
}
TraversalSource traversalSource = graphManager.getTraversalSource(gAlias);
if (traversalSource instanceof GraphTraversalSource) {
return (GraphTraversalSource) traversalSource;
}
throw opProcessorException(msg, "Traversable alias '" + gAlias + "' not found");
}
Aggregations