Search in sources :

Example 1 with GraphParseException

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);
    }
}
Also used : Graph(au.gov.asd.tac.constellation.graph.Graph) HandleIoProgress(au.gov.asd.tac.constellation.utilities.gui.HandleIoProgress) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) GraphParseException(au.gov.asd.tac.constellation.graph.file.io.GraphParseException) IOException(java.io.IOException) GraphJsonReader(au.gov.asd.tac.constellation.graph.file.io.GraphJsonReader)

Example 2 with GraphParseException

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());
    }
}
Also used : RestServiceException(au.gov.asd.tac.constellation.webserver.restapi.RestServiceException) Graph(au.gov.asd.tac.constellation.graph.Graph) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HandleIoProgress(au.gov.asd.tac.constellation.utilities.gui.HandleIoProgress) FileNotFoundException(java.io.FileNotFoundException) GraphParseException(au.gov.asd.tac.constellation.graph.file.io.GraphParseException) File(java.io.File) GraphJsonReader(au.gov.asd.tac.constellation.graph.file.io.GraphJsonReader) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

Graph (au.gov.asd.tac.constellation.graph.Graph)2 GraphJsonReader (au.gov.asd.tac.constellation.graph.file.io.GraphJsonReader)2 GraphParseException (au.gov.asd.tac.constellation.graph.file.io.GraphParseException)2 HandleIoProgress (au.gov.asd.tac.constellation.utilities.gui.HandleIoProgress)2 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)1 RestServiceException (au.gov.asd.tac.constellation.webserver.restapi.RestServiceException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1