Search in sources :

Example 6 with PluginException

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

the class CompareGraphPlugin method read.

@Override
protected void read(final GraphReadMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
    final String originalGraphName = parameters.getParameters().get(ORIGINAL_GRAPH_PARAMETER_ID).getStringValue();
    final String compareGraphName = parameters.getParameters().get(COMPARE_GRAPH_PARAMETER_ID).getStringValue();
    if (originalGraphName == null || compareGraphName == null) {
        throw new PluginException(PluginNotificationLevel.ERROR, "You must choose two graphs to compare");
    }
    final List<String> ignoreVertexAttributes = new ArrayList<>(parameters.getParameters().get(IGNORE_VERTEX_ATTRIBUTES_PARAMETER_ID).getMultiChoiceValue().getChoices());
    final List<String> ignoreTransactionAttributes = new ArrayList<>(parameters.getParameters().get(IGNORE_TRANSACTION_ATTRIBUTES_PARAMETER_ID).getMultiChoiceValue().getChoices());
    final ConstellationColor addedColour = parameters.getParameters().get(ADDED_COLOUR_PARAMETER_ID).getColorValue();
    final ConstellationColor removedColour = parameters.getParameters().get(REMOVED_COLOUR_PARAMETER_ID).getColorValue();
    final ConstellationColor changedColour = parameters.getParameters().get(CHANGED_COLOUR_PARAMETER_ID).getColorValue();
    final ConstellationColor unchangedColour = parameters.getParameters().get(UNCHANGED_COLOUR_PARAMETER_ID).getColorValue();
    final ConstellationColor addedColourValue = ConstellationColor.getColorValue(addedColour.getRed(), addedColour.getGreen(), addedColour.getBlue(), ConstellationColor.ZERO_ALPHA);
    final ConstellationColor removedColourValue = ConstellationColor.getColorValue(removedColour.getRed(), removedColour.getGreen(), removedColour.getBlue(), ConstellationColor.ZERO_ALPHA);
    final ConstellationColor changedColourValue = ConstellationColor.getColorValue(changedColour.getRed(), changedColour.getGreen(), changedColour.getBlue(), ConstellationColor.ZERO_ALPHA);
    final ConstellationColor unchangedColourValue = ConstellationColor.getColorValue(unchangedColour.getRed(), unchangedColour.getGreen(), unchangedColour.getBlue(), ConstellationColor.ZERO_ALPHA);
    final Graph originalGraph = getGraphFromName(originalGraphName);
    final Graph compareGraph = getGraphFromName(compareGraphName);
    if (originalGraph == null) {
        throw new PluginException(PluginNotificationLevel.ERROR, String.format(GRAPH_NOT_FOUND_ERROR, originalGraphName));
    }
    if (compareGraph == null) {
        throw new PluginException(PluginNotificationLevel.ERROR, String.format(GRAPH_NOT_FOUND_ERROR, compareGraphName));
    }
    final GraphRecordStore originalAll;
    final GraphRecordStore compareAll;
    final Set<String> vertexPrimaryKeys;
    final Set<String> transactionPrimaryKeys;
    // get a copy of the graph's record store and statistical info
    ReadableGraph rg = originalGraph.getReadableGraph();
    try {
        originalAll = GraphRecordStoreUtilities.getAll(rg, false, true);
        vertexPrimaryKeys = PrimaryKeyUtilities.getPrimaryKeyNames(rg, GraphElementType.VERTEX);
        transactionPrimaryKeys = PrimaryKeyUtilities.getPrimaryKeyNames(rg, GraphElementType.TRANSACTION);
    } finally {
        rg.release();
    }
    rg = compareGraph.getReadableGraph();
    try {
        compareAll = GraphRecordStoreUtilities.getAll(rg, false, true);
    } finally {
        rg.release();
    }
    // ignore the id attributes to avoid reporting on them
    ignoreVertexAttributes.add("[id]");
    ignoreTransactionAttributes.add("[id]");
    // graph changes
    final String title = String.format("Compare: %s <> %s", originalGraphName, compareGraphName);
    final GraphRecordStore changes = compareGraphs(title, originalAll, compareAll, vertexPrimaryKeys, transactionPrimaryKeys, ignoreVertexAttributes, ignoreTransactionAttributes, addedColourValue, removedColourValue, changedColourValue, unchangedColourValue);
    // create new graph
    createComparisonGraph(originalGraph, changes);
    interaction.setProgress(1, 0, changes + " changes were found.", true);
}
Also used : ConstellationColor(au.gov.asd.tac.constellation.utilities.color.ConstellationColor) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) ArrayList(java.util.ArrayList) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore)

