Search in sources :

Example 1 with GraphJsonWriter

use of au.gov.asd.tac.constellation.graph.file.io.GraphJsonWriter in project constellation by constellation-app.

the class SaveGraphUtilities method saveGraphToTemporaryDirectory.

/**
 * Save the graph to the temporary directory for debugging.
 * <p>
 * The main use case of this method is debugging unit tests and so this
 * method does extra checks to make sure one can interact with the graph
 * build from a crude unit test.
 *
 * @param graph The graph
 * @param file The graph file
 * @throws IOException
 */
public static void saveGraphToTemporaryDirectory(final StoreGraph graph, final File file) throws IOException {
    makeGraphInteractable(graph);
    final GraphJsonWriter writer = new GraphJsonWriter();
    writer.writeGraphToZip(graph, file.getPath(), new TextIoProgress(false));
}
Also used : GraphJsonWriter(au.gov.asd.tac.constellation.graph.file.io.GraphJsonWriter) TextIoProgress(au.gov.asd.tac.constellation.utilities.gui.TextIoProgress)

Example 2 with GraphJsonWriter

use of au.gov.asd.tac.constellation.graph.file.io.GraphJsonWriter in project constellation by constellation-app.

the class SaveGraphUtilities method saveGraphToTemporaryDirectory.

/**
 * Save the graph to the temporary directory for debugging.
 * <p>
 * The main use case of this method is debugging unit tests and so this
 * method does extra checks to make sure one can interact with the graph
 * build from a crude unit test.
 *
 * @param graph The graph
 * @param filename The filename excluding the file extension
 * @throws IOException
 */
public static void saveGraphToTemporaryDirectory(final StoreGraph graph, final String filename) throws IOException {
    final File saveCreatedGraph = File.createTempFile(filename, FileExtensionConstants.STAR);
    makeGraphInteractable(graph);
    final GraphJsonWriter writer = new GraphJsonWriter();
    writer.writeGraphToZip(graph, saveCreatedGraph.getPath(), new TextIoProgress(false));
}
Also used : GraphJsonWriter(au.gov.asd.tac.constellation.graph.file.io.GraphJsonWriter) TextIoProgress(au.gov.asd.tac.constellation.utilities.gui.TextIoProgress) File(java.io.File)

Example 3 with GraphJsonWriter

use of au.gov.asd.tac.constellation.graph.file.io.GraphJsonWriter in project constellation by constellation-app.

the class AutosaveGraphPlugin method execute.

@Override
public void execute(final PluginGraphs graphs, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
    final Graph graph = graphs.getGraph();
    final String graphId = graph.getId();
    final GraphNode gnode = GraphNode.getGraphNode(graphId);
    // The user might have deleted the graph, so check first.
    if (gnode != null) {
        interaction.setProgress(-1, -1, "Autosaving: " + graphId, true);
        // We don't want to hold the user up while we're reading from a graph they might be using.
        // Make a copy of the graph so that we can release the read lock as soon as possible.
        GraphReadMethods copy;
        ReadableGraph rg = graph.getReadableGraph();
        try {
            copy = rg.copy();
        } finally {
            rg.release();
        }
        interaction.setProgress(1, 0, "Finished", true);
        final File saveDir = AutosaveUtilities.getAutosaveDir();
        try {
            final String gname = graph.getId() + FileExtensionConstants.STAR;
            StatusDisplayer.getDefault().setStatusText(String.format("Auto saving %s as %s at %s...", graphId, gname, new Date()));
            final File saveFile = new File(saveDir, gname);
            new GraphJsonWriter().writeGraphToZip(copy, saveFile.getPath(), new HandleIoProgress("Autosaving..."));
            ConstellationLoggerHelper.exportPropertyBuilder(this, GraphRecordStoreUtilities.getVertices(copy, false, false, false).getAll(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL), saveFile, ConstellationLoggerHelper.SUCCESS);
            final Properties p = new Properties();
            p.setProperty(AutosaveUtilities.ID, graph.getId());
            p.setProperty(AutosaveUtilities.NAME, gnode.getName());
            p.setProperty(AutosaveUtilities.PATH, gnode.getDataObject().getPrimaryFile().getPath());
            p.setProperty(AutosaveUtilities.UNSAVED, Boolean.toString(gnode.getDataObject().isInMemory()));
            p.setProperty(AutosaveUtilities.DT, ZonedDateTime.now().format(TemporalFormatting.ZONED_DATE_TIME_FORMATTER));
            try (OutputStream s = new FileOutputStream(new File(saveDir, gname + "_auto"))) {
                p.store(s, null);
            }
        } catch (IOException ex) {
            LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
        }
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) HandleIoProgress(au.gov.asd.tac.constellation.utilities.gui.HandleIoProgress) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) GraphNode(au.gov.asd.tac.constellation.graph.node.GraphNode) IOException(java.io.IOException) Properties(java.util.Properties) Date(java.util.Date) GraphReadMethods(au.gov.asd.tac.constellation.graph.GraphReadMethods) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) GraphJsonWriter(au.gov.asd.tac.constellation.graph.file.io.GraphJsonWriter) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 4 with GraphJsonWriter

