Search in sources :

Example 1 with DataAccessPreQueryValidation

use of au.gov.asd.tac.constellation.views.dataaccess.templates.DataAccessPreQueryValidation 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)

Aggregations

GraphManager (au.gov.asd.tac.constellation.graph.manager.GraphManager)1 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)1 PluginExecution (au.gov.asd.tac.constellation.plugins.PluginExecution)1 PluginRegistry (au.gov.asd.tac.constellation.plugins.PluginRegistry)1 PluginSynchronizer (au.gov.asd.tac.constellation.plugins.PluginSynchronizer)1 PluginParametersPaneListener (au.gov.asd.tac.constellation.plugins.gui.PluginParametersPaneListener)1 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)1 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)1 DataAccessPaneState (au.gov.asd.tac.constellation.views.dataaccess.api.DataAccessPaneState)1 DataAccessPlugin (au.gov.asd.tac.constellation.views.dataaccess.plugins.DataAccessPlugin)1 DataAccessPreQueryValidation (au.gov.asd.tac.constellation.views.dataaccess.templates.DataAccessPreQueryValidation)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Future (java.util.concurrent.Future)1 Level (java.util.logging.Level)1