Search in sources :

Example 1 with DataSourceTitledPane

use of au.gov.asd.tac.constellation.views.dataaccess.panes.DataSourceTitledPane in project constellation by constellation-app.

the class DataAccessTabPane method storeParameterValues.

/**
 * Store current parameter values for all tabs and plug-ins in the
 * {@link RecentParameterValues} repository. It will store both global and
 * plugin parameters.
 */
protected void storeParameterValues() {
    getTabPane().getTabs().parallelStream().forEach(tab -> {
        final QueryPhasePane pluginPane = getQueryPhasePane(tab);
        // Store global parameters
        pluginPane.getGlobalParametersPane().getParams().getParameters().entrySet().stream().filter(param -> param.getValue().getStringValue() != null && !param.getValue().getStringValue().isEmpty()).forEach(param -> RecentParameterValues.storeRecentValue(param.getKey(), param.getValue().getStringValue()));
        // Store data access plugin parameters
        pluginPane.getDataAccessPanes().stream().map(DataSourceTitledPane::getParameters).filter(Objects::nonNull).map(PluginParameters::getParameters).map(Map::entrySet).flatMap(Collection::stream).filter(param -> param.getValue().getObjectValue() != null).forEach(param -> {
            if (!param.getValue().getType().toString().contains(LOCAL_DATE_PARAMETER_TYPE)) {
                RecentParameterValues.storeRecentValue(param.getKey(), param.getValue().getStringValue());
            } else {
                RecentParameterValues.storeRecentValue(param.getKey(), param.getValue().getObjectValue().toString());
            }
        });
    });
}
Also used : EventHandler(javafx.event.EventHandler) CoreGlobalParameters(au.gov.asd.tac.constellation.views.dataaccess.CoreGlobalParameters) MouseEvent(javafx.scene.input.MouseEvent) CompletableFuture(java.util.concurrent.CompletableFuture) DataSourceTitledPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataSourceTitledPane) Function(java.util.function.Function) Side(javafx.geometry.Side) StringUtils(org.apache.commons.lang3.StringUtils) Level(java.util.logging.Level) Future(java.util.concurrent.Future) ScrollPane(javafx.scene.control.ScrollPane) TabPane(javafx.scene.control.TabPane) ListChangeListener(javafx.collections.ListChangeListener) DataAccessPlugin(au.gov.asd.tac.constellation.views.dataaccess.plugins.DataAccessPlugin) WaitForQueriesToCompleteTask(au.gov.asd.tac.constellation.views.dataaccess.tasks.WaitForQueriesToCompleteTask) Map(java.util.Map) DateTimeRange(au.gov.asd.tac.constellation.plugins.parameters.types.DateTimeRange) Tooltip(javafx.scene.control.Tooltip) GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) TextField(javafx.scene.control.TextField) Label(javafx.scene.control.Label) RecentParameterValues(au.gov.asd.tac.constellation.plugins.parameters.RecentParameterValues) DataAccessPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane) SeparatorConstants(au.gov.asd.tac.constellation.utilities.text.SeparatorConstants) Collection(java.util.Collection) DataAccessPaneState(au.gov.asd.tac.constellation.views.dataaccess.api.DataAccessPaneState) Event(javafx.event.Event) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) QueryPhasePane(au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane) Tab(javafx.scene.control.Tab) Optional(java.util.Optional) ObservableValue(javafx.beans.value.ObservableValue) ContentDisplay(javafx.scene.control.ContentDisplay) DataSourceTitledPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataSourceTitledPane) QueryPhasePane(au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane) Collection(java.util.Collection) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)

Example 2 with DataSourceTitledPane

use of au.gov.asd.tac.constellation.views.dataaccess.panes.DataSourceTitledPane in project constellation by constellation-app.

the class DataAccessTabPaneNGTest method tabHasEnabledPlugins.

