use of au.gov.asd.tac.constellation.plugins.PluginInteraction in project constellation by constellation-app.
the class ExecuteListener method handle.
/**
* Handles the click of the execute button in the data access view.
* <p/>
* If the execute button was in the "Go" state then it will iterate through
* all the tabs and run the enabled and valid plugins.
* <p/>
* If the execute button was in the "Stop" state then cancel any running plugins.
*
* @param event the event triggered by clicking the execute button
*/
@Override
public void handle(final ActionEvent event) {
// When no graph present, create a new one
if (DataAccessPaneState.getCurrentGraphId() == null && dataAccessPane.getDataAccessTabPane().hasActiveAndValidPlugins()) {
// Create new graph
final NewDefaultSchemaGraphAction graphAction = new NewDefaultSchemaGraphAction();
graphAction.actionPerformed(null);
Graph newActiveGraph = null;
// Wait while graph is getting made
while (newActiveGraph == null) {
newActiveGraph = GraphManager.getDefault().getActiveGraph();
}
// Set the state's current graph ID to the ID of the new graph
DataAccessPaneState.setCurrentGraphId(newActiveGraph.getId());
}
// Run the selected queries
final ObservableList<Tab> tabs = dataAccessPane.getDataAccessTabPane().getTabPane().getTabs();
if (CollectionUtils.isNotEmpty(tabs) && DataAccessPaneState.isExecuteButtonIsGo()) {
// Change the execute button to "Stop" and do not disable because it is now running
dataAccessPane.setExecuteButtonToStop(false);
// Set the state for the current graph state to running queries
DataAccessPaneState.setQueriesRunning(true);
// Check to see if an output dir exists. Non exisiting dirs do not prevent the
// plugins running, just triggers a notification
final File outputDir = DataAccessPreferenceUtilities.getDataAccessResultsDirEx();
if (outputDir != null && outputDir.isDirectory()) {
StatusDisplayer.getDefault().setStatusText(String.format(STATUS_MESSAGE_FORMAT, outputDir.getAbsolutePath()));
} else if (outputDir != null) {
NotificationDisplayer.getDefault().notify(RESULTS_DIR_NOT_FOUND_TITLE, ERROR_ICON, String.format(RESULTS_DIR_NOT_FOUND_MSG, outputDir.getAbsolutePath()), null);
}
// Save the current data access view state
PluginExecution.withPlugin(new SimplePlugin(SAVE_STATE_PLUGIN_NAME) {
@Override
protected void execute(final PluginGraphs graphs, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
DataAccessUtilities.saveDataAccessState(dataAccessPane.getDataAccessTabPane().getTabPane(), GraphNode.getGraph(DataAccessPaneState.getCurrentGraphId()));
}
}).executeLater(null);
// Run the plugins from each tab. The barrier is the plugin run futures
// from the previous tab. When the tab is run, it has the option to
// wait for the previous tab to complete.
List<Future<?>> barrier = null;
for (final Tab tab : tabs) {
LOGGER.log(Level.INFO, String.format("Running tab: %s", tab.getText()));
barrier = DataAccessTabPane.getQueryPhasePane(tab).runPlugins(barrier);
}
// Asynchronously start the task that waits for all the plugins to complete.
// Once they are complete this task will perform cleanup.
CompletableFuture.runAsync(new WaitForQueriesToCompleteTask(dataAccessPane, DataAccessPaneState.getCurrentGraphId()), dataAccessPane.getParentComponent().getExecutorService());
LOGGER.info("Plugins run.");
} else {
// The execute button is in a "Stop" state. So cancel any running plugins.
DataAccessPaneState.getRunningPlugins().keySet().forEach(running -> running.cancel(true));
// Nothing is running now, so change the execute button to "Go".
dataAccessPane.setExecuteButtonToGo(false);
}
// Disables all plugins in the plugin pane
if (DataAccessPreferenceUtilities.isDeselectPluginsOnExecuteEnabled()) {
deselectAllPlugins();
}
}
use of au.gov.asd.tac.constellation.plugins.PluginInteraction in project constellation by constellation-app.
the class ExecuteListenerNGTest method setUpMethod.
@BeforeMethod
public void setUpMethod() throws Exception {
dataAccessViewTopComponent = mock(DataAccessViewTopComponent.class);
dataAccessPane = mock(DataAccessPane.class);
dataAccessTabPane = mock(DataAccessTabPane.class);
tabPane = mock(TabPane.class);
graphManager = mock(GraphManager.class);
activeGraph = mock(Graph.class);
when(dataAccessPane.getParentComponent()).thenReturn(dataAccessViewTopComponent);
when(dataAccessPane.getDataAccessTabPane()).thenReturn(dataAccessTabPane);
when(dataAccessTabPane.getTabPane()).thenReturn(tabPane);
when(dataAccessViewTopComponent.getExecutorService()).thenReturn(Executors.newSingleThreadExecutor());
executeListener = new ExecuteListener(dataAccessPane);
graphManagerMockedStatic.when(GraphManager::getDefault).thenReturn(graphManager);
when(graphManager.getActiveGraph()).thenReturn(activeGraph);
when(activeGraph.getId()).thenReturn(GRAPH_ID);
// Intercept the plugin execution run calls and run the plugins manually
// so that it executes within the same thread and sequentially for the test
pluginExecution = mock(PluginExecution.class);
pluginExecutionMockedStatic.when(() -> PluginExecution.withPlugin(any(SimplePlugin.class))).thenAnswer(iom -> {
final SimplePlugin plugin = iom.getArgument(0);
final PluginGraphs graphs = mock(PluginGraphs.class);
when(graphs.getGraph()).thenReturn(null);
final PluginInteraction pluginInteraction = mock(PluginInteraction.class);
final PluginParameters pluginParameters = mock(PluginParameters.class);
// This will call the execute method of the simple plugin
plugin.run(graphs, pluginInteraction, pluginParameters);
return pluginExecution;
});
// Intercept calls to start the wait for tasks so that they don't run
completableFutureMockedStatic.when(() -> CompletableFuture.runAsync(any(WaitForQueriesToCompleteTask.class), any(ExecutorService.class))).thenReturn(null);
notificationDisplayer = mock(NotificationDisplayer.class);
notificationDisplayerMockedStatic.when(NotificationDisplayer::getDefault).thenReturn(notificationDisplayer);
when(notificationDisplayer.notify(anyString(), any(Icon.class), anyString(), isNull())).thenReturn(null);
statusDisplayer = mock(StatusDisplayer.class);
statusDisplayerMockedStatic.when(StatusDisplayer::getDefault).thenReturn(statusDisplayer);
DataAccessPaneState.clearState();
}
use of au.gov.asd.tac.constellation.plugins.PluginInteraction in project constellation by constellation-app.
the class MergeNodesPluginNGTest method editMergeError.
@Test(expectedExceptions = PluginException.class)
public void editMergeError() throws InterruptedException, PluginException, MergeNodeType.MergeException {
final GraphWriteMethods graph = mock(GraphWriteMethods.class);
final PluginInteraction interaction = mock(PluginInteraction.class);
final PluginParameters parameters = mock(PluginParameters.class);
final PluginParameter mergeTypeParameter = mock(PluginParameter.class);
final PluginParameter thresholdParameter = mock(PluginParameter.class);
final PluginParameter mergerParameter = mock(PluginParameter.class);
final PluginParameter leadParameter = mock(PluginParameter.class);
final PluginParameter selectedParameter = mock(PluginParameter.class);
final Map<String, PluginParameter<?>> pluginParameters = Map.of("MergeNodesPlugin.merge_type", mergeTypeParameter, "MergeNodesPlugin.threshold", thresholdParameter, "MergeNodesPlugin.merger", mergerParameter, "MergeNodesPlugin.lead", leadParameter, "MergeNodesPlugin.selected", selectedParameter);
when(parameters.getParameters()).thenReturn(pluginParameters);
when(mergeTypeParameter.getStringValue()).thenReturn(TestMergeType.NAME);
when(thresholdParameter.getIntegerValue()).thenReturn(TestMergeType.MERGE_EXCEPTION_THRESHOLD);
when(mergerParameter.getStringValue()).thenReturn("Retain lead vertex attributes if present");
when(leadParameter.getStringValue()).thenReturn("Longest Value");
when(selectedParameter.getBooleanValue()).thenReturn(true);
mergeNodesPlugin.edit(graph, interaction, parameters);
}
use of au.gov.asd.tac.constellation.plugins.PluginInteraction in project constellation by constellation-app.
the class MergeNodesPluginNGTest method editNoMergeOptionSelected.
@Test(expectedExceptions = PluginException.class)
public void editNoMergeOptionSelected() throws InterruptedException, PluginException {
final GraphWriteMethods graph = mock(GraphWriteMethods.class);
final PluginInteraction interaction = mock(PluginInteraction.class);
final PluginParameters parameters = mock(PluginParameters.class);
final PluginParameter pluginParameter = mock(PluginParameter.class);
final Map<String, PluginParameter<?>> pluginParameters = Map.of("MergeNodesPlugin.merge_type", pluginParameter);
when(parameters.getParameters()).thenReturn(pluginParameters);
when(pluginParameter.getStringValue()).thenReturn(null);
mergeNodesPlugin.edit(graph, interaction, parameters);
}
use of au.gov.asd.tac.constellation.plugins.PluginInteraction in project constellation by constellation-app.
the class MergeNodesPluginNGTest method editMergeNodeTypeNotFound.
@Test(expectedExceptions = PluginException.class)
public void editMergeNodeTypeNotFound() throws InterruptedException, PluginException {
final GraphWriteMethods graph = mock(GraphWriteMethods.class);
final PluginInteraction interaction = mock(PluginInteraction.class);
final PluginParameters parameters = mock(PluginParameters.class);
final PluginParameter pluginParameter = mock(PluginParameter.class);
final Map<String, PluginParameter<?>> pluginParameters = Map.of("MergeNodesPlugin.merge_type", pluginParameter);
when(parameters.getParameters()).thenReturn(pluginParameters);
when(pluginParameter.getStringValue()).thenReturn("Something Random");
mergeNodesPlugin.edit(graph, interaction, parameters);
}
Aggregations