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;
}
Aggregations