Search in sources :

Example 46 with Plugin

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

the class DataAccessUserPreferencesNGTest method initWithPane.

@Test
public void initWithPane() {
    final QueryPhasePane tab = mock(QueryPhasePane.class);
    final GlobalParametersPane globalParametersPane = mock(GlobalParametersPane.class);
    when(tab.getGlobalParametersPane()).thenReturn(globalParametersPane);
    final Plugin plugin1 = mock(Plugin.class);
    final DataSourceTitledPane dataSourceTitledPane1 = mock(DataSourceTitledPane.class);
    when(dataSourceTitledPane1.getPlugin()).thenReturn(plugin1);
    when(dataSourceTitledPane1.isQueryEnabled()).thenReturn(true);
    final DataSourceTitledPane dataSourceTitledPane2 = mock(DataSourceTitledPane.class);
    when(dataSourceTitledPane2.isQueryEnabled()).thenReturn(false);
    when(tab.getDataAccessPanes()).thenReturn(List.of(dataSourceTitledPane1, dataSourceTitledPane2));
    final PluginParameterType passwordType = mock(PluginParameterType.class);
    when(passwordType.getId()).thenReturn("password");
    final PluginParameterType stringType = mock(PluginParameterType.class);
    when(stringType.getId()).thenReturn("string");
    // Plugin params will be in global and plugin but because it is in global
    // it should not be included in the plugin section
    final PluginParameter pluginParameter1 = mock(PluginParameter.class);
    when(pluginParameter1.getId()).thenReturn("param1");
    when(pluginParameter1.getStringValue()).thenReturn("value1");
    when(pluginParameter1.getType()).thenReturn(stringType);
    final PluginParameter pluginParameter2 = mock(PluginParameter.class);
    when(pluginParameter2.getId()).thenReturn("param2");
    when(pluginParameter2.getStringValue()).thenReturn("value2");
    when(pluginParameter2.getType()).thenReturn(stringType);
    final PluginParameter pluginParameter3 = mock(PluginParameter.class);
    when(pluginParameter3.getId()).thenReturn("param3");
    when(pluginParameter3.getStringValue()).thenReturn("value3");
    when(pluginParameter3.getType()).thenReturn(stringType);
    // Param 4 is of password type and should not be added
    final PluginParameter pluginParameter4 = mock(PluginParameter.class);
    when(pluginParameter4.getId()).thenReturn("param4");
    when(pluginParameter4.getStringValue()).thenReturn("value4");
    when(pluginParameter4.getType()).thenReturn(passwordType);
    // Set the global parameters
    final PluginParameters globalPluginParameters1 = new PluginParameters();
    globalPluginParameters1.addParameter(pluginParameter1);
    globalPluginParameters1.addParameter(pluginParameter2);
    // Set the parameters for plugin1
    final PluginParameters plugin1Parameters = new PluginParameters();
    plugin1Parameters.addParameter(pluginParameter1);
    plugin1Parameters.addParameter(pluginParameter3);
    plugin1Parameters.addParameter(pluginParameter4);
    when(globalParametersPane.getParams()).thenReturn(globalPluginParameters1);
    when(dataSourceTitledPane1.getParameters()).thenReturn(plugin1Parameters);
    final DataAccessUserPreferences preferences = new DataAccessUserPreferences(tab);
    final DataAccessUserPreferences expectedPreferences = new DataAccessUserPreferences();
    expectedPreferences.setGlobalParameters(Map.of("param1", "value1", "param2", "value2"));
    final Map<String, Map<String, String>> examplePluginParameters = new HashMap<>();
    examplePluginParameters.put(plugin1.getClass().getSimpleName(), Map.of(plugin1.getClass().getSimpleName() + "." + "__is_enabled__", "true", "param3", "value3"));
    expectedPreferences.setPluginParameters(examplePluginParameters);
    assertEquals(preferences, expectedPreferences);
}
Also used : DataSourceTitledPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataSourceTitledPane) QueryPhasePane(au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane) HashMap(java.util.HashMap) PluginParameterType(au.gov.asd.tac.constellation.plugins.parameters.PluginParameterType) 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) HashMap(java.util.HashMap) Map(java.util.Map) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) Test(org.testng.annotations.Test)

Example 47 with Plugin

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

the class QueryPhasePane method runPlugins.

