Search in sources :

Example 41 with PluginException

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

the class TestParametersPluginNGTest method testQueryException2.

/**
 * Test of query method, of class TestParametersPlugin. Tests throwing of
 * info pluginException
 */
@Test(expectedExceptions = PluginException.class)
public void testQueryException2() throws Exception {
    System.out.println("throw pluginexception2");
    final TestParametersPlugin instance = new TestParametersPlugin();
    final PluginParameters result = instance.createParameters();
    final GraphRecordStore recordStore = new GraphRecordStore();
    final DefaultPluginInteraction interaction = new DefaultPluginInteraction(null, null);
    // Set plugin query name here before execution
    result.getParameters().get(CoreGlobalParameters.QUERY_NAME_PARAMETER_ID).setStringValue("TESTPARAMETERSPLUGIN");
    // Set plugin parameters here before execution
    result.getParameters().get(TestParametersPlugin.LEVEL_PARAMETER_ID).setStringValue("Info");
    try {
        instance.query(recordStore, interaction, result);
    } catch (final PluginException ex) {
        assertEquals(ex.getNotificationLevel(), PluginNotificationLevel.INFO);
        throw ex;
    }
}
Also used : PluginException(au.gov.asd.tac.constellation.plugins.PluginException) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) DefaultPluginInteraction(au.gov.asd.tac.constellation.graph.node.plugins.DefaultPluginInteraction) Test(org.testng.annotations.Test)

Example 42 with PluginException

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

the class CompareGraphPluginNGTest method testReadWithNodesInDifferentOrder.

@Test
public void testReadWithNodesInDifferentOrder() {
    int vx0, vx1, vx2, vx3, tx0;
    int labelAttribute;
    final Schema schema = SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema();
    final StoreGraph originalGraph = new StoreGraph(schema);
    labelAttribute = originalGraph.addAttribute(GraphElementType.VERTEX, StringAttributeDescription.ATTRIBUTE_NAME, "Name", "", "", null);
    originalGraph.setPrimaryKey(GraphElementType.VERTEX, labelAttribute);
    vx0 = originalGraph.addVertex();
    vx1 = originalGraph.addVertex();
    vx2 = originalGraph.addVertex();
    vx3 = originalGraph.addVertex();
    tx0 = originalGraph.addTransaction(vx0, vx1, true);
    originalGraph.setStringValue(labelAttribute, vx0, "vx0");
    originalGraph.setStringValue(labelAttribute, vx1, "vx1");
    originalGraph.setStringValue(labelAttribute, vx2, "vx2");
    originalGraph.setStringValue(labelAttribute, vx3, "vx3");
    final StoreGraph compareGraph = new StoreGraph(schema);
    labelAttribute = compareGraph.addAttribute(GraphElementType.VERTEX, StringAttributeDescription.ATTRIBUTE_NAME, "Name", "", "", null);
    compareGraph.setPrimaryKey(GraphElementType.VERTEX, labelAttribute);
    vx0 = compareGraph.addVertex();
    vx1 = compareGraph.addVertex();
    vx2 = compareGraph.addVertex();
    vx3 = compareGraph.addVertex();
    tx0 = compareGraph.addTransaction(vx3, vx2, true);
    compareGraph.setStringValue(labelAttribute, vx0, "vx3");
    compareGraph.setStringValue(labelAttribute, vx1, "vx2");
    compareGraph.setStringValue(labelAttribute, vx2, "vx1");
    compareGraph.setStringValue(labelAttribute, vx3, "vx0");
    final GraphRecordStore originalAll = GraphRecordStoreUtilities.getAll(originalGraph, false, true);
    final GraphRecordStore compareAll = GraphRecordStoreUtilities.getAll(compareGraph, false, true);
    final Set<String> vertexPrimaryKeys = PrimaryKeyUtilities.getPrimaryKeyNames(originalGraph, GraphElementType.VERTEX);
    final Set<String> transactionPrimaryKeys = PrimaryKeyUtilities.getPrimaryKeyNames(originalGraph, GraphElementType.TRANSACTION);
    final List<String> ignoreVertexAttributes = new ArrayList<>();
    final List<String> ignoreTransactionAttributes = new ArrayList<>();
    ignoreVertexAttributes.add("[id]");
    ignoreTransactionAttributes.add("[id]");
    // debug
    System.out.println("originalAll ==>\n" + originalAll.toStringVerbose());
    System.out.println("compareAll ==>\n" + compareAll.toStringVerbose());
    final CompareGraphPlugin instance = new CompareGraphPlugin();
    GraphRecordStore changes = new GraphRecordStore();
    try {
        changes = instance.compareGraphs("", originalAll, compareAll, vertexPrimaryKeys, transactionPrimaryKeys, ignoreVertexAttributes, ignoreTransactionAttributes, ADDED_COLOUR, REMOVED_COLOUR, CHANGED_COLOUR, UNCHANGED_COLOUR);
        System.out.println("changes ==>\n" + changes.toStringVerbose());
        assertEquals(changes.size(), 5);
    } catch (PluginException ex) {
        Assert.fail(ex.getLocalizedMessage());
    }
    try {
        final Graph finalGraph = instance.createComparisonGraph(new DualGraph(originalGraph, true), changes);
    } catch (InterruptedException ex) {
        Assert.fail(ex.getLocalizedMessage());
    }
}
Also used : Schema(au.gov.asd.tac.constellation.graph.schema.Schema) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) ArrayList(java.util.ArrayList) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Test(org.testng.annotations.Test)

