Search in sources :

Example 41 with Plugin

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);
    }
}
Also used : RestServiceException(au.gov.asd.tac.constellation.webserver.restapi.RestServiceException) PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) SimpleEditPlugin(au.gov.asd.tac.constellation.plugins.templates.SimpleEditPlugin) Plugin(au.gov.asd.tac.constellation.plugins.Plugin)

Example 42 with Plugin

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);
    }
}
Also used : PluginParametersSwingDialog(au.gov.asd.tac.constellation.plugins.gui.PluginParametersSwingDialog) Graph(au.gov.asd.tac.constellation.graph.Graph) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) Plugin(au.gov.asd.tac.constellation.plugins.Plugin)

Example 43 with Plugin

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());
}
Also used : JsonIO(au.gov.asd.tac.constellation.utilities.genericjsonio.JsonIO) Serializable(java.io.Serializable) DataAccessPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane) QueryPhasePane(au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane) GlobalParametersPane(au.gov.asd.tac.constellation.views.dataaccess.panes.GlobalParametersPane) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FileInputStream(java.io.FileInputStream) DataAccessUserPreferences(au.gov.asd.tac.constellation.views.dataaccess.api.DataAccessUserPreferences) DataSourceTitledPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataSourceTitledPane) DataAccessTabPane(au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane) StringSubstitutor(org.apache.commons.text.StringSubstitutor) List(java.util.List) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) TypeReference(com.fasterxml.jackson.core.type.TypeReference) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) Test(org.testng.annotations.Test)

Example 44 with Plugin

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();
        }
    }
}
Also used : DataSourceTitledPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataSourceTitledPane) NotifyDescriptor(org.openide.NotifyDescriptor) DataAccessPreferenceUtilities(au.gov.asd.tac.constellation.views.dataaccess.utilities.DataAccessPreferenceUtilities) QueryPhasePane(au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane) NotifyDisplayer(au.gov.asd.tac.constellation.utilities.gui.NotifyDisplayer) Plugin(au.gov.asd.tac.constellation.plugins.Plugin)

Example 45 with Plugin

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());
    }
}
Also used : GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) CopyGraphUtilities(au.gov.asd.tac.constellation.graph.utilities.io.CopyGraphUtilities) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) IntegerParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.IntegerParameterType.IntegerParameterValue) SimpleEditPlugin(au.gov.asd.tac.constellation.plugins.templates.SimpleEditPlugin) ArrayList(java.util.ArrayList) Graph(au.gov.asd.tac.constellation.graph.Graph) Future(java.util.concurrent.Future) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) PluginParametersPane(au.gov.asd.tac.constellation.plugins.gui.PluginParametersPane) PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) PluginRegistry(au.gov.asd.tac.constellation.plugins.PluginRegistry) ExecutorService(java.util.concurrent.ExecutorService) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) SeparatorConstants(au.gov.asd.tac.constellation.utilities.text.SeparatorConstants) Set(java.util.Set) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) GraphRecordStoreUtilities(au.gov.asd.tac.constellation.graph.processing.GraphRecordStoreUtilities) PluginGraphs(au.gov.asd.tac.constellation.plugins.PluginGraphs) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) Executors(java.util.concurrent.Executors) PluginNotificationLevel(au.gov.asd.tac.constellation.plugins.PluginNotificationLevel) ExecutionException(java.util.concurrent.ExecutionException) GlobalParameters(au.gov.asd.tac.constellation.views.dataaccess.GlobalParameters) List(java.util.List) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) IntegerParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.IntegerParameterType) VisualSchemaPluginRegistry(au.gov.asd.tac.constellation.graph.schema.visual.VisualSchemaPluginRegistry) SimplePlugin(au.gov.asd.tac.constellation.plugins.templates.SimplePlugin) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) ArrayList(java.util.ArrayList) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) ExecutionException(java.util.concurrent.ExecutionException) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph)

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