Search in sources :

Example 46 with PluginException

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;
}
Also used : PluginReport(au.gov.asd.tac.constellation.plugins.reporting.PluginReport) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) GraphReport(au.gov.asd.tac.constellation.plugins.reporting.GraphReport) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) ExecutionException(java.util.concurrent.ExecutionException)

Example 47 with PluginException

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;
}
Also used : PluginException(au.gov.asd.tac.constellation.plugins.PluginException) DefaultPluginParameters(au.gov.asd.tac.constellation.plugins.parameters.DefaultPluginParameters) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PointSelectionPlugin(au.gov.asd.tac.constellation.graph.interaction.plugins.select.PointSelectionPlugin) BoxSelectionPlugin(au.gov.asd.tac.constellation.graph.interaction.plugins.select.BoxSelectionPlugin) CreateTransactionPlugin(au.gov.asd.tac.constellation.graph.interaction.plugins.draw.CreateTransactionPlugin) FreeformSelectionPlugin(au.gov.asd.tac.constellation.graph.interaction.plugins.select.FreeformSelectionPlugin) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) CreateVertexPlugin(au.gov.asd.tac.constellation.graph.interaction.plugins.draw.CreateVertexPlugin) SimplePlugin(au.gov.asd.tac.constellation.plugins.templates.SimplePlugin)

Example 48 with PluginException

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);
    }
}
Also used : NotifyDescriptor(org.openide.NotifyDescriptor) GraphJsonWriter(au.gov.asd.tac.constellation.graph.file.io.GraphJsonWriter) HandleIoProgress(au.gov.asd.tac.constellation.utilities.gui.HandleIoProgress) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) IOException(java.io.IOException) Preferences(java.util.prefs.Preferences) NbPreferences(org.openide.util.NbPreferences) File(java.io.File)

Example 49 with PluginException

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);
}
Also used : Graph(au.gov.asd.tac.constellation.graph.Graph) PluginGraphs(au.gov.asd.tac.constellation.plugins.PluginGraphs) 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 50 with PluginException

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);
}
Also used : PluginSynchronizer(au.gov.asd.tac.constellation.plugins.PluginSynchronizer) PluginGraphs(au.gov.asd.tac.constellation.plugins.PluginGraphs) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) Callable(java.util.concurrent.Callable) Graph(au.gov.asd.tac.constellation.graph.Graph) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) ExecutorService(java.util.concurrent.ExecutorService) CompletableFuture(java.util.concurrent.CompletableFuture) Future(java.util.concurrent.Future) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) Test(org.testng.annotations.Test)

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