Example 43 with PluginException

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

the class CompareGraphPluginNGTest method testReadWithTransactionsInBothDirections.

@Test
public void testReadWithTransactionsInBothDirections() {
    int vx0, vx1, vx2, vx3, tx0, tx1;
    int labelAttribute;
    final Schema schema = SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema();
    final StoreGraph originalGraph = new StoreGraph(schema);
    labelAttribute = VisualConcept.VertexAttribute.LABEL.ensure(originalGraph);
    originalGraph.setPrimaryKey(GraphElementType.VERTEX, labelAttribute);
    vx0 = originalGraph.addVertex();
    vx1 = originalGraph.addVertex();
    vx2 = originalGraph.addVertex();
    vx3 = originalGraph.addVertex();
    tx0 = originalGraph.addTransaction(vx0, vx1, true);
    tx1 = originalGraph.addTransaction(vx1, vx2, true);
    originalGraph.setStringValue(labelAttribute, vx0, "vx0");
    originalGraph.setStringValue(labelAttribute, vx1, "vx1");
    originalGraph.setStringValue(labelAttribute, vx2, "vx2");
    originalGraph.setStringValue(labelAttribute, vx3, "vx3");
    final StoreGraph compareGraph = new StoreGraph(schema);
    labelAttribute = VisualConcept.VertexAttribute.LABEL.ensure(compareGraph);
    compareGraph.setPrimaryKey(GraphElementType.VERTEX, labelAttribute);
    vx0 = compareGraph.addVertex();
    vx1 = compareGraph.addVertex();
    vx2 = compareGraph.addVertex();
    vx3 = compareGraph.addVertex();
    tx0 = compareGraph.addTransaction(vx0, vx1, true);
    // this is the change
    tx1 = compareGraph.addTransaction(vx2, vx1, true);
    compareGraph.setStringValue(labelAttribute, vx0, "vx0");
    compareGraph.setStringValue(labelAttribute, vx1, "vx1");
    compareGraph.setStringValue(labelAttribute, vx2, "vx2");
    compareGraph.setStringValue(labelAttribute, vx3, "vx3");
    final GraphRecordStore originalAll = GraphRecordStoreUtilities.getAll(originalGraph, false, true);
    final GraphRecordStore compareAll = GraphRecordStoreUtilities.getAll(compareGraph, false, true);
    final Set<String> vertexPrimaryKeys = PrimaryKeyUtilities.getPrimaryKeyNames(originalGraph, GraphElementType.VERTEX);
    final Set<String> transactionPrimaryKeys = PrimaryKeyUtilities.getPrimaryKeyNames(originalGraph, GraphElementType.TRANSACTION);
    final List<String> ignoreVertexAttributes = new ArrayList<>();
    final List<String> ignoreTransactionAttributes = new ArrayList<>();
    ignoreVertexAttributes.add("[id]");
    ignoreTransactionAttributes.add("[id]");
    // debug
    System.out.println("originalAll ==>\n" + originalAll.toStringVerbose());
    System.out.println("compareAll ==>\n" + compareAll.toStringVerbose());
    final CompareGraphPlugin instance = new CompareGraphPlugin();
    GraphRecordStore changes = new GraphRecordStore();
    try {
        changes = instance.compareGraphs("", originalAll, compareAll, vertexPrimaryKeys, transactionPrimaryKeys, ignoreVertexAttributes, ignoreTransactionAttributes, ADDED_COLOUR, REMOVED_COLOUR, CHANGED_COLOUR, UNCHANGED_COLOUR);
        System.out.println("changes ==>\n" + changes.toStringVerbose());
        assertEquals(changes.size(), 7);
    } catch (PluginException ex) {
        Assert.fail(ex.getLocalizedMessage());
    }
    changes.reset();
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL), "vx0");
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.UNCHANGED);
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL), "vx1");
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.UNCHANGED);
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL), "vx2");
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.UNCHANGED);
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL), "vx3");
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.UNCHANGED);
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL), "vx0");
    assertEquals(changes.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.LABEL), "vx1");
    assertEquals(changes.get(GraphRecordStoreUtilities.TRANSACTION + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.UNCHANGED);
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL), "vx1");
    assertEquals(changes.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.LABEL), "vx2");
    assertEquals(changes.get(GraphRecordStoreUtilities.TRANSACTION + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.REMOVED);
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL), "vx2");
    assertEquals(changes.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.LABEL), "vx1");
    assertEquals(changes.get(GraphRecordStoreUtilities.TRANSACTION + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.ADDED);
    try {
        final Graph finalGraph = instance.createComparisonGraph(new DualGraph(originalGraph, true), changes);
        SaveGraphUtilities.saveGraphToTemporaryDirectory(finalGraph, "testReadWithTransactionsInBothDirections", true);
    } catch (InterruptedException | IOException ex) {
        Assert.fail(ex.getLocalizedMessage());
    }
}
Also used : Schema(au.gov.asd.tac.constellation.graph.schema.Schema) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Test(org.testng.annotations.Test)