Example 7 with PluginException

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

the class CompareGraphPlugin method createComparisonGraph.

/**
 * Create the comparison graph using the original graph as the starting
 * point and add the result record store
 *
 * @param originalGraph
 * @param changes
 * @param initializeWithSchema
 * @param completeWithSchema
 * @return
 * @throws InterruptedException
 */
protected Graph createComparisonGraph(final Graph originalGraph, final GraphRecordStore changes) throws InterruptedException {
    Graph copy;
    final ReadableGraph rg = originalGraph.getReadableGraph();
    try {
        try {
            final Plugin copyGraphPlugin = PluginRegistry.get(InteractiveGraphPluginRegistry.COPY_TO_NEW_GRAPH);
            final PluginParameters copyParams = copyGraphPlugin.createParameters();
            copyParams.getParameters().get(CopyToNewGraphPlugin.COPY_ALL_PARAMETER_ID).setBooleanValue(true);
            PluginExecution.withPlugin(copyGraphPlugin).withParameters(copyParams).executeNow(rg);
            copy = (Graph) copyParams.getParameters().get(CopyToNewGraphPlugin.NEW_GRAPH_OUTPUT_PARAMETER_ID).getObjectValue();
        } catch (final PluginException ex) {
            copy = null;
            LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
        }
        if (copy == null) {
            // The copy failed, drop out now.
            return null;
        }
    } finally {
        rg.release();
    }
    final List<String> vertexIdAttributes = new ArrayList<>();
    vertexIdAttributes.add(VisualConcept.VertexAttribute.LABEL.getName() + "<string>");
    final WritableGraph wgcopy = copy.getWritableGraph("Add changes", true);
    try {
        changes.reset();
        GraphRecordStoreUtilities.addRecordStoreToGraph(wgcopy, changes, false, false, null);
        final int vertexColorReferenceAttribute = VisualConcept.GraphAttribute.NODE_COLOR_REFERENCE.ensure(wgcopy);
        final int transactionColorReferenceAttribute = VisualConcept.GraphAttribute.TRANSACTION_COLOR_REFERENCE.ensure(wgcopy);
        wgcopy.setObjectValue(vertexColorReferenceAttribute, 0, VisualConcept.VertexAttribute.OVERLAY_COLOR.getName());
        wgcopy.setObjectValue(transactionColorReferenceAttribute, 0, VisualConcept.TransactionAttribute.OVERLAY_COLOR.getName());
    } finally {
        wgcopy.commit();
    }
    // only returning this so that this method can be tested
    return copy;
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) ArrayList(java.util.ArrayList) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) CopyToNewGraphPlugin(au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.CopyToNewGraphPlugin) SimpleReadPlugin(au.gov.asd.tac.constellation.plugins.templates.SimpleReadPlugin) Plugin(au.gov.asd.tac.constellation.plugins.Plugin)

Example 8 with PluginException

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

the class CompareGraphPluginNGTest method testReadWithDuplicateGraphScenarioInReverse.

