Search in sources :

Example 1 with DataAccessPlugin

use of au.gov.asd.tac.constellation.views.dataaccess.plugins.DataAccessPlugin in project constellation by constellation-app.

the class DataAccessPaneStateNGTest method dataAccessPluginComparator.

@Test
public void dataAccessPluginComparator() {
    try (final MockedStatic<DataAccessPluginType> dataAccessPluginTypeMockedStatic = Mockito.mockStatic(DataAccessPluginType.class)) {
        dataAccessPluginTypeMockedStatic.when(DataAccessPluginType::getTypeWithPosition).thenReturn(Map.of("type1", 1, "type2", 2, "type3", 2, "type4", 3));
        final DataAccessPaneState.DataAccessPluginComparator comparator = new DataAccessPaneState.DataAccessPluginComparator();
        final DataAccessPlugin plugin1 = mock(DataAccessPlugin.class);
        final DataAccessPlugin plugin2 = mock(DataAccessPlugin.class);
        // TYPE POSITION EQUAL
        when(plugin1.getType()).thenReturn("type2");
        when(plugin2.getType()).thenReturn("type3");
        when(plugin1.getPosition()).thenReturn(1);
        when(plugin2.getPosition()).thenReturn(2);
        assertTrue(comparator.compare(plugin1, plugin2) < 0);
        when(plugin1.getPosition()).thenReturn(2);
        when(plugin2.getPosition()).thenReturn(1);
        assertTrue(comparator.compare(plugin1, plugin2) > 0);
        when(plugin1.getPosition()).thenReturn(1);
        when(plugin2.getPosition()).thenReturn(1);
        assertTrue(comparator.compare(plugin1, plugin2) == 0);
        // TYPE POSITION NOT EQUAL
        when(plugin1.getType()).thenReturn("type1");
        when(plugin2.getType()).thenReturn("type4");
        assertTrue(comparator.compare(plugin1, plugin2) < 0);
        when(plugin1.getType()).thenReturn("type4");
        when(plugin2.getType()).thenReturn("type1");
        assertTrue(comparator.compare(plugin1, plugin2) > 0);
    }
}
Also used : DataAccessPlugin(au.gov.asd.tac.constellation.views.dataaccess.plugins.DataAccessPlugin) DataAccessPluginType(au.gov.asd.tac.constellation.views.dataaccess.plugins.DataAccessPluginType) Test(org.testng.annotations.Test)

Example 2 with DataAccessPlugin

use of au.gov.asd.tac.constellation.views.dataaccess.plugins.DataAccessPlugin in project constellation by constellation-app.

the class LookupPluginsTaskNGTest method get.

