Search in sources :

Example 51 with PluginException

use of au.gov.asd.tac.constellation.plugins.PluginException in project constellation by constellation-app.

the class DefaultPluginEnvironmentNGTest method testExecuteEditPluginNowThrowsPluginException.

@Test(expectedExceptions = PluginException.class)
public void testExecuteEditPluginNowThrowsPluginException() throws Exception {
    System.out.println("executeEditPluginNow");
    GraphWriteMethods graph = mock(GraphWriteMethods.class);
    Plugin plugin = mock(Plugin.class);
    PluginException pluginException = mock(PluginException.class);
    PluginParameters parameters = mock(PluginParameters.class);
    boolean interactive = false;
    doThrow(pluginException).when(plugin).run(any(GraphWriteMethods.class), any(PluginInteraction.class), any(PluginParameters.class));
    when(pluginException.getNotificationLevel()).thenReturn(PluginNotificationLevel.FATAL);
    DefaultPluginEnvironment instance = new DefaultPluginEnvironment();
    instance.executeEditPluginNow(graph, plugin, parameters, interactive);
}
Also used : GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) Test(org.testng.annotations.Test)

Example 52 with PluginException

use of au.gov.asd.tac.constellation.plugins.PluginException in project constellation by constellation-app.

the class ExportToTextPlugin method execute.

@Override
protected void execute(final PluginGraphs graphs, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
    final String fileName = parameters.getParameters().get(FILE_NAME_PARAMETER_ID).getStringValue();
    final String text = parameters.getParameters().get(TEXT_PARAMETER_ID).getStringValue();
    final File file = new File(fileName);
    try {
        try (PrintWriter os = new PrintWriter(file, StandardCharsets.UTF_8.name())) {
            os.append(text);
        } catch (final UnsupportedEncodingException ex) {
            LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
        }
    } catch (final FileNotFoundException ex) {
        throw new PluginException(PluginNotificationLevel.ERROR, ex);
    }
}
Also used : PluginException(au.gov.asd.tac.constellation.plugins.PluginException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 53 with PluginException

use of au.gov.asd.tac.constellation.plugins.PluginException in project constellation by constellation-app.

the class RunPlugin method callService.

@Override
public void callService(final PluginParameters parameters, InputStream in, OutputStream out) throws IOException {
    final String pluginName = parameters.getStringValue(PLUGIN_NAME_PARAMETER_ID);
    final String graphId = parameters.getStringValue(GRAPH_ID_PARAMETER_ID);
    final Graph graph = graphId == null ? RestUtilities.getActiveGraph() : GraphNode.getGraph(graphId);
    if (graph != null) {
        try {
            final ObjectMapper mapper = new ObjectMapper();
            final JsonNode json = mapper.readTree(in);
            if (json.size() > 0) {
                final Plugin plugin = PluginRegistry.get(pluginName);
                final PluginParameters pluginParameters = plugin.createParameters();
                RestServiceUtilities.parametersFromJson((ObjectNode) json, pluginParameters);
                PluginExecution.withPlugin(plugin).withParameters(pluginParameters).executeNow(graph);
            } else {
                PluginExecution.withPlugin(pluginName).executeNow(graph);
            }
        } catch (final InterruptedException ex) {
            Thread.currentThread().interrupt();
            throw new RestServiceException(ex);
        } catch (final PluginException | IllegalArgumentException ex) {
            throw new RestServiceException(HTTP_UNPROCESSABLE_ENTITY, ex.getMessage());
        }
    } else {
        throw new RestServiceException(HTTP_UNPROCESSABLE_ENTITY, "No graph with id " + graphId);
    }
}
Also used : RestServiceException(au.gov.asd.tac.constellation.webserver.restapi.RestServiceException) Graph(au.gov.asd.tac.constellation.graph.Graph) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) JsonNode(com.fasterxml.jackson.databind.JsonNode) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Plugin(au.gov.asd.tac.constellation.plugins.Plugin)

Example 54 with PluginException

use of au.gov.asd.tac.constellation.plugins.PluginException in project constellation by constellation-app.

the class ScriptingUtilities method executePlugin.

/**
 * Lookup a plugin by name and execute it with default parameter values.
 *
 * @param graph The graph on which to execute the plugin.
 * @param pluginName The name of the plugin to execute.
 */
public void executePlugin(final SGraph graph, final String pluginName) {
    final Plugin plugin = PluginRegistry.get(pluginName);
    final PluginParameters parameters = new PluginParameters();
    parameters.appendParameters(plugin.createParameters());
    try {
        PluginExecution.withPlugin(plugin).withParameters(parameters).executeNow(graph.getGraph());
    } catch (final InterruptedException ex) {
        LOGGER.log(Level.SEVERE, ex, () -> pluginName + " was interrupted");
        Thread.currentThread().interrupt();
    } catch (final PluginException ex) {
        LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
    }
}
Also used : PluginException(au.gov.asd.tac.constellation.plugins.PluginException) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) Plugin(au.gov.asd.tac.constellation.plugins.Plugin)