// @Test(expectedExceptions = DuplicateKeyException.class)
@Test
public void testReadWithDuplicateGraphScenarioInReverse() throws InterruptedException {
    int vx0, vx1, vx2, tx0, tx1;
    int identifierAttribute, vertexTypeAttribute, uniqueIdAttribute, transactionTypeAttribute, transactionDateTimeAttribute;
    final Schema schema = SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema();
    final StoreGraph originalGraph = new StoreGraph(schema);
    identifierAttribute = VisualConcept.VertexAttribute.IDENTIFIER.ensure(originalGraph);
    vertexTypeAttribute = AnalyticConcept.VertexAttribute.TYPE.ensure(originalGraph);
    uniqueIdAttribute = VisualConcept.TransactionAttribute.IDENTIFIER.ensure(originalGraph);
    transactionTypeAttribute = AnalyticConcept.TransactionAttribute.TYPE.ensure(originalGraph);
    transactionDateTimeAttribute = TemporalConcept.TransactionAttribute.DATETIME.ensure(originalGraph);
    originalGraph.setPrimaryKey(GraphElementType.VERTEX, identifierAttribute, vertexTypeAttribute);
    originalGraph.setPrimaryKey(GraphElementType.TRANSACTION, uniqueIdAttribute, transactionTypeAttribute, transactionDateTimeAttribute);
    originalGraph.validateKeys();
    vx0 = originalGraph.addVertex();
    vx1 = originalGraph.addVertex();
    vx2 = originalGraph.addVertex();
    tx0 = originalGraph.addTransaction(vx0, vx1, true);
    tx1 = originalGraph.addTransaction(vx1, vx2, true);
    originalGraph.setStringValue(identifierAttribute, vx0, "Vertex #0");
    originalGraph.setStringValue(identifierAttribute, vx1, "Vertex #1");
    // mimic creating nodes on visual schema which will create a DuplicateKeyException - i.e. this is a known issue
    originalGraph.setStringValue(identifierAttribute, vx2, "Vertex #2");
    originalGraph.setStringValue(vertexTypeAttribute, vx0, "Unknown");
    originalGraph.setStringValue(vertexTypeAttribute, vx1, "Unknown");
    originalGraph.setStringValue(vertexTypeAttribute, vx2, "Unknown");
    Graph compareGraph;
    GraphRecordStore compareAll;
    try {
        final Plugin copyGraphPlugin = PluginRegistry.get(InteractiveGraphPluginRegistry.COPY_TO_NEW_GRAPH);
        final PluginParameters copyGraphParams = copyGraphPlugin.createParameters();
        PluginExecution.withPlugin(copyGraphPlugin).withParameters(copyGraphParams).executeNow((GraphReadMethods) originalGraph);
        compareGraph = (Graph) copyGraphParams.getParameters().get(CopyToNewGraphPlugin.NEW_GRAPH_OUTPUT_PARAMETER_ID).getObjectValue();
    } catch (PluginException ex) {
        compareGraph = null;
        Assert.fail(ex.getLocalizedMessage());
    }
    final WritableGraph wg = compareGraph.getWritableGraph("remove a node", true);
    try {
        Assert.assertEquals(wg.getVertexCount(), 3);
        wg.removeVertex(vx1);
        Assert.assertEquals(wg.getVertexCount(), 2);
    } finally {
        wg.commit();
    }
    final ReadableGraph rg = compareGraph.getReadableGraph();
    try {
        compareAll = GraphRecordStoreUtilities.getAll(rg, false, true);
    } finally {
        rg.release();
    }
    final GraphRecordStore originalAll = GraphRecordStoreUtilities.getAll(originalGraph, false, true);
    Set<String> vertexPrimaryKeys = null;
    Set<String> transactionPrimaryKeys = null;
    final ReadableGraph rg2 = compareGraph.getReadableGraph();
    try {
        vertexPrimaryKeys = PrimaryKeyUtilities.getPrimaryKeyNames(rg2, GraphElementType.VERTEX);
        transactionPrimaryKeys = PrimaryKeyUtilities.getPrimaryKeyNames(rg2, GraphElementType.TRANSACTION);
    } finally {
        rg2.release();
    }
    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();
    Graph finalGraph = null;
    GraphRecordStore changes = new GraphRecordStore();
    try {
        changes = instance.compareGraphs("", compareAll, originalAll, vertexPrimaryKeys, transactionPrimaryKeys, ignoreVertexAttributes, ignoreTransactionAttributes, ADDED_COLOUR, REMOVED_COLOUR, CHANGED_COLOUR, UNCHANGED_COLOUR);
        System.out.println("changes ==>\n" + changes.toStringVerbose());
        // assertEquals(changes.size(), 3);
        finalGraph = instance.createComparisonGraph(compareGraph, changes);
    } catch (InterruptedException | PluginException ex) {
        Assert.fail(ex.getLocalizedMessage());
    }
    // }
    try {
        SaveGraphUtilities.saveGraphToTemporaryDirectory(originalGraph, "originalGraph");
        SaveGraphUtilities.saveGraphToTemporaryDirectory(compareGraph, "compareGraph", true);
        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) 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) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) CopyToNewGraphPlugin(au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.CopyToNewGraphPlugin) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) Test(org.testng.annotations.Test)