@Test
public void get() {
    try (final MockedStatic<DataAccessPluginType> dapTypeMockedStatic = Mockito.mockStatic(DataAccessPluginType.class);
        final MockedStatic<Lookup> lookupMockedStatic = Mockito.mockStatic(Lookup.class)) {
        dapTypeMockedStatic.when(DataAccessPluginType::getTypes).thenReturn(List.of(DataAccessPluginCoreType.DEVELOPER, DataAccessPluginCoreType.UTILITY));
        final Lookup defaultLookup = mock(Lookup.class);
        lookupMockedStatic.when(Lookup::getDefault).thenReturn(defaultLookup);
        // All of the mock creations are being coupled with an interface to
        // force the getClass() call on them to be different
        // Plugin 1 is disabled and so will be ignored
        final DataAccessPlugin plugin1 = mock(DataAccessPlugin.class, withSettings().extraInterfaces(DataAccessPluginType.class));
        when(plugin1.isEnabled()).thenReturn(false);
        // Plugin 2 is of a type that is not in the listed types above, so
        // it will be ignored
        final DataAccessPlugin plugin2 = mock(DataAccessPlugin.class, withSettings().extraInterfaces(DataAccessPreQueryValidation.class));
        when(plugin2.isEnabled()).thenReturn(true);
        when(plugin2.getType()).thenReturn(DataAccessPluginCoreType.IMPORT);
        // Plugin 3 is a favourite and should be present in the favourite list
        final DataAccessPlugin plugin3 = mock(DataAccessPlugin.class, withSettings().extraInterfaces(MergeNodeType.class));
        when(plugin3.isEnabled()).thenReturn(true);
        when(plugin3.getType()).thenReturn(DataAccessPluginCoreType.DEVELOPER);
        when(plugin3.getName()).thenReturn("Plugin 3");
        DataAccessPreferenceUtilities.setFavourite("Plugin 3", true);
        when(plugin3.getOverriddenPlugins()).thenReturn(Collections.emptyList());
        // Plugin 4 will be present but not a favourite
        final DataAccessPlugin plugin4 = mock(DataAccessPlugin.class, withSettings().extraInterfaces(MergeTransactionType.class));
        when(plugin4.isEnabled()).thenReturn(true);
        when(plugin4.getType()).thenReturn(DataAccessPluginCoreType.UTILITY);
        when(plugin4.getName()).thenReturn("Plugin 4");
        // Overriden by plugin 4 so should not be present in the returned map
        final DataAccessPlugin plugin5 = mock(DataAccessPlugin.class, withSettings().extraInterfaces(Comparable.class));
        when(plugin5.isEnabled()).thenReturn(true);
        when(plugin5.getType()).thenReturn(DataAccessPluginCoreType.DEVELOPER);
        when(plugin5.getName()).thenReturn("Plugin 5");
        when(plugin5.getOverriddenPlugins()).thenReturn(Collections.emptyList());
        // Overriden by plugin 4 so should not be present in the returned map
        final DataAccessPlugin plugin6 = mock(DataAccessPlugin.class, withSettings().extraInterfaces(Serializable.class));
        when(plugin6.isEnabled()).thenReturn(true);
        when(plugin6.getType()).thenReturn(DataAccessPluginCoreType.DEVELOPER);
        when(plugin6.getName()).thenReturn("Plugin 6");
        when(plugin6.getOverriddenPlugins()).thenReturn(Collections.emptyList());
        // Plugin 4 overrides plugin 5 and plugin 6
        when(plugin4.getOverriddenPlugins()).thenReturn(List.of(plugin5.getClass().getName(), plugin6.getClass().getName()));
        doReturn(List.of(plugin1, plugin2, plugin3, plugin4, plugin5, plugin6)).when(defaultLookup).lookupAll(DataAccessPlugin.class);
        final Map<String, List<DataAccessPlugin>> expectedPlugins = Map.of("Developer", List.of(plugin3), "Utility", List.of(plugin4), "Favourites", List.of(plugin3));
        assertEquals(new LookupPluginsTask().get(), expectedPlugins);
    }
}
Also used : Serializable(java.io.Serializable) DataAccessPlugin(au.gov.asd.tac.constellation.views.dataaccess.plugins.DataAccessPlugin) DataAccessPreQueryValidation(au.gov.asd.tac.constellation.views.dataaccess.templates.DataAccessPreQueryValidation) Lookup(org.openide.util.Lookup) MergeNodeType(au.gov.asd.tac.constellation.views.dataaccess.plugins.clean.MergeNodeType) List(java.util.List) DataAccessPluginType(au.gov.asd.tac.constellation.views.dataaccess.plugins.DataAccessPluginType) MergeTransactionType(au.gov.asd.tac.constellation.views.dataaccess.plugins.clean.MergeTransactionType) Test(org.testng.annotations.Test)

Example 3 with DataAccessPlugin

use of au.gov.asd.tac.constellation.views.dataaccess.plugins.DataAccessPlugin in project constellation by constellation-app.

the class PluginsNodeProvider method setContent.

