Search in sources :

Example 1 with PluginInteraction

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();
    }
}
Also used : Graph(au.gov.asd.tac.constellation.graph.Graph) WaitForQueriesToCompleteTask(au.gov.asd.tac.constellation.views.dataaccess.tasks.WaitForQueriesToCompleteTask) Tab(javafx.scene.control.Tab) PluginGraphs(au.gov.asd.tac.constellation.plugins.PluginGraphs) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) SimplePlugin(au.gov.asd.tac.constellation.plugins.templates.SimplePlugin) CompletableFuture(java.util.concurrent.CompletableFuture) Future(java.util.concurrent.Future) NewDefaultSchemaGraphAction(au.gov.asd.tac.constellation.graph.node.create.NewDefaultSchemaGraphAction) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) File(java.io.File)

Example 2 with PluginInteraction

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();
}
Also used : TabPane(javafx.scene.control.TabPane) DataAccessTabPane(au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane) PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) WaitForQueriesToCompleteTask(au.gov.asd.tac.constellation.views.dataaccess.tasks.WaitForQueriesToCompleteTask) StatusDisplayer(org.openide.awt.StatusDisplayer) DataAccessPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane) PluginGraphs(au.gov.asd.tac.constellation.plugins.PluginGraphs) DataAccessTabPane(au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane) Graph(au.gov.asd.tac.constellation.graph.Graph) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) ExecutorService(java.util.concurrent.ExecutorService) SimplePlugin(au.gov.asd.tac.constellation.plugins.templates.SimplePlugin) NotificationDisplayer(org.openide.awt.NotificationDisplayer) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) Icon(javax.swing.Icon) DataAccessViewTopComponent(au.gov.asd.tac.constellation.views.dataaccess.DataAccessViewTopComponent) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with PluginInteraction

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);
}
Also used : GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) Test(org.testng.annotations.Test)

Example 4 with PluginInteraction

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);
}
Also used : GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) Test(org.testng.annotations.Test)

Example 5 with PluginInteraction

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);
}
Also used : GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) Test(org.testng.annotations.Test)

Aggregations

PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)51 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)44 Test (org.testng.annotations.Test)33 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)16 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)15 ArrayList (java.util.ArrayList)15 TextPluginInteraction (au.gov.asd.tac.constellation.plugins.text.TextPluginInteraction)14 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)13 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)12 PluginGraphs (au.gov.asd.tac.constellation.plugins.PluginGraphs)10 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)9 Graph (au.gov.asd.tac.constellation.graph.Graph)8 GraphRecordStore (au.gov.asd.tac.constellation.graph.processing.GraphRecordStore)8 RecordStore (au.gov.asd.tac.constellation.graph.processing.RecordStore)8 List (java.util.List)8 VisualConcept (au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept)7 PluginInfo (au.gov.asd.tac.constellation.plugins.PluginInfo)7 PluginTags (au.gov.asd.tac.constellation.plugins.templates.PluginTags)7 SimpleEditPlugin (au.gov.asd.tac.constellation.plugins.templates.SimpleEditPlugin)7 PluginExecution (au.gov.asd.tac.constellation.plugins.PluginExecution)6