Search in sources :

Example 1 with GraphMLWriter

use of com.tinkerpop.blueprints.util.io.graphml.GraphMLWriter in project orientdb by orientechnologies.

the class OGremlinConsole method exportDatabase.

@Override
@ConsoleCommand(description = "Export a database", splitInWords = false, onlineHelp = "Console-Command-Export")
public void exportDatabase(@ConsoleParameter(name = "options", description = "Export options") String iText) throws IOException {
    checkForDatabase();
    final List<String> items = OStringSerializerHelper.smartSplit(iText, ' ');
    final String fileName = items.size() <= 1 || items.get(1).charAt(0) == '-' ? null : items.get(1);
    if (fileName != null && (fileName.endsWith(".graphml") || fileName.endsWith(".xml"))) {
        message("\nExporting database in GRAPHML format to " + iText + "...");
        try {
            final OrientGraph g = (OrientGraph) OrientGraphFactory.getTxGraphImplFactory().getGraph(currentDatabase);
            g.setUseLog(false);
            g.setWarnOnForceClosingTx(false);
            // CREATE THE EXPORT FILE IF NOT EXIST YET
            final File f = new File(fileName);
            if (f.getParentFile() != null) {
                f.getParentFile().mkdirs();
            }
            f.createNewFile();
            new GraphMLWriter(g).outputGraph(fileName);
        } catch (ODatabaseImportException e) {
            printError(e);
        }
    } else
        // BASE EXPORT
        super.exportDatabase(iText);
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) GraphMLWriter(com.tinkerpop.blueprints.util.io.graphml.GraphMLWriter) ODatabaseImportException(com.orientechnologies.orient.core.db.tool.ODatabaseImportException) File(java.io.File) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

Example 2 with GraphMLWriter

use of com.tinkerpop.blueprints.util.io.graphml.GraphMLWriter in project hale by halestudio.

the class TransformationTreeMetadataHook method processTransformationTree.

/**
 * @see TransformationTreeHook#processTransformationTree(TransformationTree,
 *      TreeState, MutableInstance)
 */
@Override
public void processTransformationTree(TransformationTree tree, TreeState state, MutableInstance target) {
    if (state == TreeState.SOURCE_POPULATED) {
        // TODO key per state - for
        // now only support this
        // state
        TreeGraphProvider prov = new TreeGraphMLProvider(tree);
        Graph graph = prov.generateGraph();
        GraphMLWriter writer = new GraphMLWriter(graph);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try {
            writer.outputGraph(out);
        } catch (Exception e) {
            log.error("Error converting GraphML Graph to String", e);
        }
        String graphstring = new String(out.toByteArray());
        target.setMetaData(KEY_POPULATED_TREE, graphstring);
    }
}
Also used : Graph(com.tinkerpop.blueprints.Graph) GraphMLWriter(com.tinkerpop.blueprints.util.io.graphml.GraphMLWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

GraphMLWriter (com.tinkerpop.blueprints.util.io.graphml.GraphMLWriter)2 ConsoleCommand (com.orientechnologies.common.console.annotation.ConsoleCommand)1 ODatabaseImportException (com.orientechnologies.orient.core.db.tool.ODatabaseImportException)1 Graph (com.tinkerpop.blueprints.Graph)1 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1