use of au.gov.asd.tac.constellation.graph.file.io.GraphJsonWriter in project constellation by constellation-app.

the class SaveGraphUtilities method saveGraphToTemporaryDirectory.

/**
 * Save the graph to the temporary directory for debugging.
 * <p>
 * The main use case of this method is debugging unit tests and so this
 * method does extra checks to make sure one can interact with the graph
 * build from a crude unit test.
 *
 * @param graph The graph
 * @param filename The filename excluding the file extension
 * @param makeInteractable If true, will modify the graph and add attributes
 * to make sure the graph can be opened
 * @throws IOException
 * @throws InterruptedException
 */
public static void saveGraphToTemporaryDirectory(final Graph graph, final String filename, boolean makeInteractable) throws IOException, InterruptedException {
    final File saveCreatedGraph = File.createTempFile(filename, FileExtensionConstants.STAR);
    final WritableGraph wg = graph.getWritableGraph("make graph interactable", true);
    try {
        if (makeInteractable) {
            makeGraphInteractable(wg);
        }
    } finally {
        wg.commit();
    }
    final ReadableGraph rg = graph.getReadableGraph();
    try {
        final GraphJsonWriter writer = new GraphJsonWriter();
        writer.writeGraphToZip(rg, saveCreatedGraph.getPath(), new TextIoProgress(false));
    } finally {
        rg.release();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) GraphJsonWriter(au.gov.asd.tac.constellation.graph.file.io.GraphJsonWriter) TextIoProgress(au.gov.asd.tac.constellation.utilities.gui.TextIoProgress) File(java.io.File) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph)

Example 5 with GraphJsonWriter

use of au.gov.asd.tac.constellation.graph.file.io.GraphJsonWriter in project constellation by constellation-app.

the class SaveGraphUtilities method saveGraphToTemporaryDirectory.

/**
 * Save the graph to the temporary directory for debugging.
 * <p>
 * The main use case of this method is debugging unit tests and so this
 * method does extra checks to make sure one can interact with the graph
 * build from a crude unit test.
 *
 * @param graph The graph
 * @param file The graph file
 * @param makeInteractable If true, will modify the graph and add attributes
 * to make sure the graph can be opened
 * @throws IOException
 * @throws InterruptedException
 */
public static void saveGraphToTemporaryDirectory(final Graph graph, final File file, boolean makeInteractable) throws IOException, InterruptedException {
    final WritableGraph wg = graph.getWritableGraph("make graph interactable", true);
    try {
        if (makeInteractable) {
            makeGraphInteractable(wg);
        }
    } finally {
        wg.commit();
    }
    final ReadableGraph rg = graph.getReadableGraph();
    try {
        final GraphJsonWriter writer = new GraphJsonWriter();
        writer.writeGraphToZip(rg, file.getPath(), new TextIoProgress(false));
    } finally {
        rg.release();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) GraphJsonWriter(au.gov.asd.tac.constellation.graph.file.io.GraphJsonWriter) TextIoProgress(au.gov.asd.tac.constellation.utilities.gui.TextIoProgress) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph)

Aggregations

GraphJsonWriter (au.gov.asd.tac.constellation.graph.file.io.GraphJsonWriter)7 File (java.io.File)5 TextIoProgress (au.gov.asd.tac.constellation.utilities.gui.TextIoProgress)4 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)3 HandleIoProgress (au.gov.asd.tac.constellation.utilities.gui.HandleIoProgress)3 IOException (java.io.IOException)3 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)2 Graph (au.gov.asd.tac.constellation.graph.Graph)1 GraphReadMethods (au.gov.asd.tac.constellation.graph.GraphReadMethods)1 GraphNode (au.gov.asd.tac.constellation.graph.node.GraphNode)1 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 Date (java.util.Date)1 Properties (java.util.Properties)1 Preferences (java.util.prefs.Preferences)1 NotifyDescriptor (org.openide.NotifyDescriptor)1 NbPreferences (org.openide.util.NbPreferences)1