Search in sources :

Example 1 with RecentParameterValues

use of au.gov.asd.tac.constellation.plugins.parameters.RecentParameterValues 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 RecentParameterValues

use of au.gov.asd.tac.constellation.plugins.parameters.RecentParameterValues in project constellation by constellation-app.

the class DataAccessTabPaneNGTest method storeParameterValues_verify_global_params_stored.

@Test
public void storeParameterValues_verify_global_params_stored() {
    final TabPane tabPane = mock(TabPane.class);
    final Tab tab1 = mock(Tab.class);
    final ScrollPane scrollPane = mock(ScrollPane.class);
    final QueryPhasePane queryPhasePane = mock(QueryPhasePane.class);
    final PluginParameter pluginParameter1 = mock(PluginParameter.class);
    final PluginParameter pluginParameter2 = mock(PluginParameter.class);
    final PluginParameter pluginParameter3 = mock(PluginParameter.class);
    // Set up our fake tab pane
    doReturn(tabPane).when(dataAccessTabPane).getTabPane();
    when(tabPane.getTabs()).thenReturn(FXCollections.observableArrayList(tab1));
    when(tab1.getContent()).thenReturn(scrollPane);
    when(scrollPane.getContent()).thenReturn(queryPhasePane);
    // Set up the global parameters
    final GlobalParametersPane globalParametersPane = mock(GlobalParametersPane.class);
    final PluginParameters pluginParameters = mock(PluginParameters.class);
    when(queryPhasePane.getGlobalParametersPane()).thenReturn(globalParametersPane);
    when(globalParametersPane.getParams()).thenReturn(pluginParameters);
    when(pluginParameters.getParameters()).thenReturn(Map.of("plugin1", pluginParameter1, "plugin2", pluginParameter2, "plugin3", pluginParameter3));
    // Parameters for plugins 1 and 2 will be dropped because they have no value.
    when(pluginParameter1.getStringValue()).thenReturn(null);
    when(pluginParameter2.getStringValue()).thenReturn(" ");
    when(pluginParameter3.getStringValue()).thenReturn("PluginParam3 String Value");
    try (final MockedStatic<RecentParameterValues> recentParamValsMockedStatic = Mockito.mockStatic(RecentParameterValues.class)) {
        dataAccessTabPane.storeParameterValues();
        // Verify that only plugin 3 parameter was set in the store
        recentParamValsMockedStatic.verify(() -> RecentParameterValues.storeRecentValue("plugin3", "PluginParam3 String Value"));
    }
}
Also used : TabPane(javafx.scene.control.TabPane) Tab(javafx.scene.control.Tab) QueryPhasePane(au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane) ScrollPane(javafx.scene.control.ScrollPane) RecentParameterValues(au.gov.asd.tac.constellation.plugins.parameters.RecentParameterValues) GlobalParametersPane(au.gov.asd.tac.constellation.views.dataaccess.panes.GlobalParametersPane) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) Test(org.testng.annotations.Test)

Example 3 with RecentParameterValues

use of au.gov.asd.tac.constellation.plugins.parameters.RecentParameterValues in project constellation by constellation-app.

the class DataAccessTabPaneNGTest method storeParameterValues_verify_plugin_params_stored.

