Search in sources :

Example 1 with ExportConfig

use of apoc.export.util.ExportConfig in project neo4j-apoc-procedures by neo4j-contrib.

the class ExportCSV method exportCsv.

private Stream<ProgressInfo> exportCsv(@Name("file") String fileName, String source, Object data, Map<String, Object> config) throws Exception {
    checkWriteAllowed();
    ExportConfig c = new ExportConfig(config);
    ProgressReporter reporter = new ProgressReporter(null, null, new ProgressInfo(fileName, source, "csv"));
    PrintWriter printWriter = getPrintWriter(fileName, null);
    CsvFormat exporter = new CsvFormat(db);
    if (data instanceof SubGraph)
        exporter.dump(((SubGraph) data), printWriter, reporter, c);
    if (data instanceof Result)
        exporter.dump(((Result) data), printWriter, reporter, c);
    return reporter.stream();
}
Also used : ExportConfig(apoc.export.util.ExportConfig) ProgressInfo(apoc.result.ProgressInfo) ProgressReporter(apoc.export.util.ProgressReporter) SubGraph(org.neo4j.cypher.export.SubGraph) NodesAndRelsSubGraph(apoc.export.util.NodesAndRelsSubGraph) DatabaseSubGraph(org.neo4j.cypher.export.DatabaseSubGraph) PrintWriter(java.io.PrintWriter) FileUtils.getPrintWriter(apoc.util.FileUtils.getPrintWriter) Result(org.neo4j.graphdb.Result)

Example 2 with ExportConfig

use of apoc.export.util.ExportConfig in project neo4j-apoc-procedures by neo4j-contrib.

the class ExportCypher method query.

@Procedure
@Description("apoc.export.cypher.query(query,file,config) - exports nodes and relationships from the cypher statement incl. indexes as cypher statements to the provided file")
public Stream<DataProgressInfo> query(@Name("query") String query, @Name(value = "file", defaultValue = "") String fileName, @Name(value = "config", defaultValue = "{}") Map<String, Object> config) throws IOException {
    if (Util.isNullOrEmpty(fileName))
        fileName = null;
    ExportConfig c = new ExportConfig(config);
    Result result = db.execute(query);
    SubGraph graph = CypherResultSubGraph.from(result, db, c.getRelsInBetween());
    String source = String.format("statement: nodes(%d), rels(%d)", Iterables.count(graph.getNodes()), Iterables.count(graph.getRelationships()));
    return exportCypher(fileName, source, graph, c, false);
}
Also used : ExportConfig(apoc.export.util.ExportConfig) SubGraph(org.neo4j.cypher.export.SubGraph) NodesAndRelsSubGraph(apoc.export.util.NodesAndRelsSubGraph) DatabaseSubGraph(org.neo4j.cypher.export.DatabaseSubGraph) CypherResultSubGraph(org.neo4j.cypher.export.CypherResultSubGraph) Result(org.neo4j.graphdb.Result)

Example 3 with ExportConfig

use of apoc.export.util.ExportConfig in project neo4j-apoc-procedures by neo4j-contrib.

the class ExportGraphML method graph.

@Procedure
@Description("apoc.export.graphml.graph(graph,file,config) - exports given graph object as graphml to the provided file")
public Stream<ProgressInfo> graph(@Name("graph") Map<String, Object> graph, @Name("file") String fileName, @Name("config") Map<String, Object> config) throws Exception {
    Collection<Node> nodes = (Collection<Node>) graph.get("nodes");
    Collection<Relationship> rels = (Collection<Relationship>) graph.get("relationships");
    String source = String.format("graph: nodes(%d), rels(%d)", nodes.size(), rels.size());
    return exportGraphML(fileName, source, new NodesAndRelsSubGraph(db, nodes, rels), new ExportConfig(config));
}
Also used : ExportConfig(apoc.export.util.ExportConfig) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) NodesAndRelsSubGraph(apoc.export.util.NodesAndRelsSubGraph) Collection(java.util.Collection)

Example 4 with ExportConfig

use of apoc.export.util.ExportConfig in project neo4j-apoc-procedures by neo4j-contrib.

the class ExportGraphML method query.

@Procedure
@Description("apoc.export.graphml.query(query,file,config) - exports nodes and relationships from the cypher statement as graphml to the provided file")
public Stream<ProgressInfo> query(@Name("query") String query, @Name("file") String fileName, @Name("config") Map<String, Object> config) throws Exception {
    ExportConfig c = new ExportConfig(config);
    Result result = db.execute(query);
    SubGraph graph = CypherResultSubGraph.from(result, db, c.getRelsInBetween());
    String source = String.format("statement: nodes(%d), rels(%d)", Iterables.count(graph.getNodes()), Iterables.count(graph.getRelationships()));
    return exportGraphML(fileName, source, graph, c);
}
Also used : ExportConfig(apoc.export.util.ExportConfig) SubGraph(org.neo4j.cypher.export.SubGraph) NodesAndRelsSubGraph(apoc.export.util.NodesAndRelsSubGraph) DatabaseSubGraph(org.neo4j.cypher.export.DatabaseSubGraph) CypherResultSubGraph(org.neo4j.cypher.export.CypherResultSubGraph) Result(org.neo4j.graphdb.Result)

Example 5 with ExportConfig

use of apoc.export.util.ExportConfig in project neo4j-apoc-procedures by neo4j-contrib.

the class ExportGraphML method file.

@Procedure(name = "apoc.import.graphml", mode = Mode.WRITE)
@Description("apoc.import.graphml(file,config) - imports graphml file")
public Stream<ProgressInfo> file(@Name("file") String fileName, @Name("config") Map<String, Object> config) throws Exception {
    ProgressInfo result = Util.inThread(() -> {
        ExportConfig exportConfig = new ExportConfig(config);
        ProgressReporter reporter = new ProgressReporter(null, null, new ProgressInfo(fileName, "file", "graphml"));
        XmlGraphMLReader graphMLReader = new XmlGraphMLReader(db).reporter(reporter).batchSize(exportConfig.getBatchSize()).relType(exportConfig.defaultRelationshipType()).nodeLabels(exportConfig.readLabels());
        if (exportConfig.storeNodeIds())
            graphMLReader.storeNodeIds();
        graphMLReader.parseXML(FileUtils.readerFor(fileName));
        return reporter.getTotal();
    });
    return Stream.of(result);
}
Also used : ExportConfig(apoc.export.util.ExportConfig) ProgressInfo(apoc.result.ProgressInfo) ProgressReporter(apoc.export.util.ProgressReporter)

Aggregations

ExportConfig (apoc.export.util.ExportConfig)6 NodesAndRelsSubGraph (apoc.export.util.NodesAndRelsSubGraph)5 DatabaseSubGraph (org.neo4j.cypher.export.DatabaseSubGraph)3 SubGraph (org.neo4j.cypher.export.SubGraph)3 Result (org.neo4j.graphdb.Result)3 ProgressReporter (apoc.export.util.ProgressReporter)2 ProgressInfo (apoc.result.ProgressInfo)2 CypherResultSubGraph (org.neo4j.cypher.export.CypherResultSubGraph)2 Node (org.neo4j.graphdb.Node)2 Relationship (org.neo4j.graphdb.Relationship)2 FileUtils.getPrintWriter (apoc.util.FileUtils.getPrintWriter)1 PrintWriter (java.io.PrintWriter)1 Collection (java.util.Collection)1