@Test
public void tabHasEnabledPlugins() {
    final DataSourceTitledPane dataSourceTitledPane1 = mock(DataSourceTitledPane.class);
    final DataSourceTitledPane dataSourceTitledPane2 = mock(DataSourceTitledPane.class);
    final Tab tab = mock(Tab.class);
    final QueryPhasePane queryPhasePane = mock(QueryPhasePane.class);
    try (final MockedStatic<DataAccessTabPane> datPaneMockedStatic = Mockito.mockStatic(DataAccessTabPane.class, Mockito.CALLS_REAL_METHODS)) {
        datPaneMockedStatic.when(() -> DataAccessTabPane.getQueryPhasePane(same(tab))).thenReturn(queryPhasePane);
        when(queryPhasePane.getDataAccessPanes()).thenReturn(List.of(dataSourceTitledPane1, dataSourceTitledPane2));
        when(dataSourceTitledPane1.isQueryEnabled()).thenReturn(false);
        when(dataSourceTitledPane2.isQueryEnabled()).thenReturn(true);
        assertTrue(DataAccessTabPane.tabHasEnabledPlugins(tab));
    }
}
Also used : DataSourceTitledPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataSourceTitledPane) Tab(javafx.scene.control.Tab) QueryPhasePane(au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane) Test(org.testng.annotations.Test)

Example 3 with DataSourceTitledPane

use of au.gov.asd.tac.constellation.views.dataaccess.panes.DataSourceTitledPane in project constellation by constellation-app.

the class TabContextMenuNGTest method verifyDeactivateAllPluginsMenuItemAction.

/**
 * Verifies that the deactivate all plugins menu item will set the validity of all
 * plugins that are enabled to false when it is clicked.
 *
 * @param deactivateAllPluginsMenuItem the deactivate all plugins menu item
 */
private void verifyDeactivateAllPluginsMenuItemAction(final MenuItem deactivateAllPluginsMenuItem) {
    try (final MockedStatic<DataAccessTabPane> tabPaneMockedStatic = Mockito.mockStatic(DataAccessTabPane.class)) {
        final QueryPhasePane queryPhasePane = mock(QueryPhasePane.class);
        tabPaneMockedStatic.when(() -> DataAccessTabPane.getQueryPhasePane(tab)).thenReturn(queryPhasePane);
        final DataSourceTitledPane dataSourceTitledPane1 = mock(DataSourceTitledPane.class);
        final DataSourceTitledPane dataSourceTitledPane2 = mock(DataSourceTitledPane.class);
        when(queryPhasePane.getDataAccessPanes()).thenReturn(List.of(dataSourceTitledPane1, dataSourceTitledPane2));
        when(dataSourceTitledPane1.isQueryEnabled()).thenReturn(false);
        when(dataSourceTitledPane2.isQueryEnabled()).thenReturn(true);
        final ActionEvent actionEvent = mock(ActionEvent.class);
        deactivateAllPluginsMenuItem.getOnAction().handle(actionEvent);
        verify(dataSourceTitledPane2).validityChanged(false);
        verify(actionEvent).consume();
    }
}
Also used : DataSourceTitledPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataSourceTitledPane) QueryPhasePane(au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane) ActionEvent(javafx.event.ActionEvent)

Example 4 with DataSourceTitledPane

use of au.gov.asd.tac.constellation.views.dataaccess.panes.DataSourceTitledPane in project constellation by constellation-app.

the class ExecuteListenerNGTest method handle_sunny_days.