Example 55 with PluginException

use of au.gov.asd.tac.constellation.plugins.PluginException in project constellation by constellation-app.

the class PluginReportPane method update.

/**
 * Updates the UI displayed by this PluginReportPane to reflect the current
 * state of the underlying PluginReport.
 */
private void update() {
    sequencePane.getStyleClass().clear();
    pluginNameLabel.getStyleClass().clear();
    messageLabel.getStyleClass().clear();
    Throwable error = pluginReport.getError();
    if (error == null) {
        long stopTime = pluginReport.getStopTime();
        // If the plugin is still running
        if (stopTime == -1) {
            sequencePane.getStyleClass().add("running");
            pluginNameLabel.getStyleClass().add(JavafxStyleManager.LIGHT_NAME_TEXT);
            messageLabel.getStyleClass().add(JavafxStyleManager.LIGHT_MESSAGE_TEXT);
        // If the plugin has finished
        } else {
            sequencePane.getStyleClass().add("finished");
            pluginNameLabel.getStyleClass().add(JavafxStyleManager.LIGHT_NAME_TEXT);
            messageLabel.getStyleClass().add(JavafxStyleManager.LIGHT_MESSAGE_TEXT);
        }
        if (pluginReport.getMessage() == null) {
            messageLabel.setVisible(false);
        } else {
            messageLabel.setVisible(true);
            messageLabel.setText(pluginReport.getMessage());
        }
    } else {
        // If the plugin has been cancelled
        if (error instanceof InterruptedException) {
            sequencePane.getStyleClass().add("interrupted");
            pluginNameLabel.getStyleClass().add(JavafxStyleManager.LIGHT_NAME_TEXT);
            messageLabel.getStyleClass().add(JavafxStyleManager.LIGHT_MESSAGE_TEXT);
            messageLabel.setText("Cancelled");
        // If the plugin failed in an expected way
        } else if (error instanceof PluginException) {
            sequencePane.getStyleClass().add("failed");
            pluginNameLabel.getStyleClass().add("darkNameText");
            messageLabel.getStyleClass().add("darkMessageText");
            Writer errorWriter = new CharArrayWriter();
            try (PrintWriter out = new PrintWriter(errorWriter)) {
                out.append(error.getMessage());
                out.append("\n\n");
                error.printStackTrace(out);
            }
            messageLabel.setText(errorWriter.toString());
        // If the plugin failed in an unexpected way
        } else {
            sequencePane.getStyleClass().add("errored");
            pluginNameLabel.getStyleClass().add(JavafxStyleManager.LIGHT_NAME_TEXT);
            messageLabel.getStyleClass().add(JavafxStyleManager.LIGHT_MESSAGE_TEXT);
            Writer errorWriter = new CharArrayWriter();
            try (PrintWriter out = new PrintWriter(errorWriter)) {
                out.append(error.getMessage());
                out.append("\n\n");
                error.printStackTrace(out);
            }
            messageLabel.setText(errorWriter.toString());
        }
    }
    int currentStep = pluginReport.getCurrentStep();
    int totalSteps = pluginReport.getTotalSteps();
    if (currentStep > totalSteps) {
        pluginProgressBar.setVisible(false);
    } else if (totalSteps <= 0) {
        pluginProgressBar.setVisible(true);
        pluginProgressBar.setProgress(-1);
    } else {
        pluginProgressBar.setVisible(true);
        pluginProgressBar.setProgress((double) currentStep / (double) totalSteps);
    }
    updateTime();
    pluginNameLabel.setText(pluginReport.getPluginName());
}
Also used : PluginException(au.gov.asd.tac.constellation.plugins.PluginException) PrintWriter(java.io.PrintWriter) CharArrayWriter(java.io.CharArrayWriter) Writer(java.io.Writer) CharArrayWriter(java.io.CharArrayWriter) PrintWriter(java.io.PrintWriter)

Aggregations

PluginException (au.gov.asd.tac.constellation.plugins.PluginException)60 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)28 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)23 Graph (au.gov.asd.tac.constellation.graph.Graph)21 ArrayList (java.util.ArrayList)20 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)19 Test (org.testng.annotations.Test)16 GraphRecordStore (au.gov.asd.tac.constellation.graph.processing.GraphRecordStore)14 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)12 IOException (java.io.IOException)12 List (java.util.List)12 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)10 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)10 File (java.io.File)10 PluginNotificationLevel (au.gov.asd.tac.constellation.plugins.PluginNotificationLevel)9 Map (java.util.Map)9 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)8 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)8 VisualConcept (au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept)8 PluginGraphs (au.gov.asd.tac.constellation.plugins.PluginGraphs)8