use of au.gov.asd.tac.constellation.graph.file.io.GraphParseException in project constellation by constellation-app.
the class LoadTemplatePlugin method loadTemplate.
private void loadTemplate(final File loadFile, final String templateName) throws PluginException {
try {
final Graph graph = new GraphJsonReader().readGraphZip(loadFile, new HandleIoProgress("Loading Template..."));
GraphOpener.getDefault().openGraph(graph, templateName);
} catch (GraphParseException | IOException ex) {
throw new PluginException(this, PluginNotificationLevel.ERROR, "Failed to open template", ex);
}
}
use of au.gov.asd.tac.constellation.graph.file.io.GraphParseException in project constellation by constellation-app.
the class OpenGraph method callService.
@Override
public void callService(final PluginParameters parameters, final InputStream in, final OutputStream out) throws IOException {
final String filePath = parameters.getStringValue(FILE_PARAMETER_ID);
final String existingId = RestServiceUtilities.activeGraphId();
final File fnam = new File(filePath).getAbsoluteFile();
String name = fnam.getName();
if (StringUtils.endsWithIgnoreCase(name, GraphDataObject.FILE_EXTENSION)) {
name = name.substring(0, name.length() - GraphDataObject.FILE_EXTENSION.length());
}
try {
final Graph g = new GraphJsonReader().readGraphZip(fnam, new HandleIoProgress(String.format("Loading graph %s...", fnam)));
GraphOpener.getDefault().openGraph(g, name, false);
final String newId = RestServiceUtilities.waitForGraphChange(existingId);
final Graph graph = GraphNode.getGraphNode(newId).getGraph();
final ObjectMapper mapper = new ObjectMapper();
final ObjectNode root = mapper.createObjectNode();
root.put("id", graph.getId());
root.put("name", GraphNode.getGraphNode(graph.getId()).getDisplayName());
root.put("schema", graph.getSchema().getFactory().getName());
mapper.writeValue(out, root);
} catch (final GraphParseException | FileNotFoundException ex) {
throw new RestServiceException(HTTP_UNPROCESSABLE_ENTITY, ex.getMessage());
}
}
Aggregations