@Test
public void handle_sunny_days() {
    // Set the results directory
    final File tmpDir = new File(System.getProperty("java.io.tmpdir"));
    DataAccessPreferenceUtilities.setDataAccessResultsDir(tmpDir);
    // Setting this to true ensures that active plugins are de-selected at the end
    DataAccessPreferenceUtilities.setDeselectPluginsOnExecute(true);
    // We don't set the current graph ID in the state but ensure that there
    // active and valid plugins in the tab pane so that a new graph is created
    // on the fly
    when(dataAccessTabPane.hasActiveAndValidPlugins()).thenReturn(true);
    graphNodeMockedStatic.when(() -> GraphNode.getGraph(anyString())).thenReturn(activeGraph);
    // Set up our fake tab pane
    final Tab tab1 = mock(Tab.class);
    final Tab tab2 = mock(Tab.class);
    when(tabPane.getTabs()).thenReturn(FXCollections.observableArrayList(tab1, tab2));
    final QueryPhasePane queryPhasePane1 = mock(QueryPhasePane.class);
    final QueryPhasePane queryPhasePane2 = mock(QueryPhasePane.class);
    dataAccessTabPaneMockedStatic.when(() -> DataAccessTabPane.getQueryPhasePane(tab1)).thenReturn(queryPhasePane1);
    dataAccessTabPaneMockedStatic.when(() -> DataAccessTabPane.getQueryPhasePane(tab2)).thenReturn(queryPhasePane2);
    // Tab 1 does not have enabled plugins and tab 2 does. This is testing the deselect
    // plugin code. The deselection should not happen on tab 1 because it has no enabled
    // plugins
    dataAccessTabPaneMockedStatic.when(() -> DataAccessTabPane.tabHasEnabledPlugins(tab1)).thenReturn(false);
    dataAccessTabPaneMockedStatic.when(() -> DataAccessTabPane.tabHasEnabledPlugins(tab2)).thenReturn(true);
    // Because tab 1 is not enabled de-selection should happen on pane 2 and 3, but
    // not pane 1.
    final DataSourceTitledPane dataSourceTitledPane1 = mock(DataSourceTitledPane.class);
    when(queryPhasePane1.getDataAccessPanes()).thenReturn(List.of(dataSourceTitledPane1));
    final DataSourceTitledPane dataSourceTitledPane2 = mock(DataSourceTitledPane.class);
    final DataSourceTitledPane dataSourceTitledPane3 = mock(DataSourceTitledPane.class);
    when(queryPhasePane2.getDataAccessPanes()).thenReturn(List.of(dataSourceTitledPane2, dataSourceTitledPane3));
    // Set up the plugin running. Tab 1 is run first which returns a future. That future
    // is then passed in when tab 2 is run.
    final List<Future<?>> barrier1 = List.of(CompletableFuture.completedFuture("First tab run"));
    doReturn(barrier1).when(queryPhasePane1).runPlugins(null);
    doReturn(null).when(queryPhasePane2).runPlugins(barrier1);
    final ActionEvent event = mock(ActionEvent.class);
    try (MockedConstruction<WaitForQueriesToCompleteTask> waitForMockedConstruction = Mockito.mockConstruction(WaitForQueriesToCompleteTask.class, (waitForMock, cntxt) -> {
        assertEquals(cntxt.arguments(), List.of(dataAccessPane, GRAPH_ID));
    })) {
        executeListener.handle(event);
        // There was not current graph set during the test setup. So we
        // should see one construction of the graph action to create on.
        assertEquals(graphActionMockedConstruction.constructed().size(), 1);
        // Verify the execute button is changed to "Stop" and the status
        // displayer is sent some text describing the action success
        verify(dataAccessPane).setExecuteButtonToStop(false);
        verify(statusDisplayer).setStatusText("Data access results will be written to " + tmpDir.getAbsolutePath());
        // Verify the current state is saved before the plugins are run
        utilitiesMockedStatic.verify(() -> DataAccessUtilities.saveDataAccessState(tabPane, activeGraph));
        verify(pluginExecution).executeLater(null);
        // Verify the plugins are run
        verify(queryPhasePane1).runPlugins(or(anyList(), isNull()));
        verify(queryPhasePane2).runPlugins(or(anyList(), isNull()));
        verify(queryPhasePane1).runPlugins(null);
        verify(queryPhasePane2).runPlugins(barrier1);
        // Verify that the wait and clean up task is started
        assertEquals(waitForMockedConstruction.constructed().size(), 1);
        completableFutureMockedStatic.verify(() -> CompletableFuture.runAsync(same(waitForMockedConstruction.constructed().get(0)), any(ExecutorService.class)));
        // Verify that the correct plugins are de-selected
        verifyNoInteractions(dataSourceTitledPane1);
        verify(dataSourceTitledPane2).validityChanged(false);
        verify(dataSourceTitledPane3).validityChanged(false);
        verifyNoInteractions(event);
        // Verify that the state for the current graph is that queries are running
        assertTrue(DataAccessPaneState.isQueriesRunning());
    }
}
Also used : DataSourceTitledPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataSourceTitledPane) WaitForQueriesToCompleteTask(au.gov.asd.tac.constellation.views.dataaccess.tasks.WaitForQueriesToCompleteTask) Tab(javafx.scene.control.Tab) QueryPhasePane(au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane) ActionEvent(javafx.event.ActionEvent) Future(java.util.concurrent.Future) CompletableFuture(java.util.concurrent.CompletableFuture) File(java.io.File) Test(org.testng.annotations.Test)

