use of au.gov.asd.tac.constellation.plugins.PluginException in project constellation by constellation-app.
the class DefaultPluginEnvironment method executeReadPluginNow.
@Override
public Object executeReadPluginNow(final GraphReadMethods graph, final Plugin plugin, final PluginParameters parameters, final boolean interactive) throws InterruptedException, PluginException {
if (graph == null) {
LOGGER.log(Level.FINE, GRAPH_NULL_WARNING_MESSAGE, plugin.getName());
}
final ThreadConstraints callingConstraints = ThreadConstraints.getConstraints();
final int silentCount = callingConstraints.getSilentCount();
final boolean alwaysSilent = callingConstraints.isAlwaysSilent();
callingConstraints.setSilentCount(0);
callingConstraints.setAlwaysSilent(alwaysSilent || silentCount > 0);
final GraphReport graphReport = graph == null ? null : GraphReportManager.getGraphReport(graph.getId());
PluginReport parentReport = null;
PluginReport currentReport = null;
if (graphReport != null) {
parentReport = callingConstraints.getCurrentReport();
if (parentReport == null) {
currentReport = graphReport.addPluginReport(plugin);
} else {
currentReport = parentReport.addChildReport(plugin);
}
callingConstraints.setCurrentReport(currentReport);
}
final PluginManager manager = new PluginManager(DefaultPluginEnvironment.this, plugin, graph, interactive, null);
final PluginInteraction interaction = new DefaultPluginInteraction(manager, currentReport);
try {
ConstellationLogger.getDefault().pluginStarted(plugin, parameters, GraphNode.getGraph(graph != null ? graph.getId() : null));
} catch (final Exception ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage());
}
try {
plugin.run(graph, interaction, parameters);
} catch (final InterruptedException ex) {
auditPluginError(plugin, ex);
reportException(plugin.getName(), interaction, currentReport, null, ex);
Thread.currentThread().interrupt();
throw ex;
} catch (final PluginException ex) {
auditPluginError(plugin, ex);
reportException(plugin.getName(), interaction, currentReport, ex.getNotificationLevel(), ex);
throw ex;
} catch (final Exception ex) {
auditPluginError(plugin, ex);
reportException(plugin.getName(), interaction, currentReport, PluginNotificationLevel.ERROR, ex);
throw ex;
} finally {
callingConstraints.setSilentCount(silentCount);
callingConstraints.setAlwaysSilent(alwaysSilent);
if (currentReport != null) {
currentReport.stop();
callingConstraints.setCurrentReport(parentReport);
currentReport.firePluginReportChangedEvent();
}
try {
ConstellationLogger.getDefault().pluginStopped(plugin, parameters);
} catch (final Exception ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage());
}
}
return null;
}
use of au.gov.asd.tac.constellation.plugins.PluginException in project constellation by constellation-app.
the class DefaultInteractionEventHandler method createTransaction.
/**
* Creates a transaction on the graph between the specified vertices.
* <p>
* The vertex will be created via a plugin which will synchronously, holding
* up the event handler until it is finished. The reason for this is that
* otherwise the new transaction will not be visible until the event handler
* gives up its current lock (which if we are creating multiple transactions
* with the shift/control key down, could be indefinitely).
*
* @param fromVertex The graph id of the source vertex
* @param toVertex The graph id of the destination vertex
* @param directed Whether or not the transaction should be directed.
* @param wg Write access to the graph, corresponding to the lock on which
* gestures are currently being processed.
*/
private void createTransaction(final GraphWriteMethods wg, final int fromVertex, final int toVertex, final boolean directed) {
Plugin plugin = PluginRegistry.get(InteractiveGraphPluginRegistry.CREATE_TRANSACTION);
PluginParameters parameters = DefaultPluginParameters.getDefaultParameters(plugin);
parameters.getParameters().get(CreateTransactionPlugin.SOURCE_PARAMETER_ID).setObjectValue(fromVertex);
parameters.getParameters().get(CreateTransactionPlugin.DESTINATION_PARAMETER_ID).setObjectValue(toVertex);
parameters.getParameters().get(CreateTransactionPlugin.DIRECTED_PARAMETER_ID).setObjectValue(directed);
try {
PluginExecution.withPlugin(plugin).withParameters(parameters).interactively(false).executeNow(wg);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
} catch (PluginException ex) {
}
announceNextFlush = true;
}
use of au.gov.asd.tac.constellation.plugins.PluginException in project constellation by constellation-app.
the class SaveTemplatePlugin method saveTemplate.
private void saveTemplate(final GraphReadMethods graph, final String templateName) throws PluginException {
final Preferences prefs = NbPreferences.forModule(ApplicationPreferenceKeys.class);
final String userDir = ApplicationPreferenceKeys.getUserDir(prefs);
final File templateDir = new File(userDir, TEMPLATE_DIR);
final File oldTemplate = new File(templateDir, NewSchemaGraphAction.getTemplateNames().get(templateName) + "/" + templateName);
if (oldTemplate.exists()) {
final boolean oldTemplateIsDeleted = oldTemplate.delete();
if (!oldTemplateIsDeleted) {
// TODO: Handle case where file not successfully deleted
}
}
if (!templateDir.exists()) {
templateDir.mkdir();
}
if (!templateDir.isDirectory()) {
final String msg = String.format("Can't create template directory '%s'.", templateDir);
final NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.ERROR_MESSAGE);
DialogDisplayer.getDefault().notify(nd);
return;
}
final File schemaDir = new File(templateDir, graph.getSchema().getFactory().getName());
if (!schemaDir.exists()) {
schemaDir.mkdir();
}
if (!schemaDir.isDirectory()) {
final String msg = String.format("Can't create template directory '%s'.", schemaDir);
final NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.ERROR_MESSAGE);
DialogDisplayer.getDefault().notify(nd);
return;
}
final File saveFile = new File(schemaDir, templateName);
try {
new GraphJsonWriter().writeTemplateToZip(graph, saveFile.getPath(), new HandleIoProgress("Saving Template..."));
} catch (IOException ex) {
throw new PluginException(this, PluginNotificationLevel.ERROR, "Failed to save template", ex);
}
}
use of au.gov.asd.tac.constellation.plugins.PluginException in project constellation by constellation-app.
the class DefaultPluginEnvironmentNGTest method testExecutePluginNowThrowsPluginException.
@Test(expectedExceptions = PluginException.class)
public void testExecutePluginNowThrowsPluginException() throws Exception {
System.out.println("executePluginNow");
Graph graph = mock(Graph.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(PluginGraphs.class), any(PluginInteraction.class), any(PluginParameters.class));
when(pluginException.getNotificationLevel()).thenReturn(PluginNotificationLevel.FATAL);
DefaultPluginEnvironment instance = new DefaultPluginEnvironment();
instance.executePluginNow(graph, plugin, parameters, interactive);
}
use of au.gov.asd.tac.constellation.plugins.PluginException in project constellation by constellation-app.
the class DefaultPluginEnvironmentNGTest method testExecutePluginLaterThrowsPluginException.
@Test
public void testExecutePluginLaterThrowsPluginException() throws ExecutionException, InterruptedException, PluginException {
System.out.println("executePluginLater");
Graph graph = mock(Graph.class);
Plugin plugin = mock(Plugin.class);
PluginParameters parameters = mock(PluginParameters.class);
boolean interactive = false;
PluginSynchronizer synchronizer = mock(PluginSynchronizer.class);
List<Future<?>> async = null;
PluginException pluginException = mock(PluginException.class);
final ExecutorService executorService = mock(ExecutorService.class);
doThrow(pluginException).when(plugin).run(any(PluginGraphs.class), any(PluginInteraction.class), any(PluginParameters.class));
when(pluginException.getNotificationLevel()).thenReturn(PluginNotificationLevel.FATAL);
DefaultPluginEnvironment instance = spy(new DefaultPluginEnvironment());
doReturn(executorService).when(instance).getPluginExecutor();
when(executorService.submit(any(Callable.class))).thenAnswer(iom -> {
final Callable callable = iom.getArgument(0);
callable.call();
return CompletableFuture.completedFuture(null);
});
Object expResult = null;
Future future = instance.executePluginLater(graph, plugin, parameters, interactive, async, synchronizer);
Object result = future.get();
assertEquals(result, expResult);
}
Aggregations