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));
}
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));
}
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);
}
}
}
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();
}
}
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();
}
}
Aggregations