/**
 * Run the plugin for each data access pane in this query pane, optionally
 * waiting first on a list of passed futures. This method will start the
 * plugin execution and return a list of futures representing each plugins
 * execution.
 *
 * @param async if not null, the plugins to be executed will wait till all the
 *     futures in the list have been completed before running
 * @return a list of futures representing the plugins that were executed
 */
public List<Future<?>> runPlugins(final List<Future<?>> async) {
    // Get the global plugin parameters for this query pane
    final Map<String, PluginParameter<?>> globalParams = getGlobalParametersPane().getParams().getParameters();
    // Pre-query validation checking
    for (final DataAccessPreQueryValidation check : PRE_QUERY_VALIDATION) {
        if (!check.execute(this)) {
            return Collections.emptyList();
        }
    }
    // Determine the number of plugins that will be executed
    final int pluginsToRun = Long.valueOf(getDataAccessPanes().stream().filter(DataSourceTitledPane::isQueryEnabled).count()).intValue();
    LOGGER.log(Level.INFO, "\tRunning {0} plugins", pluginsToRun);
    final PluginSynchronizer synchroniser = new PluginSynchronizer(pluginsToRun);
    final List<Future<?>> newAsync = new ArrayList<>(pluginsToRun);
    getDataAccessPanes().stream().filter(DataSourceTitledPane::isQueryEnabled).forEach(pane -> {
        // Copy global parameters into plugin parameters where there
        // is overlap
        PluginParameters parameters = pane.getParameters();
        if (parameters != null) {
            parameters = parameters.copy();
            parameters.getParameters().entrySet().stream().filter(entry -> globalParams.containsKey(entry.getKey())).forEach(entry -> entry.getValue().setObjectValue(globalParams.get(entry.getKey()).getObjectValue()));
        }
        // Get the plugin for this pane and run it
        final Plugin plugin = PluginRegistry.get(pane.getPlugin().getClass().getName());
        LOGGER.log(Level.INFO, "\t\tRunning {0}", plugin.getName());
        final Future<?> pluginResult = PluginExecution.withPlugin(plugin).withParameters(parameters).waitingFor(async).synchronizingOn(synchroniser).executeLater(GraphManager.getDefault().getActiveGraph());
        newAsync.add(pluginResult);
        DataAccessPaneState.addRunningPlugin(pluginResult, plugin.getName());
    });
    return newAsync;
}
Also used : Arrays(java.util.Arrays) VBox(javafx.scene.layout.VBox) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) HashSet(java.util.HashSet) DataAccessPreQueryValidation(au.gov.asd.tac.constellation.views.dataaccess.templates.DataAccessPreQueryValidation) Future(java.util.concurrent.Future) ScrollPane(javafx.scene.control.ScrollPane) DataAccessPlugin(au.gov.asd.tac.constellation.views.dataaccess.plugins.DataAccessPlugin) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) Map(java.util.Map) PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) PluginRegistry(au.gov.asd.tac.constellation.plugins.PluginRegistry) GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) Lookup(org.openide.util.Lookup) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) MenuItem(javafx.scene.control.MenuItem) Node(javafx.scene.Node) DataAccessPaneState(au.gov.asd.tac.constellation.views.dataaccess.api.DataAccessPaneState) Set(java.util.Set) Logger(java.util.logging.Logger) Platform(javafx.application.Platform) PluginParametersPaneListener(au.gov.asd.tac.constellation.plugins.gui.PluginParametersPaneListener) List(java.util.List) PluginSynchronizer(au.gov.asd.tac.constellation.plugins.PluginSynchronizer) Collections(java.util.Collections) PluginSynchronizer(au.gov.asd.tac.constellation.plugins.PluginSynchronizer) ArrayList(java.util.ArrayList) DataAccessPreQueryValidation(au.gov.asd.tac.constellation.views.dataaccess.templates.DataAccessPreQueryValidation) Future(java.util.concurrent.Future) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) DataAccessPlugin(au.gov.asd.tac.constellation.views.dataaccess.plugins.DataAccessPlugin) Plugin(au.gov.asd.tac.constellation.plugins.Plugin)

Example 48 with Plugin

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

the class SaveResultsFileWriterNGTest method testGenerateFilename.

