use of au.gov.asd.tac.constellation.plugins.PluginInteraction 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;
}
use of au.gov.asd.tac.constellation.plugins.PluginInteraction 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;
}
use of au.gov.asd.tac.constellation.plugins.PluginInteraction in project constellation by constellation-app.
the class ExportToExcelFilePluginNGTest method exportToExcelFileAllRows.
@Test
public void exportToExcelFileAllRows() throws IOException, InterruptedException, PluginException {
final boolean selectedOnly = false;
final String sheetName = "My Sheet";
final TableView<ObservableList<String>> table = mock(TableView.class);
final Pagination pagination = mock(Pagination.class);
final PluginInteraction pluginInteraction = mock(PluginInteraction.class);
final Callback<Integer, Node> callback = mock(Callback.class);
File tmpFile = null;
try {
tmpFile = File.createTempFile("constellationTest", ".xls");
when(pagination.getPageFactory()).thenReturn(callback);
when(callback.call(anyInt())).thenReturn(table);
when(pagination.getCurrentPageIndex()).thenReturn(42);
when(pagination.getPageCount()).thenReturn(2);
final TableColumn<ObservableList<String>, ? extends Object> column1 = mock(TableColumn.class);
final TableColumn<ObservableList<String>, ? extends Object> column2 = mock(TableColumn.class);
when(column1.getText()).thenReturn("COLUMN_1");
when(column2.getText()).thenReturn("COLUMN_2");
when(column1.isVisible()).thenReturn(true);
when(column2.isVisible()).thenReturn(true);
when(table.getColumns()).thenReturn(FXCollections.observableArrayList(column1, column2));
// Page 1
doReturn(FXCollections.observableList(List.of(FXCollections.observableList(List.of("row1Column1", "row1Column2", "row1InvisibleColumn3"))))).doReturn(FXCollections.observableList(List.of(FXCollections.observableList(List.of("row2Column1", "row2Column2", "row2InvisibleColumn3"))))).when(table).getItems();
final ExportToExcelFilePlugin exportToExcel = new ExportToExcelFilePlugin(tmpFile, table, pagination, 1, selectedOnly, sheetName);
exportToExcel.execute(null, pluginInteraction, null);
// Due to date/times etc. no two files are the same at the byte level
// So open the saved file, iterating over it, generating a CSV that can
// be verified.
final String csvInFile = generateCsvFromExcelFile(tmpFile, sheetName);
final String expected = "COLUMN_1,COLUMN_2\nrow1Column1,row1Column2\nrow2Column1,row2Column2\n";
assertEquals(expected, csvInFile);
// Verifies that it resets to the current page
verify(callback).call(42);
assertEquals("Table View: Export to Excel File", exportToExcel.getName());
} finally {
if (tmpFile != null) {
tmpFile.delete();
}
}
}
use of au.gov.asd.tac.constellation.plugins.PluginInteraction in project constellation by constellation-app.
the class LayersDualGraphSyncNGTest method dynamicLayerChangeTest.
@Test
public void dynamicLayerChangeTest() throws InterruptedException, PluginException {
// Check Vertex set correctly
ReadableGraph readableGraph = graph.getReadableGraph();
try {
assertEquals(readableGraph.getIntValue(layerMaskV, vxId1), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId1), 1.0f);
assertEquals(readableGraph.getIntValue(layerMaskV, vxId2), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId2), 1.0f);
assertEquals(readableGraph.getIntValue(layerMaskV, vxId3), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId3), 1.0f);
} finally {
readableGraph.release();
}
WritableGraph writableGraph = graph.getWritableGraph("", true);
try {
writableGraph.setLongValue(bitmaskAttributeId, 0, 0b10);
writableGraph.setLongValue(layerMaskV, vxId1, 3);
writableGraph.setFloatValue(layerVisibilityV, vxId1, 1.0f);
writableGraph.setLongValue(layerMaskV, vxId2, 1);
writableGraph.setFloatValue(layerVisibilityV, vxId2, 0.0f);
writableGraph.setLongValue(layerMaskV, vxId3, 1);
writableGraph.setFloatValue(layerVisibilityV, vxId3, 0.0f);
} finally {
writableGraph.commit();
}
readableGraph = graph.getReadableGraph();
try {
assertEquals(readableGraph.getLongValue(bitmaskAttributeId, 0), 0b10);
assertEquals((long) readableGraph.getObjectValue(layerMaskV, vxId1), 3);
assertEquals(readableGraph.getObjectValue(layerVisibilityV, vxId1), 1.0f);
assertEquals((long) readableGraph.getObjectValue(layerMaskV, vxId2), 1);
assertEquals(readableGraph.getObjectValue(layerVisibilityV, vxId2), 0.0f);
assertEquals((long) readableGraph.getObjectValue(layerMaskV, vxId3), 1);
assertEquals(readableGraph.getObjectValue(layerVisibilityV, vxId3), 0.0f);
} finally {
readableGraph.release();
}
// change an attribute to trigger switching of graph object within dual graph
PluginExecution.withPlugin(new SimpleEditPlugin("Test: change attribute value") {
@Override
public void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException {
final int maxTransactionsId = VisualConcept.GraphAttribute.MAX_TRANSACTIONS.ensure(graph);
graph.setLongValue(maxTransactionsId, 0, 9);
}
}).executeNow(graph);
// Check Vertex set correctly on second graph of dualgraph
readableGraph = graph.getReadableGraph();
try {
assertEquals((long) readableGraph.getObjectValue(layerMaskV, vxId1), 3);
assertEquals(readableGraph.getObjectValue(layerVisibilityV, vxId1), 1.0f);
assertEquals((long) readableGraph.getObjectValue(layerMaskV, vxId2), 1);
assertEquals(readableGraph.getObjectValue(layerVisibilityV, vxId2), 0.0f);
assertEquals((long) readableGraph.getObjectValue(layerMaskV, vxId3), 1);
assertEquals(readableGraph.getObjectValue(layerVisibilityV, vxId3), 0.0f);
} finally {
readableGraph.release();
}
writableGraph = graph.getWritableGraph("", true);
try {
writableGraph.setLongValue(layerMaskV, vxId1, 3);
writableGraph.setFloatValue(layerVisibilityV, vxId1, 1.0f);
writableGraph.setLongValue(layerMaskV, vxId2, 1);
writableGraph.setFloatValue(layerVisibilityV, vxId2, 1.0f);
writableGraph.setLongValue(layerMaskV, vxId3, 1);
writableGraph.setFloatValue(layerVisibilityV, vxId3, 1.0f);
} finally {
writableGraph.commit();
}
// PluginExecution.withPlugin(new UpdateLayerSelectionPlugin(queries, 1)).executeNow(graph);
readableGraph = graph.getReadableGraph();
try {
assertEquals(readableGraph.getLongValue(layerMaskV, vxId1), 3);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId1), 1.0f);
assertEquals(readableGraph.getLongValue(layerMaskV, vxId2), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId2), 1.0f);
assertEquals(readableGraph.getLongValue(layerMaskV, vxId3), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId3), 1.0f);
} finally {
readableGraph.release();
}
writableGraph = graph.getWritableGraph("", true);
try {
writableGraph.setLongValue(layerMaskV, vxId1, 3);
writableGraph.setFloatValue(layerVisibilityV, vxId1, 0.0f);
writableGraph.setLongValue(layerMaskV, vxId2, 0b101);
writableGraph.setFloatValue(layerVisibilityV, vxId2, 1.0f);
writableGraph.setLongValue(layerMaskV, vxId3, 1);
writableGraph.setFloatValue(layerVisibilityV, vxId3, 0.0f);
} finally {
writableGraph.commit();
}
readableGraph = graph.getReadableGraph();
try {
assertEquals(readableGraph.getLongValue(layerMaskV, vxId1), 3);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId1), 0.0f);
assertEquals(readableGraph.getLongValue(layerMaskV, vxId2), 0b101);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId2), 1.0f);
assertEquals(readableGraph.getLongValue(layerMaskV, vxId3), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId3), 0.0f);
} finally {
readableGraph.release();
}
writableGraph = graph.getWritableGraph("", true);
try {
writableGraph.setLongValue(layerMaskV, vxId1, 3);
writableGraph.setFloatValue(layerVisibilityV, vxId1, 1.0f);
writableGraph.setLongValue(layerMaskV, vxId2, 0b101);
writableGraph.setFloatValue(layerVisibilityV, vxId2, 1.0f);
writableGraph.setLongValue(layerMaskV, vxId3, 1);
writableGraph.setFloatValue(layerVisibilityV, vxId3, 1.0f);
} finally {
writableGraph.commit();
}
readableGraph = graph.getReadableGraph();
try {
assertEquals(readableGraph.getLongValue(layerMaskV, vxId1), 3);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId1), 1.0f);
assertEquals(readableGraph.getLongValue(layerMaskV, vxId2), 0b101);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId2), 1.0f);
assertEquals(readableGraph.getLongValue(layerMaskV, vxId3), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId3), 1.0f);
} finally {
readableGraph.release();
}
writableGraph = graph.getWritableGraph("", true);
try {
writableGraph.setLongValue(layerMaskV, vxId1, 1);
writableGraph.setFloatValue(layerVisibilityV, vxId1, 0.0f);
writableGraph.setLongValue(layerMaskV, vxId2, 0b111);
writableGraph.setFloatValue(layerVisibilityV, vxId2, 1.0f);
writableGraph.setLongValue(layerMaskV, vxId3, 1);
writableGraph.setFloatValue(layerVisibilityV, vxId3, 0.0f);
} finally {
writableGraph.commit();
}
readableGraph = graph.getReadableGraph();
try {
assertEquals(readableGraph.getLongValue(layerMaskV, vxId1), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId1), 0.0f);
assertEquals(readableGraph.getLongValue(layerMaskV, vxId2), 0b111);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId2), 1.0f);
assertEquals(readableGraph.getLongValue(layerMaskV, vxId3), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId3), 0.0f);
} finally {
readableGraph.release();
}
PluginExecution.withPlugin(new SimpleEditPlugin("Test: change attribute value") {
@Override
public void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException {
final int maxTransactionsId = VisualConcept.GraphAttribute.MAX_TRANSACTIONS.ensure(graph);
graph.setIntValue(maxTransactionsId, 0, 9);
}
}).executeNow(graph);
readableGraph = graph.getReadableGraph();
try {
assertEquals(readableGraph.getLongValue(layerMaskV, vxId1), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId1), 0.0f);
assertEquals(readableGraph.getLongValue(layerMaskV, vxId2), 0b111);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId2), 1.0f);
assertEquals(readableGraph.getLongValue(layerMaskV, vxId3), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId3), 0.0f);
} finally {
readableGraph.release();
}
}
use of au.gov.asd.tac.constellation.plugins.PluginInteraction in project constellation by constellation-app.
the class SelectBackbonePlugin method edit.
@Override
public void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException {
final ArrayList<Integer> selected_nodes = new ArrayList<>();
final int selectedNodeAttrId = VisualConcept.VertexAttribute.SELECTED.get(graph);
final int selectedTransactionAttrId = VisualConcept.TransactionAttribute.SELECTED.get(graph);
for (int position = 0; position < graph.getVertexCount(); position++) {
final int vxId = graph.getVertex(position);
// identify all nodes with connections > 1 that aren't self-loops
final IntStream neighbours = IntStream.range(0, graph.getVertexLinkCount(vxId)).map(linkPos -> graph.getVertexNeighbour(vxId, linkPos)).filter(neighbourId -> neighbourId != vxId);
if (neighbours.count() > 1) {
graph.setBooleanValue(selectedNodeAttrId, vxId, true);
selected_nodes.add(vxId);
}
}
// identify all transactions whose both nodes are selected
for (int position = 0; position < graph.getTransactionCount(); position++) {
final int txId = graph.getTransaction(position);
final int destVert = graph.getTransactionDestinationVertex(txId);
final int srcVert = graph.getTransactionSourceVertex(txId);
if (selected_nodes.contains(destVert) && selected_nodes.contains(srcVert) && srcVert != destVert) {
graph.setBooleanValue(selectedTransactionAttrId, txId, true);
}
}
}
Aggregations