Example 9 with PluginException

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

the class CompareGraphPluginNGTest method testReadWithDuplicateGraphScenario.

@Test
public void testReadWithDuplicateGraphScenario() throws InterruptedException {
    int vx0, vx1, vx2, tx0, tx1;
    int identifierAttribute, typeAttribute, uniqueIdAttribute;
    final Schema schema = SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema();
    final StoreGraph originalGraph = new StoreGraph(schema);
    identifierAttribute = VisualConcept.VertexAttribute.IDENTIFIER.ensure(originalGraph);
    // typeAttribute = AnalyticConcept.VertexAttribute.TYPE.ensure(originalGraph);
    uniqueIdAttribute = VisualConcept.TransactionAttribute.IDENTIFIER.ensure(originalGraph);
    originalGraph.setPrimaryKey(GraphElementType.VERTEX, identifierAttribute);
    originalGraph.setPrimaryKey(GraphElementType.TRANSACTION, uniqueIdAttribute);
    vx0 = originalGraph.addVertex();
    vx1 = originalGraph.addVertex();
    vx2 = originalGraph.addVertex();
    tx0 = originalGraph.addTransaction(vx0, vx1, true);
    tx1 = originalGraph.addTransaction(vx1, vx2, true);
    originalGraph.setStringValue(identifierAttribute, vx0, "vx0");
    originalGraph.setStringValue(identifierAttribute, vx1, "vx1");
    originalGraph.setStringValue(identifierAttribute, vx2, "vx2");
    Graph compareGraph;
    GraphRecordStore compareAll;
    try {
        final Plugin copyGraphPlugin = PluginRegistry.get(InteractiveGraphPluginRegistry.COPY_TO_NEW_GRAPH);
        final PluginParameters copyParams = copyGraphPlugin.createParameters();
        copyParams.getParameters().get(CopyToNewGraphPlugin.COPY_ALL_PARAMETER_ID).setBooleanValue(true);
        PluginExecution.withPlugin(copyGraphPlugin).withParameters(copyParams).executeNow((GraphReadMethods) originalGraph);
        compareGraph = (Graph) copyParams.getParameters().get(CopyToNewGraphPlugin.NEW_GRAPH_OUTPUT_PARAMETER_ID).getObjectValue();
    } catch (PluginException ex) {
        compareGraph = null;
        Assert.fail(ex.getLocalizedMessage());
    }
    final WritableGraph wg = compareGraph.getWritableGraph("remove a node", true);
    try {
        Assert.assertEquals(wg.getVertexCount(), 3);
        Assert.assertEquals(wg.getTransactionCount(), 2);
        wg.removeVertex(vx1);
        Assert.assertEquals(wg.getVertexCount(), 2);
        Assert.assertEquals(wg.getTransactionCount(), 0);
    } finally {
        wg.commit();
    }
    ReadableGraph rg = compareGraph.getReadableGraph();
    try {
        compareAll = GraphRecordStoreUtilities.getAll(rg, false, true);
    } finally {
        rg.release();
    }
    final GraphRecordStore originalAll = GraphRecordStoreUtilities.getAll(originalGraph, 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();
    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(), 5);
        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.IDENTIFIER), "vx0");
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.UNCHANGED);
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.IDENTIFIER), "vx1");
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.REMOVED);
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.IDENTIFIER), "vx2");
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.UNCHANGED);
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.IDENTIFIER), "vx0");
    assertEquals(changes.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.IDENTIFIER), "vx1");
    assertEquals(changes.get(GraphRecordStoreUtilities.TRANSACTION + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.REMOVED);
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.IDENTIFIER), "vx1");
    assertEquals(changes.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.IDENTIFIER), "vx2");
    assertEquals(changes.get(GraphRecordStoreUtilities.TRANSACTION + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.REMOVED);
    rg = finalGraph.getReadableGraph();
    try {
        int vxCount = rg.getVertexCount();
        int txCount = rg.getTransactionCount();
        assertEquals(vxCount, 3);
        assertEquals(txCount, 2);
    } finally {
        rg.release();
    }
    try {
        SaveGraphUtilities.saveGraphToTemporaryDirectory(originalGraph, "originalGraph");
        SaveGraphUtilities.saveGraphToTemporaryDirectory(compareGraph, "compareGraph", true);
        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) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) CopyToNewGraphPlugin(au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.CopyToNewGraphPlugin) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) Test(org.testng.annotations.Test)