Example 5 with DataSourceTitledPane

use of au.gov.asd.tac.constellation.views.dataaccess.panes.DataSourceTitledPane in project constellation by constellation-app.

the class DataAccessParametersIoProviderNGTest method loadParameters.

@Test
public void loadParameters() throws IOException {
    final DataAccessPane dataAccessPane = mock(DataAccessPane.class);
    final DataAccessTabPane dataAccessTabPane = mock(DataAccessTabPane.class);
    when(dataAccessPane.getDataAccessTabPane()).thenReturn(dataAccessTabPane);
    final QueryPhasePane tab1 = mock(QueryPhasePane.class);
    final QueryPhasePane tab2 = mock(QueryPhasePane.class);
    when(dataAccessTabPane.newTab(anyString())).thenReturn(tab1).thenReturn(tab2);
    final GlobalParametersPane globalParametersPane1 = mock(GlobalParametersPane.class);
    final GlobalParametersPane globalParametersPane2 = mock(GlobalParametersPane.class);
    when(tab1.getGlobalParametersPane()).thenReturn(globalParametersPane1);
    when(tab2.getGlobalParametersPane()).thenReturn(globalParametersPane2);
    // By adding the settings bit here, it forces mockito to generate two different
    // classes. Otherwise they would be two different objects but have the same class name
    final Plugin plugin1 = mock(Plugin.class, withSettings().extraInterfaces(Comparable.class));
    final Plugin plugin2 = mock(Plugin.class, withSettings().extraInterfaces(Serializable.class));
    final DataSourceTitledPane dataSourceTitledPane1 = mock(DataSourceTitledPane.class);
    when(dataSourceTitledPane1.getPlugin()).thenReturn(plugin1);
    final DataSourceTitledPane dataSourceTitledPane2 = mock(DataSourceTitledPane.class);
    when(dataSourceTitledPane2.getPlugin()).thenReturn(plugin2);
    when(tab1.getDataAccessPanes()).thenReturn(List.of(dataSourceTitledPane1, dataSourceTitledPane2));
    when(tab2.getDataAccessPanes()).thenReturn(List.of());
    final PluginParameter pluginParameter1 = mock(PluginParameter.class);
    when(pluginParameter1.getId()).thenReturn("param1");
    final PluginParameter pluginParameter2 = mock(PluginParameter.class);
    when(pluginParameter2.getId()).thenReturn("param2");
    final PluginParameter pluginParameter3 = mock(PluginParameter.class);
    when(pluginParameter3.getId()).thenReturn("param3");
    final PluginParameter pluginParameter4 = mock(PluginParameter.class);
    when(pluginParameter4.getId()).thenReturn("param4");
    final PluginParameters globalPluginParameters1 = new PluginParameters();
    globalPluginParameters1.addParameter(pluginParameter1);
    globalPluginParameters1.addParameter(pluginParameter2);
    globalPluginParameters1.addParameter(pluginParameter3);
    final PluginParameters globalPluginParameters2 = new PluginParameters();
    globalPluginParameters2.addParameter(pluginParameter3);
    globalPluginParameters2.addParameter(pluginParameter4);
    when(globalParametersPane1.getParams()).thenReturn(globalPluginParameters1);
    when(globalParametersPane2.getParams()).thenReturn(globalPluginParameters2);
    try (final MockedStatic<JsonIO> jsonIOStaticMock = Mockito.mockStatic(JsonIO.class)) {
        final ObjectMapper objectMapper = new ObjectMapper();
        final String json = IOUtils.toString(new FileInputStream(getClass().getResource("resources/preferences.json").getPath()), StandardCharsets.UTF_8);
        // We do not know the mockito plugin names ahead of time so substitute them in now
        final StringSubstitutor substitutor = new StringSubstitutor(Map.of("INSERT_PLUGIN1_NAME", plugin1.getClass().getSimpleName(), "INSERT_PLUGIN2_NAME", plugin2.getClass().getSimpleName()));
        final List<DataAccessUserPreferences> preferences = objectMapper.readValue(substitutor.replace(json), new TypeReference<List<DataAccessUserPreferences>>() {
        });
        jsonIOStaticMock.when(() -> JsonIO.loadJsonPreferences(eq(Optional.of("DataAccessView")), any(TypeReference.class))).thenReturn(preferences);
        DataAccessParametersIoProvider.loadParameters(dataAccessPane);
    }
    verify(dataAccessTabPane, times(2)).newTab(anyString());
    // tab1 global parameters
    verify(pluginParameter1).setStringValue("tab1_param1_value");
    verify(pluginParameter3).setStringValue(null);
    // tab1 plugin parameters - only plugin1 because plugin2 is disabled
    verify(dataSourceTitledPane1).setParameterValues(Map.of(plugin1.getClass().getSimpleName() + "." + "__is_enabled__", "true", plugin1.getClass().getSimpleName() + "." + "param1", "plugin1_param1_value"));
    // tab2 global parameters
    verify(pluginParameter4).setStringValue("tab2_param4_value");
    // tab2 plugin parameters
    verify(dataSourceTitledPane2, times(0)).setParameterValues(anyMap());
}
Also used : JsonIO(au.gov.asd.tac.constellation.utilities.genericjsonio.JsonIO) Serializable(java.io.Serializable) DataAccessPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane) QueryPhasePane(au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane) GlobalParametersPane(au.gov.asd.tac.constellation.views.dataaccess.panes.GlobalParametersPane) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FileInputStream(java.io.FileInputStream) DataAccessUserPreferences(au.gov.asd.tac.constellation.views.dataaccess.api.DataAccessUserPreferences) DataSourceTitledPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataSourceTitledPane) DataAccessTabPane(au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane) StringSubstitutor(org.apache.commons.text.StringSubstitutor) List(java.util.List) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) TypeReference(com.fasterxml.jackson.core.type.TypeReference) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) Test(org.testng.annotations.Test)

Aggregations

DataSourceTitledPane (au.gov.asd.tac.constellation.views.dataaccess.panes.DataSourceTitledPane)10 QueryPhasePane (au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane)10 Tab (javafx.scene.control.Tab)6 Test (org.testng.annotations.Test)6 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)5 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)4 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)3 GlobalParametersPane (au.gov.asd.tac.constellation.views.dataaccess.panes.GlobalParametersPane)3 WaitForQueriesToCompleteTask (au.gov.asd.tac.constellation.views.dataaccess.tasks.WaitForQueriesToCompleteTask)3 ActionEvent (javafx.event.ActionEvent)3 RecentParameterValues (au.gov.asd.tac.constellation.plugins.parameters.RecentParameterValues)2 DataAccessPane (au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane)2 File (java.io.File)2 List (java.util.List)2 Map (java.util.Map)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Future (java.util.concurrent.Future)2 ScrollPane (javafx.scene.control.ScrollPane)2 TabPane (javafx.scene.control.TabPane)2 GraphManager (au.gov.asd.tac.constellation.graph.manager.GraphManager)1