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