Search in sources :

Example 11 with PluginException

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

the class MiscNGTest method testCreateTransactionToNonexistentDestinationInPluginTest.

@Test
public void testCreateTransactionToNonexistentDestinationInPluginTest() {
    try {
        final DualGraph graph = new DualGraph(null);
        graph.setUndoManager(new UndoRedo.Manager());
        PluginExecution.withPlugin(new SimpleEditPlugin() {

            @Override
            public void edit(final GraphWriteMethods wg, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
                for (int i = 0; i < 10; i++) {
                    final String s = String.format("x%d", i);
                    wg.addAttribute(GraphElementType.VERTEX, ObjectAttributeDescription.ATTRIBUTE_NAME, s, s, 99, null);
                    wg.addAttribute(GraphElementType.TRANSACTION, FloatAttributeDescription.ATTRIBUTE_NAME, s, s, 99, null);
                }
                int vx = 0;
                for (int i = 0; i < 100; i++) {
                    vx = wg.addVertex();
                }
                final int tx = wg.addTransaction(vx, vx + 1, true);
                Assert.fail("Shouldn't get here, wg.addTransaction() should fail.");
                System.out.printf("New transaction: %d\n", tx);
            }

            @Override
            public String getName() {
                return "Build graph + tx failure test";
            }
        }).executeNow(graph);
    } catch (InterruptedException ex) {
        Assert.fail("Nothing was interrupted.");
    } catch (PluginException ex) {
        Assert.fail("There shouldn't be a plugin exception.");
    } catch (RuntimeException ex) {
        final boolean containsIllegalArgumentException = ex.getLocalizedMessage().contains("Attempt to create transaction to destination vertex that does not exist");
        Assert.assertTrue(containsIllegalArgumentException);
    }
}
Also used : GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) SimpleEditPlugin(au.gov.asd.tac.constellation.plugins.templates.SimpleEditPlugin) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) UndoRedo(org.openide.awt.UndoRedo) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) Test(org.testng.annotations.Test)

Example 12 with PluginException

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

the class DefaultPluginEnvironmentNGTest method testExecuteReadPluginNowThrowsPluginException.

@Test(expectedExceptions = PluginException.class)
public void testExecuteReadPluginNowThrowsPluginException() throws Exception {
    System.out.println("executeReadPluginNow");
    GraphReadMethods graph = mock(GraphReadMethods.class);
    Plugin plugin = mock(Plugin.class);
    PluginParameters parameters = mock(PluginParameters.class);
    PluginException pluginException = mock(PluginException.class);
    boolean interactive = false;
    DefaultPluginEnvironment instance = new DefaultPluginEnvironment();
    doThrow(pluginException).when(plugin).run(any(GraphReadMethods.class), any(PluginInteraction.class), any(PluginParameters.class));
    when(pluginException.getNotificationLevel()).thenReturn(PluginNotificationLevel.FATAL);
    instance.executeReadPluginNow(graph, plugin, parameters, interactive);
}
Also used : GraphReadMethods(au.gov.asd.tac.constellation.graph.GraphReadMethods) 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 13 with PluginException

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

the class DefaultPluginEnvironment method executePluginLater.

@Override
public Future<?> executePluginLater(final Graph graph, final Plugin plugin, final PluginParameters parameters, final boolean interactive, final List<Future<?>> async, final PluginSynchronizer synchronizer) {
    if (graph == null) {
        LOGGER.log(Level.INFO, GRAPH_NULL_WARNING_MESSAGE, plugin.getName());
    }
    return getPluginExecutor().submit(() -> {
        Thread.currentThread().setName(THREAD_POOL_NAME);
        // vertices have been relocated is not sensible.
        if (async != null) {
            for (final Future<?> future : async) {
                if (future != null) {
                    try {
                        future.get();
                    } catch (final InterruptedException ex) {
                        LOGGER.log(Level.SEVERE, "Execution interrupted", ex);
                        Thread.currentThread().interrupt();
                    } catch (final ExecutionException ex) {
                        LOGGER.log(Level.SEVERE, "Execution Exception", ex);
                    }
                }
            }
        }
        final ThreadConstraints callingConstraints = ThreadConstraints.getConstraints();
        final boolean alwaysSilent = callingConstraints.isAlwaysSilent() || callingConstraints.getSilentCount() > 0;
        PluginReport currentReport = null;
        final GraphReport graphReport = graph == null ? null : GraphReportManager.getGraphReport(graph.getId());
        if (graphReport != null) {
            currentReport = graphReport.addPluginReport(plugin);
            callingConstraints.setCurrentReport(currentReport);
        }
        try {
            ConstellationLogger.getDefault().pluginStarted(plugin, parameters, graph);
        } catch (final Exception ex) {
            LOGGER.log(Level.SEVERE, ex.getLocalizedMessage());
        }
        final PluginManager manager = new PluginManager(DefaultPluginEnvironment.this, plugin, graph, interactive, synchronizer);
        final PluginGraphs graphs = new DefaultPluginGraphs(manager);
        final PluginInteraction interaction = new DefaultPluginInteraction(manager, currentReport);
        try {
            if (parameters != null) {
                plugin.updateParameters(graph, parameters);
            }
            if (interactive && parameters != null) {
                if (interaction.prompt(plugin.getName(), parameters)) {
                    ThreadConstraints calledConstraints = ThreadConstraints.getConstraints();
                    calledConstraints.setAlwaysSilent(alwaysSilent);
                    try {
                        plugin.run(graphs, interaction, parameters);
                    } finally {
                        calledConstraints.setAlwaysSilent(false);
                        calledConstraints.setSilentCount(0);
                        if (synchronizer != null) {
                            synchronizer.finished();
                        }
                    }
                }
            } else {
                final ThreadConstraints calledConstraints = ThreadConstraints.getConstraints();
                calledConstraints.setAlwaysSilent(alwaysSilent);
                try {
                    plugin.run(graphs, interaction, parameters);
                } finally {
                    calledConstraints.setAlwaysSilent(false);
                    calledConstraints.setSilentCount(0);
                    if (synchronizer != null) {
                        synchronizer.finished();
                    }
                }
            }
        } catch (final InterruptedException ex) {
            auditPluginError(plugin, ex);
            reportException(plugin.getName(), interaction, currentReport, null, ex);
            Thread.currentThread().interrupt();
        } catch (final PluginException ex) {
            auditPluginError(plugin, ex);
            reportException(plugin.getName(), interaction, currentReport, ex.getNotificationLevel(), ex);
        } catch (final Exception ex) {
            auditPluginError(plugin, ex);
            reportException(plugin.getName(), interaction, currentReport, PluginNotificationLevel.ERROR, ex);
        } finally {
            if (currentReport != null) {
                currentReport.stop();
                callingConstraints.setCurrentReport(null);
                currentReport.firePluginReportChangedEvent();
            }
            try {
                ConstellationLogger.getDefault().pluginStopped(plugin, parameters);
            } catch (final Exception ex) {
                LOGGER.log(Level.SEVERE, ex.getLocalizedMessage());
            }
        }
        return null;
    });
}
Also used : PluginGraphs(au.gov.asd.tac.constellation.plugins.PluginGraphs) 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) PluginReport(au.gov.asd.tac.constellation.plugins.reporting.PluginReport) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) ExecutionException(java.util.concurrent.ExecutionException)

Example 14 with PluginException

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

the class DefaultPluginEnvironment method executeEditPluginNow.

@Override
public Object executeEditPluginNow(final GraphWriteMethods 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 15 with PluginException

use of au.gov.asd.tac.constellation.plugins.PluginException 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)

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