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);
}
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;
}
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());
}
}
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());
}
}
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;
}
}
Aggregations