@Override
public void setContent(final Tab tab) {
    final Map<String, String> pluginNames = new TreeMap<>();
    final Map<String, ObservableList<PluginParameter<?>>> pluginParameters = new HashMap<>();
    final Map<String, String> dataAccessTypes = new HashMap<>();
    // Get plugins in order of description.
    PluginRegistry.getPluginClassNames().stream().forEach(pluginClassName -> {
        boolean isEnabled = true;
        final Plugin plugin = PluginRegistry.get(pluginClassName);
        final String pluginName = plugin.getName();
        if (plugin instanceof DataAccessPlugin) {
            final DataAccessPlugin dataAccessPlugin = (DataAccessPlugin) plugin;
            final String dataAccessType = dataAccessPlugin.getType();
            isEnabled = dataAccessPlugin.isEnabled();
            if (isEnabled && !dataAccessType.equals(DataAccessPluginCoreType.EXPERIMENTAL) && !dataAccessType.equals(DataAccessPluginCoreType.DEVELOPER)) {
                dataAccessTypes.put(pluginName != null ? pluginName : pluginClassName, dataAccessType);
            }
        }
        if (isEnabled) {
            if (pluginName == null) {
                LOGGER.log(Level.WARNING, "null name for plugin %s{0}", pluginClassName);
            } else if (pluginNames.containsKey(pluginName)) {
                LOGGER.log(Level.WARNING, "duplicate name {0} for plugins {1}, {2}", new Object[] { pluginName, pluginClassName, pluginNames.get(pluginName) });
            } else {
            // Do nothing
            }
            pluginNames.put(pluginName != null ? pluginName : pluginClassName, pluginClassName);
            try {
                final PluginParameters parameters = plugin.createParameters();
                if (parameters != null) {
                    final ObservableList<PluginParameter<?>> parameterList = FXCollections.observableArrayList();
                    parameters.getParameters().entrySet().stream().forEach(entry -> {
                        final PluginParameter<?> parameter = entry.getValue();
                        parameterList.add(parameter);
                    });
                    Collections.sort(parameterList, (a, b) -> a.getId().compareToIgnoreCase(b.getId()));
                    pluginParameters.put(pluginName != null ? pluginName : pluginClassName, parameterList);
                }
            } catch (final Exception ex) {
                LOGGER.log(Level.SEVERE, "plugin " + pluginClassName + " created an exception", ex);
            }
        }
    });
    final Accordion pluginList = new Accordion();
    pluginNames.entrySet().stream().forEach(entry -> {
        final String pluginName = entry.getKey();
        final String pluginClassName = entry.getValue();
        final GridPane grid = new GridPane();
        grid.setPadding(new Insets(0, 0, 0, 5));
        grid.setHgap(5);
        grid.setVgap(10);
        grid.add(boldLabel("Name"), 0, 0);
        grid.add(new Label(pluginClassName), 1, 0);
        grid.add(boldLabel("Alias"), 0, 1);
        grid.add(new Label(PluginRegistry.getAlias(pluginClassName)), 1, 1);
        if (PluginRegistry.get(pluginClassName).getDescription() != null) {
            grid.add(boldLabel("Description"), 0, 2);
            final Label description = new Label(PluginRegistry.get(pluginClassName).getDescription());
            description.setPrefHeight(Region.USE_PREF_SIZE);
            description.setWrapText(true);
            grid.add(description, 1, 2);
        }
        final VBox pluginContent = new VBox();
        if (pluginParameters.containsKey(pluginName)) {
            grid.add(boldLabel("Parameters"), 0, 3);
            final TableColumn<PluginParameter<?>, String> colName = new TableColumn<>("Name");
            colName.setCellValueFactory(p -> new SimpleStringProperty(p.getValue().getId()));
            final TableColumn<PluginParameter<?>, String> colType = new TableColumn<>("Type");
            colType.setCellValueFactory(p -> new SimpleStringProperty(p.getValue().getType().getId()));
            final TableColumn<PluginParameter<?>, String> colLabel = new TableColumn<>("Label");
            colLabel.setCellValueFactory(p -> new SimpleStringProperty(p.getValue().getName()));
            final TableColumn<PluginParameter<?>, String> colDescr = new TableColumn<>("Description");
            colDescr.setCellValueFactory(p -> new SimpleStringProperty(p.getValue().getDescription()));
            final TableColumn<PluginParameter<?>, String> colDefault = new TableColumn<>("Default Value");
            colDefault.setCellValueFactory(p -> new SimpleStringProperty(p.getValue().getStringValue()));
            final TableView<PluginParameter<?>> parameterTable = new TableView<>(pluginParameters.get(pluginName));
            parameterTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
            parameterTable.getColumns().addAll(colName, colType, colLabel, colDescr, colDefault);
            parameterTable.setFixedCellSize(25);
            parameterTable.prefHeightProperty().bind(parameterTable.fixedCellSizeProperty().multiply(Bindings.size(parameterTable.getItems()).add(1.01)));
            parameterTable.minHeightProperty().bind(parameterTable.prefHeightProperty());
            parameterTable.maxHeightProperty().bind(parameterTable.prefHeightProperty());
            pluginContent.getChildren().add(grid);
            pluginContent.getChildren().add(parameterTable);
        } else {
            pluginContent.getChildren().add(grid);
        }
        final TitledPane pluginPane = new TitledPane(pluginName, pluginContent);
        if (dataAccessTypes.containsKey(pluginName)) {
            final ImageView iv = new ImageView(UserInterfaceIconProvider.VISIBLE.buildImage(16, ConstellationColor.CLOUDS.getJavaColor()));
            final Label l = new Label(String.format("(%s)", dataAccessTypes.get(pluginName)));
            final HBox box = new HBox(iv, l);
            pluginPane.setGraphic(box);
            pluginPane.setGraphicTextGap(20);
            pluginPane.setContentDisplay(ContentDisplay.RIGHT);
        }
        pluginList.getPanes().add(pluginPane);
    });
    final Button exportPluginsButton = new Button();
    exportPluginsButton.setTooltip(new Tooltip("Export Plugin Details to CSV"));
    exportPluginsButton.setGraphic(new ImageView(UserInterfaceIconProvider.DOWNLOAD.buildImage(16, ConstellationColor.CLOUDS.getJavaColor())));
    exportPluginsButton.setOnAction(action -> exportPluginsToCsv(tab.getContent().getScene().getWindow()));
    Platform.runLater(() -> {
        pane.setAlignment(Pos.TOP_RIGHT);
        final ScrollPane scrollPane = new ScrollPane();
        scrollPane.setContent(pluginList);
        scrollPane.setFitToWidth(true);
        pane.getChildren().add(exportPluginsButton);
        pane.getChildren().add(scrollPane);
        tab.setContent(pane);
    });
}
Also used : HBox(javafx.scene.layout.HBox) Insets(javafx.geometry.Insets) HashMap(java.util.HashMap) Label(javafx.scene.control.Label) Button(javafx.scene.control.Button) DataAccessPlugin(au.gov.asd.tac.constellation.views.dataaccess.plugins.DataAccessPlugin) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) ImageView(javafx.scene.image.ImageView) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) TableView(javafx.scene.control.TableView) TitledPane(javafx.scene.control.TitledPane) GridPane(javafx.scene.layout.GridPane) Tooltip(javafx.scene.control.Tooltip) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) TreeMap(java.util.TreeMap) TableColumn(javafx.scene.control.TableColumn) IOException(java.io.IOException) Accordion(javafx.scene.control.Accordion) ObservableList(javafx.collections.ObservableList) ScrollPane(javafx.scene.control.ScrollPane) VBox(javafx.scene.layout.VBox) DataAccessPlugin(au.gov.asd.tac.constellation.views.dataaccess.plugins.DataAccessPlugin) Plugin(au.gov.asd.tac.constellation.plugins.Plugin)

Aggregations

DataAccessPlugin (au.gov.asd.tac.constellation.views.dataaccess.plugins.DataAccessPlugin)3 DataAccessPluginType (au.gov.asd.tac.constellation.views.dataaccess.plugins.DataAccessPluginType)2 Test (org.testng.annotations.Test)2 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)1 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)1 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)1 MergeNodeType (au.gov.asd.tac.constellation.views.dataaccess.plugins.clean.MergeNodeType)1 MergeTransactionType (au.gov.asd.tac.constellation.views.dataaccess.plugins.clean.MergeTransactionType)1 DataAccessPreQueryValidation (au.gov.asd.tac.constellation.views.dataaccess.templates.DataAccessPreQueryValidation)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 HashMap (java.util.HashMap)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)1 ObservableList (javafx.collections.ObservableList)1 Insets (javafx.geometry.Insets)1 Accordion (javafx.scene.control.Accordion)1 Button (javafx.scene.control.Button)1 Label (javafx.scene.control.Label)1