Example 44 with PluginException

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

the class CompareGraphPluginNGTest method testReadWithMultipleChangesToVerticies.

@Test
public void testReadWithMultipleChangesToVerticies() {
    int vx0, vx1, vx2, vx3, vx4, vx5, tx0, tx1, tx2;
    int labelAttribute, fooAttribute, lineStyleAttribute;
    final Schema schema = SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema();
    final StoreGraph originalGraph = new StoreGraph(schema);
    labelAttribute = originalGraph.addAttribute(GraphElementType.VERTEX, StringAttributeDescription.ATTRIBUTE_NAME, "Label", "", "", null);
    lineStyleAttribute = VisualConcept.TransactionAttribute.LINE_STYLE.ensure(originalGraph);
    fooAttribute = originalGraph.addAttribute(GraphElementType.VERTEX, StringAttributeDescription.ATTRIBUTE_NAME, "foo", "", "", null);
    originalGraph.setPrimaryKey(GraphElementType.VERTEX, labelAttribute);
    originalGraph.setPrimaryKey(GraphElementType.TRANSACTION, lineStyleAttribute);
    vx0 = originalGraph.addVertex();
    vx1 = originalGraph.addVertex();
    vx2 = originalGraph.addVertex();
    vx3 = originalGraph.addVertex();
    vx4 = originalGraph.addVertex();
    tx0 = originalGraph.addTransaction(vx0, vx1, true);
    tx1 = originalGraph.addTransaction(vx0, vx4, true);
    originalGraph.setStringValue(labelAttribute, vx0, "vx0");
    originalGraph.setStringValue(labelAttribute, vx1, "vx1");
    originalGraph.setStringValue(labelAttribute, vx2, "vx2");
    originalGraph.setStringValue(labelAttribute, vx3, "vx3");
    originalGraph.setStringValue(labelAttribute, vx4, "vx4");
    final StoreGraph compareGraph = new StoreGraph(schema);
    labelAttribute = compareGraph.addAttribute(GraphElementType.VERTEX, StringAttributeDescription.ATTRIBUTE_NAME, "Label", "", "", null);
    fooAttribute = compareGraph.addAttribute(GraphElementType.VERTEX, StringAttributeDescription.ATTRIBUTE_NAME, "foo", "", "", null);
    lineStyleAttribute = VisualConcept.TransactionAttribute.LINE_STYLE.ensure(compareGraph);
    compareGraph.setPrimaryKey(GraphElementType.VERTEX, labelAttribute);
    compareGraph.setPrimaryKey(GraphElementType.TRANSACTION, lineStyleAttribute);
    vx0 = compareGraph.addVertex();
    vx1 = compareGraph.addVertex();
    vx2 = compareGraph.addVertex();
    // vx3 = compareGraph.addVertex();
    vx4 = compareGraph.addVertex();
    vx5 = compareGraph.addVertex();
    tx0 = compareGraph.addTransaction(vx0, vx1, true);
    // tx1 = originalGraph.addTransaction(vx0, vx4, true); // # change is REMOVE
    // # change is ADDED
    tx2 = compareGraph.addTransaction(vx0, vx5, true);
    compareGraph.setStringValue(labelAttribute, vx0, "vx0");
    compareGraph.setStringValue(labelAttribute, vx1, "vx1");
    compareGraph.setStringValue(labelAttribute, vx2, "vx2");
    // compareGraph.setStringValue(labelAttribute, vx3, "vx3"); // # change is REMOVE
    compareGraph.setStringValue(labelAttribute, vx4, "vx4");
    // # change is CHANGE
    compareGraph.setStringValue(fooAttribute, vx4, "bar");
    // # change is ADDED
    compareGraph.setStringValue(labelAttribute, vx5, "vx5");
    final GraphRecordStore originalAll = GraphRecordStoreUtilities.getAll(originalGraph, false, true);
    final GraphRecordStore compareAll = GraphRecordStoreUtilities.getAll(compareGraph, false, true);
    final Set<String> vertexPrimaryKeys = PrimaryKeyUtilities.getPrimaryKeyNames(originalGraph, GraphElementType.VERTEX);
    final Set<String> transactionPrimaryKeys = PrimaryKeyUtilities.getPrimaryKeyNames(originalGraph, GraphElementType.TRANSACTION);
    final List<String> ignoreVertexAttributes = new ArrayList<>();
    ignoreVertexAttributes.add("[id]");
    final List<String> ignoreTransactionAttributes = new ArrayList<>();
    ignoreTransactionAttributes.add("[id]");
    // debug
    System.out.println("originalAll ==>\n" + originalAll.toStringVerbose());
    System.out.println("compareAll ==>\n" + compareAll.toStringVerbose());
    final CompareGraphPlugin instance = new CompareGraphPlugin();
    Graph finalGraph = null;
    GraphRecordStore changes = new GraphRecordStore();
    try {
        changes = instance.compareGraphs("", originalAll, compareAll, vertexPrimaryKeys, transactionPrimaryKeys, ignoreVertexAttributes, ignoreTransactionAttributes, ADDED_COLOUR, REMOVED_COLOUR, CHANGED_COLOUR, UNCHANGED_COLOUR);
        System.out.println("changes ==>\n" + changes.toStringVerbose());
        assertEquals(changes.size(), 9);
        finalGraph = instance.createComparisonGraph(new DualGraph(originalGraph, true), changes);
    } catch (InterruptedException | PluginException ex) {
        Assert.fail(ex.getLocalizedMessage());
    }
    changes.reset();
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL), "vx0");
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.UNCHANGED);
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL), "vx1");
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.UNCHANGED);
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL), "vx2");
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.UNCHANGED);
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL), "vx3");
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.REMOVED);
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL), "vx4");
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.CHANGED);
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL), "vx0");
    assertEquals(changes.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.LABEL), "vx1");
    assertEquals(changes.get(GraphRecordStoreUtilities.TRANSACTION + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.UNCHANGED);
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL), "vx0");
    assertEquals(changes.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.LABEL), "vx4");
    assertEquals(changes.get(GraphRecordStoreUtilities.TRANSACTION + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.REMOVED);
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL), "vx5");
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.ADDED);
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL), "vx0");
    assertEquals(changes.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.LABEL), "vx5");
    assertEquals(changes.get(GraphRecordStoreUtilities.TRANSACTION + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.ADDED);
    final ReadableGraph rg = finalGraph.getReadableGraph();
    try {
        int vxCount = rg.getVertexCount();
        int txCount = rg.getTransactionCount();
        assertEquals(vxCount, 6);
        assertEquals(txCount, 3);
    } finally {
        rg.release();
    }
    try {
        SaveGraphUtilities.saveGraphToTemporaryDirectory(originalGraph, "originalGraph");
        SaveGraphUtilities.saveGraphToTemporaryDirectory(compareGraph, "compareGraph");
        SaveGraphUtilities.saveGraphToTemporaryDirectory(finalGraph, "finalGraph", true);
    } catch (IOException | InterruptedException ex) {
        Assert.fail(ex.getLocalizedMessage());
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Schema(au.gov.asd.tac.constellation.graph.schema.Schema) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Test(org.testng.annotations.Test)

Example 45 with PluginException

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

the class DefaultPluginEnvironment method executePluginNow.

@Override
public Object executePluginNow(final Graph 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 PluginGraphs graphs = new DefaultPluginGraphs(manager);
    final PluginInteraction interaction = new DefaultPluginInteraction(manager, currentReport);
    try {
        ConstellationLogger.getDefault().pluginStarted(plugin, parameters, graph);
    } catch (final Exception ex) {
        LOGGER.log(Level.SEVERE, ex.getLocalizedMessage());
    }
    try {
        if (parameters != null) {
            plugin.updateParameters(graph, parameters);
        }
        if (interactive && parameters != null) {
            if (interaction.prompt(plugin.getName(), parameters)) {
                plugin.run(graphs, interaction, parameters);
            }
        } else {
            plugin.run(graphs, 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 : 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)

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