@Test
public void storeParameterValues_verify_plugin_params_stored() {
    final TabPane tabPane = mock(TabPane.class);
    final Tab tab1 = mock(Tab.class);
    final ScrollPane scrollPane = mock(ScrollPane.class);
    final QueryPhasePane queryPhasePane = mock(QueryPhasePane.class);
    // Set up our fake tab pane
    doReturn(tabPane).when(dataAccessTabPane).getTabPane();
    when(tabPane.getTabs()).thenReturn(FXCollections.observableArrayList(tab1));
    when(tab1.getContent()).thenReturn(scrollPane);
    when(scrollPane.getContent()).thenReturn(queryPhasePane);
    // This just needs to be set up to prevent null pointers
    final GlobalParametersPane globalParametersPane = mock(GlobalParametersPane.class);
    final PluginParameters globalPluginParameters = mock(PluginParameters.class);
    when(queryPhasePane.getGlobalParametersPane()).thenReturn(globalParametersPane);
    when(globalParametersPane.getParams()).thenReturn(globalPluginParameters);
    when(globalPluginParameters.getParameters()).thenReturn(Map.of());
    // Add three data source title panes to the query source pane
    final DataSourceTitledPane dataSourceTitledPane1 = mock(DataSourceTitledPane.class);
    final DataSourceTitledPane dataSourceTitledPane2 = mock(DataSourceTitledPane.class);
    final DataSourceTitledPane dataSourceTitledPane3 = mock(DataSourceTitledPane.class);
    final List<DataSourceTitledPane> dataSourceTitledPanes = new ArrayList<>();
    dataSourceTitledPanes.add(dataSourceTitledPane1);
    dataSourceTitledPanes.add(dataSourceTitledPane2);
    dataSourceTitledPanes.add(dataSourceTitledPane3);
    when(queryPhasePane.getDataAccessPanes()).thenReturn(dataSourceTitledPanes);
    // Stub out the data source title pane's plugin parameters
    // Pane 1 has no parameters so it will be dropped
    when(dataSourceTitledPane1.getParameters()).thenReturn(null);
    final PluginParameters pane2PluginParameters = mock(PluginParameters.class);
    final PluginParameters pane3PluginParameters = mock(PluginParameters.class);
    when(dataSourceTitledPane2.getParameters()).thenReturn(pane2PluginParameters);
    when(dataSourceTitledPane3.getParameters()).thenReturn(pane3PluginParameters);
    // Stub out the individual parameters
    final PluginParameter pluginParameter1 = mock(PluginParameter.class);
    final PluginParameter pluginParameter2 = mock(PluginParameter.class);
    final PluginParameter pluginParameter3 = mock(PluginParameter.class);
    when(pane2PluginParameters.getParameters()).thenReturn(Map.of("plugin1", pluginParameter1, "plugin2", pluginParameter2));
    when(pane3PluginParameters.getParameters()).thenReturn(Map.of("plugin3", pluginParameter3));
    // Plugin 1 parameter will have no value and so will be ignored
    when(pluginParameter1.getObjectValue()).thenReturn(null);
    // Plugin 2 parameter will be a local date param type and handled differently
    when(pluginParameter2.getType()).thenReturn(LocalDateParameterType.INSTANCE);
    when(pluginParameter2.getObjectValue()).thenReturn("PluginParam2 Object Value");
    when(pluginParameter2.getStringValue()).thenReturn("PluginParam2 String Value");
    when(pluginParameter3.getType()).thenReturn(BooleanParameterType.INSTANCE);
    when(pluginParameter3.getObjectValue()).thenReturn("PluginParam3 Object Value");
    when(pluginParameter3.getStringValue()).thenReturn("PluginParam3 String Value");
    try (final MockedStatic<RecentParameterValues> recentParamValsMockedStatic = Mockito.mockStatic(RecentParameterValues.class)) {
        dataAccessTabPane.storeParameterValues();
        // Verify that parameters for plugins 2 and 3 were set to the store correctly
        recentParamValsMockedStatic.verify(() -> RecentParameterValues.storeRecentValue("plugin2", "PluginParam2 Object Value"));
        recentParamValsMockedStatic.verify(() -> RecentParameterValues.storeRecentValue("plugin3", "PluginParam3 String Value"));
    }
}
Also used : DataSourceTitledPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataSourceTitledPane) TabPane(javafx.scene.control.TabPane) Tab(javafx.scene.control.Tab) QueryPhasePane(au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane) ScrollPane(javafx.scene.control.ScrollPane) RecentParameterValues(au.gov.asd.tac.constellation.plugins.parameters.RecentParameterValues) ArrayList(java.util.ArrayList) GlobalParametersPane(au.gov.asd.tac.constellation.views.dataaccess.panes.GlobalParametersPane) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) Test(org.testng.annotations.Test)

Aggregations

PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)3 RecentParameterValues (au.gov.asd.tac.constellation.plugins.parameters.RecentParameterValues)3 QueryPhasePane (au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane)3 ScrollPane (javafx.scene.control.ScrollPane)3 Tab (javafx.scene.control.Tab)3 TabPane (javafx.scene.control.TabPane)3 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)2 DataSourceTitledPane (au.gov.asd.tac.constellation.views.dataaccess.panes.DataSourceTitledPane)2 GlobalParametersPane (au.gov.asd.tac.constellation.views.dataaccess.panes.GlobalParametersPane)2 Test (org.testng.annotations.Test)2 GraphManager (au.gov.asd.tac.constellation.graph.manager.GraphManager)1 DateTimeRange (au.gov.asd.tac.constellation.plugins.parameters.types.DateTimeRange)1 SeparatorConstants (au.gov.asd.tac.constellation.utilities.text.SeparatorConstants)1 CoreGlobalParameters (au.gov.asd.tac.constellation.views.dataaccess.CoreGlobalParameters)1 DataAccessPaneState (au.gov.asd.tac.constellation.views.dataaccess.api.DataAccessPaneState)1 DataAccessPane (au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane)1 DataAccessPlugin (au.gov.asd.tac.constellation.views.dataaccess.plugins.DataAccessPlugin)1 WaitForQueriesToCompleteTask (au.gov.asd.tac.constellation.views.dataaccess.tasks.WaitForQueriesToCompleteTask)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1