/**
 * Test of generateFilename method. Ensure that generated filename is of the
 * correct format yyyyMMddTHHmmssSSS.
 */
@Test
public void testGenerateFilename() {
    Plugin plugin = new ExampleClass();
    String filename = SaveResultsFileWriter.generateFilename(plugin, "xml");
    Pattern pattern = Pattern.compile("[0-9]{8}T[0-9]{9}-ExampleClass.xml");
    Matcher matcher = pattern.matcher(filename);
    Assert.assertTrue(matcher.matches(), "Testing generated filename matches pattern - yyyyMMddTHHmmssSSS.");
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) Test(org.testng.annotations.Test)

Example 49 with Plugin

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

the class SaveResultsFileWriterNGTest method testWriteRecordStoreNoDataAccessResultsDir.

/**
 * Test of writeRecordStore method for case when
 * DataAccessPreferenceKeys.getDataAccessResultsDir() returns null. The
 * expectation is that no attempted writes are made. This test executes a
 * code path through SaveResultsFileWriter.writeRecordStore that does not
 * throw an exception.
 *
 * @throws java.lang.Exception
 */
@Test
public void testWriteRecordStoreNoDataAccessResultsDir() throws Exception {
    Plugin plugin = new ExampleClass();
    TabularRecordStore tabularRecordStore = new TabularRecordStore();
    mockedDataAccessPreferenceKeys.when(() -> DataAccessPreferenceUtilities.getDataAccessResultsDir()).thenReturn(null);
    SaveResultsFileWriter.writeRecordStore(plugin, tabularRecordStore);
    Assert.assertTrue(true, "Testing writing record to non existant directory - code will do nothing.");
}
Also used : TabularRecordStore(au.gov.asd.tac.constellation.graph.processing.TabularRecordStore) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) Test(org.testng.annotations.Test)

Example 50 with Plugin

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

the class DataAccessPaneNGTest method update_pass_null_graph.

@Test
public void update_pass_null_graph() {
    final DataAccessTabPane dataAccessTabPane = mock(DataAccessTabPane.class);
    final Tab currentTab = mock(Tab.class);
    final QueryPhasePane currentQueryPhasePane = mock(QueryPhasePane.class);
    final DataSourceTitledPane dataSourceTitledPane = mock(DataSourceTitledPane.class);
    final Plugin plugin = mock(Plugin.class);
    final PluginParameters pluginParameters = mock(PluginParameters.class);
    when(dataAccessPane.getDataAccessTabPane()).thenReturn(dataAccessTabPane);
    when(dataAccessTabPane.getCurrentTab()).thenReturn(currentTab);
    when(dataAccessTabPane.getQueryPhasePaneOfCurrentTab()).thenReturn(currentQueryPhasePane);
    when(currentQueryPhasePane.getDataAccessPanes()).thenReturn(List.of(dataSourceTitledPane));
    when(dataSourceTitledPane.getPlugin()).thenReturn(plugin);
    when(dataSourceTitledPane.getParameters()).thenReturn(pluginParameters);
    dataAccessPane.update((Graph) null);
    verify(plugin).updateParameters(null, pluginParameters);
    verify(dataAccessPane).update((String) null);
}
Also used : DataAccessTabPane(au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane) Tab(javafx.scene.control.Tab) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) Test(org.testng.annotations.Test)

Aggregations

Plugin (au.gov.asd.tac.constellation.plugins.Plugin)85 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)52 Test (org.testng.annotations.Test)43 Graph (au.gov.asd.tac.constellation.graph.Graph)24 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)19 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)14 SimplePlugin (au.gov.asd.tac.constellation.plugins.templates.SimplePlugin)10 PluginSynchronizer (au.gov.asd.tac.constellation.plugins.PluginSynchronizer)9 Future (java.util.concurrent.Future)9 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)8 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)8 PluginExecution (au.gov.asd.tac.constellation.plugins.PluginExecution)8 PluginGraphs (au.gov.asd.tac.constellation.plugins.PluginGraphs)8 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)7 CompletableFuture (java.util.concurrent.CompletableFuture)7 ExecutorService (java.util.concurrent.ExecutorService)7 ArrayList (java.util.ArrayList)6 Callable (java.util.concurrent.Callable)6 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)5 CopyToNewGraphPlugin (au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.CopyToNewGraphPlugin)5