Example 10 with PluginException

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

the class SaveTemplateAction method actionPerformed.

@Override
public void actionPerformed(final ActionEvent e) {
    final Plugin plugin = PluginRegistry.get(GraphNodePluginRegistry.SAVE_TEMPLATE);
    final PluginParameters params = plugin.createParameters();
    while (true) {
        final PluginParametersSwingDialog dialog = new PluginParametersSwingDialog(Bundle.CTL_SaveTemplateAction(), params);
        dialog.showAndWait();
        if (PluginParametersDialog.OK.equals(dialog.getResult())) {
            if (NewSchemaGraphAction.getTemplateNames().containsKey(params.getStringValue(SaveTemplatePlugin.TEMPLATE_NAME_PARAMETER_ID))) {
                final PluginParameters warningParams = new PluginParameters();
                final PluginParameter<StringParameterValue> warningMessageParam = StringParameterType.build("");
                warningMessageParam.setName("");
                warningMessageParam.setStringValue("Warning template with that name already exists - really overwrite?");
                StringParameterType.setIsLabel(warningMessageParam, true);
                warningParams.addParameter(warningMessageParam);
                final PluginParametersSwingDialog overwrite = new PluginParametersSwingDialog("Overwrite?", warningParams);
                overwrite.showAndWait();
                if (!PluginParametersDialog.OK.equals(overwrite.getResult())) {
                    continue;
                }
            }
            Future<?> f = PluginExecution.withPlugin(plugin).withParameters(params).executeLater(context.getGraph());
            PluginExecution.withPlugin(new SimplePlugin() {

                @Override
                public String getName() {
                    return "Update Template Menu";
                }

                @Override
                protected void execute(final PluginGraphs graphs, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
                    NewSchemaGraphAction.recreateTemplateMenuItems();
                }
            }).waitingFor(f).executeLater(null);
        }
        break;
    }
}
Also used : PluginGraphs(au.gov.asd.tac.constellation.plugins.PluginGraphs) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) StringParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.StringParameterValue) PluginParametersSwingDialog(au.gov.asd.tac.constellation.plugins.gui.PluginParametersSwingDialog) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) SimplePlugin(au.gov.asd.tac.constellation.plugins.templates.SimplePlugin) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) SimplePlugin(au.gov.asd.tac.constellation.plugins.templates.SimplePlugin)

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