Search in sources :

Example 1 with LazyVertex

use of org.vertexium.cli.model.LazyVertex in project vertexium by visallo.

the class VertexiumScript method vertexiumCypherResultToString.

private static String vertexiumCypherResultToString(VertexiumCypherResult cypherResult) {
    VertexiumScript.getContextProperties().clear();
    AtomicInteger vertexIndex = new AtomicInteger(0);
    AtomicInteger edgeIndex = new AtomicInteger(0);
    VertexiumCypherQueryContext ctx = new CliVertexiumCypherQueryContext(getGraph(), getAuthorizations());
    LinkedHashSet<String> columnNames = cypherResult.getColumnNames();
    List<List<String>> table = new ArrayList<>();
    table.add(new ArrayList<>(columnNames));
    table.addAll(cypherResult.stream().map(row -> columnNames.stream().map(columnName -> row.getByName(columnName)).map(o -> {
        if (o instanceof Vertex) {
            String vertexIndexString = "v" + vertexIndex.get();
            LazyVertex lazyVertex = new LazyVertex(((Vertex) o).getId());
            VertexiumScript.getContextVertices().put(vertexIndexString, lazyVertex);
            vertexIndex.incrementAndGet();
            return "@|bold " + vertexIndexString + ":|@ " + ((Vertex) o).getId();
        }
        if (o instanceof Edge) {
            String edgeIndexString = "e" + edgeIndex.get();
            LazyEdge lazyEdge = new LazyEdge(((Edge) o).getId());
            VertexiumScript.getContextEdges().put(edgeIndexString, lazyEdge);
            edgeIndex.incrementAndGet();
            return "@|bold " + edgeIndexString + ":|@ " + ((Edge) o).getId();
        }
        return ctx.getResultWriter().columnValueToString(ctx, o);
    }).collect(Collectors.toList())).collect(Collectors.toList()));
    return "\n" + ShellTableWriter.tableToString(table);
}
Also used : LazyProperty(org.vertexium.cli.model.LazyProperty) java.util(java.util) InvokerHelper(org.codehaus.groovy.runtime.InvokerHelper) VertexiumCypherQuery(org.vertexium.cypher.VertexiumCypherQuery) LazyEdge(org.vertexium.cli.model.LazyEdge) LazyExtendedDataTable(org.vertexium.cli.model.LazyExtendedDataTable) VertexiumCypherResult(org.vertexium.cypher.VertexiumCypherResult) IOException(java.io.IOException) Script(groovy.lang.Script) ShellTableWriter(org.vertexium.cli.utils.ShellTableWriter) Collectors(java.util.stream.Collectors) org.vertexium(org.vertexium) VertexiumCypherQueryContext(org.vertexium.cypher.VertexiumCypherQueryContext) IOUtils(org.apache.commons.io.IOUtils) Charset(java.nio.charset.Charset) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LazyVertex(org.vertexium.cli.model.LazyVertex) CypherCompilerContext(org.vertexium.cypher.ast.CypherCompilerContext) StreamingPropertyValue(org.vertexium.property.StreamingPropertyValue) InputStream(java.io.InputStream) LazyVertex(org.vertexium.cli.model.LazyVertex) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LazyVertex(org.vertexium.cli.model.LazyVertex) VertexiumCypherQueryContext(org.vertexium.cypher.VertexiumCypherQueryContext) LazyEdge(org.vertexium.cli.model.LazyEdge) LazyEdge(org.vertexium.cli.model.LazyEdge)

Aggregations

Script (groovy.lang.Script)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Charset (java.nio.charset.Charset)1 java.util (java.util)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Collectors (java.util.stream.Collectors)1 IOUtils (org.apache.commons.io.IOUtils)1 InvokerHelper (org.codehaus.groovy.runtime.InvokerHelper)1 org.vertexium (org.vertexium)1 LazyEdge (org.vertexium.cli.model.LazyEdge)1 LazyExtendedDataTable (org.vertexium.cli.model.LazyExtendedDataTable)1 LazyProperty (org.vertexium.cli.model.LazyProperty)1 LazyVertex (org.vertexium.cli.model.LazyVertex)1 ShellTableWriter (org.vertexium.cli.utils.ShellTableWriter)1 VertexiumCypherQuery (org.vertexium.cypher.VertexiumCypherQuery)1 VertexiumCypherQueryContext (org.vertexium.cypher.VertexiumCypherQueryContext)1 VertexiumCypherResult (org.vertexium.cypher.VertexiumCypherResult)1 CypherCompilerContext (org.vertexium.cypher.ast.CypherCompilerContext)1 StreamingPropertyValue (org.vertexium.property.StreamingPropertyValue)1