use of au.gov.asd.tac.constellation.plugins.Plugin in project constellation by constellation-app.
the class SetGraphValues method setGraphAttributes.
private static void setGraphAttributes(final Graph graph, final ArrayNode columns, final ArrayNode row) {
final Plugin p = new SetGraphAttributesFromRestApiPlugin(columns, row);
final PluginExecution pe = PluginExecution.withPlugin(p);
try {
pe.executeNow(graph);
} catch (final InterruptedException ex) {
Thread.currentThread().interrupt();
throw new RestServiceException(ex);
} catch (final PluginException ex) {
throw new RestServiceException(ex);
}
}
use of au.gov.asd.tac.constellation.plugins.Plugin in project constellation by constellation-app.
the class LayerByTimeAction method actionPerformed.
@Override
public void actionPerformed(final ActionEvent ev) {
final Plugin plugin = PluginRegistry.get(ArrangementPluginRegistry.TIME);
final PluginParameters params = plugin.createParameters();
final Graph graph = context.getGraph();
plugin.updateParameters(graph, params);
final PluginParametersSwingDialog dialog = new PluginParametersSwingDialog(Bundle.CTL_LayerByTimeAction(), params);
dialog.showAndWait();
if (PluginParametersDialog.OK.equals(dialog.getResult())) {
PluginExecution.withPlugin(plugin).withParameters(params).executeLater(graph);
}
}
use of au.gov.asd.tac.constellation.plugins.Plugin 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());
}
use of au.gov.asd.tac.constellation.plugins.Plugin in project constellation by constellation-app.
the class ButtonToolbarNGTest method verifyManageFavouritesWithUserInput.
/**
* Verifies that when manage favourites is called, depending on the user
* action against the dialog, different outcomes will occur.
*
* @param pluginTitle the plugin title of the only selected pane that is
* enabled
* @param selectedOption the option that the user selection in the dialog
* @param preferenceUtilsVerification the verification against
* {@link DataAccessPreferenceUtilities}
*/
private void verifyManageFavouritesWithUserInput(final String pluginTitle, final Object selectedOption, final Verification preferenceUtilsVerification) {
final DataAccessTabPane dataAccessTabPane = mock(DataAccessTabPane.class);
final QueryPhasePane currentQueryPhasePane = mock(QueryPhasePane.class);
final DataSourceTitledPane dataSourceTitledPane1 = mock(DataSourceTitledPane.class);
final DataSourceTitledPane dataSourceTitledPane2 = mock(DataSourceTitledPane.class);
final Plugin plugin = mock(Plugin.class);
when(dataAccessPane.getDataAccessTabPane()).thenReturn(dataAccessTabPane);
when(dataAccessTabPane.getQueryPhasePaneOfCurrentTab()).thenReturn(currentQueryPhasePane);
when(currentQueryPhasePane.getDataAccessPanes()).thenReturn(List.of(dataSourceTitledPane1, dataSourceTitledPane2));
when(dataSourceTitledPane1.isQueryEnabled()).thenReturn(false);
when(dataSourceTitledPane2.isQueryEnabled()).thenReturn(true);
when(dataSourceTitledPane2.getPlugin()).thenReturn(plugin);
when(plugin.getName()).thenReturn(pluginTitle);
try (final MockedStatic<NotifyDisplayer> notifyDisplayerMockedStatic = Mockito.mockStatic(NotifyDisplayer.class);
final MockedStatic<DataAccessPreferenceUtilities> prefUtilsMockedStatic = Mockito.mockStatic(DataAccessPreferenceUtilities.class)) {
notifyDisplayerMockedStatic.when(() -> NotifyDisplayer.displayAndWait(any(NotifyDescriptor.class))).thenAnswer(iom -> {
final NotifyDescriptor descriptor = iom.getArgument(0);
final String expectedMessage = "Add or remove plugins from your favourites category.\n\n" + "The following plugins were selected:\n" + pluginTitle + "\n" + "\nNote that you need to restart before changes take effect.";
assertEquals(descriptor.getMessage(), expectedMessage);
assertEquals(descriptor.getTitle(), "Manage Favourites");
assertEquals(descriptor.getOptionType(), NotifyDescriptor.DEFAULT_OPTION);
assertEquals(descriptor.getMessageType(), NotifyDescriptor.QUESTION_MESSAGE);
assertEquals(descriptor.getOptions(), new Object[] { "Add", "Remove", NotifyDescriptor.CANCEL_OPTION });
assertEquals(descriptor.getValue(), NotifyDescriptor.OK_OPTION);
// Simulating the value returned when the function is called on the FX thread
return CompletableFuture.completedFuture(CompletableFuture.completedFuture(selectedOption));
});
buttonToolbar.manageFavourites();
if (preferenceUtilsVerification != null) {
prefUtilsMockedStatic.verify(preferenceUtilsVerification);
} else {
prefUtilsMockedStatic.verifyNoInteractions();
}
}
}
use of au.gov.asd.tac.constellation.plugins.Plugin in project constellation by constellation-app.
the class WorkflowQueryPlugin method execute.
@Override
protected void execute(final PluginGraphs pluginGraphs, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
final Graph graph = pluginGraphs.getGraph();
final ReadableGraph readableGraph = graph.getReadableGraph();
// buildId batches
try {
queryBatches = GraphRecordStoreUtilities.getSelectedVerticesBatches(readableGraph, parameters.getIntegerValue(BATCH_SIZE_PARAMETER_ID));
} finally {
readableGraph.release();
}
pluginGraphs.waitAtGate(1);
// create a service for executing jobs, limiting concurrent executions to the max concurrent plugins parameter.
final int maxConcurrentPlugins = parameters.getIntegerValue(MAX_CONCURRENT_PLUGINS_PARAMETER_ID);
final ExecutorService workflowExecutor = Executors.newFixedThreadPool(maxConcurrentPlugins);
// schedule a job for each batch, where the job is to execute the defined workflow
final List<Future<?>> workerPlugins = new ArrayList<>();
final List<PluginException> exceptions = new ArrayList<>();
if (queryBatches.isEmpty()) {
queryBatches.add(new GraphRecordStore());
}
// run plugin once for every batch record store
queryBatches.forEach(batch -> {
final StoreGraph batchGraph = new StoreGraph(graph.getSchema() != null ? graph.getSchema().getFactory().createSchema() : null);
batchGraph.getSchema().newGraph(batchGraph);
CopyGraphUtilities.copyGraphTypeElements(readableGraph, batchGraph);
GraphRecordStoreUtilities.addRecordStoreToGraph(batchGraph, batch, true, true, null);
final WorkerQueryPlugin worker = new WorkerQueryPlugin(getWorkflow(), batchGraph, exceptions, getErrorHandlingPlugin(), addPartialResults());
workerPlugins.add(workflowExecutor.submit(() -> {
Thread.currentThread().setName(THREAD_POOL_NAME);
try {
PluginExecution.withPlugin(worker).withParameters(parameters).executeNow(graph);
} catch (InterruptedException | PluginException ex) {
throw new RuntimeException(ex);
}
}));
});
final int[] workerFailCount = { 0 };
for (Future<?> worker : workerPlugins) {
try {
worker.get();
} catch (InterruptedException ex) {
workerPlugins.forEach(workerToInterrupt -> workerToInterrupt.cancel(true));
throw ex;
} catch (ExecutionException ex) {
workerFailCount[0]++;
}
}
workflowExecutor.shutdown();
// if there were any errors, collect them and display them to the user
if (!exceptions.isEmpty()) {
final StringBuilder entireException = new StringBuilder();
entireException.append(workerFailCount[0]).append(" workers failed.").append(SeparatorConstants.NEWLINE);
exceptions.forEach(ex -> entireException.append(ex.getMessage()).append(SeparatorConstants.NEWLINE));
throw new PluginException(PluginNotificationLevel.ERROR, entireException.toString());
}
}
Aggregations