Search in sources :

Example 66 with PluginParameter

use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter in project constellation by constellation-app.

the class SelectTopNPlugin method createParameters.

@Override
public PluginParameters createParameters() {
    final PluginParameters params = new PluginParameters();
    final List<String> modes = new ArrayList<>();
    modes.add(NODE);
    modes.add(TRANSACTION);
    final PluginParameter<SingleChoiceParameterValue> modeParameter = SingleChoiceParameterType.build(MODE_PARAMETER_ID);
    modeParameter.setName("Mode");
    modeParameter.setDescription("Select either the Node or Transaction mode");
    SingleChoiceParameterType.setOptions(modeParameter, modes);
    params.addParameter(modeParameter);
    final PluginParameter<SingleChoiceParameterValue> typeCategoryParameter = SingleChoiceParameterType.build(TYPE_CATEGORY_PARAMETER_ID);
    typeCategoryParameter.setName("Type Category");
    typeCategoryParameter.setDescription("The high level type category");
    params.addParameter(typeCategoryParameter);
    final PluginParameter<MultiChoiceParameterValue> typeParameter = MultiChoiceParameterType.build(TYPE_PARAMETER_ID);
    typeParameter.setName("Specific Types");
    typeParameter.setDescription("The specific types to include when calculating the top N");
    params.addParameter(typeParameter);
    final PluginParameter<IntegerParameterValue> limitParameter = IntegerParameterType.build(LIMIT_PARAMETER_ID);
    limitParameter.setName("Limit");
    limitParameter.setDescription("The limit, default being 10");
    limitParameter.setIntegerValue(10);
    params.addParameter(limitParameter);
    params.addController(MODE_PARAMETER_ID, (PluginParameter<?> master, Map<String, PluginParameter<?>> parameters, ParameterChange change) -> {
        if (change == ParameterChange.VALUE) {
            final String mode = parameters.get(MODE_PARAMETER_ID).getStringValue();
            if (mode != null) {
                final List<String> types = new ArrayList<>();
                switch(mode) {
                    case NODE:
                        for (final SchemaVertexType type : SchemaVertexTypeUtilities.getTypes()) {
                            if (type.isTopLevelType()) {
                                types.add(type.getName());
                            }
                        }
                        break;
                    case TRANSACTION:
                        for (final SchemaTransactionType type : SchemaTransactionTypeUtilities.getTypes()) {
                            if (type.isTopLevelType()) {
                                types.add(type.getName());
                            }
                        }
                        break;
                    default:
                        LOGGER.severe("Invalid mode provided. Mode values accepted are " + NODE + " or " + TRANSACTION);
                }
                // TYPE_CATEGORY_PARAMETER will always be of type SingleChoiceParameter
                @SuppressWarnings("unchecked") final PluginParameter<SingleChoiceParameterValue> typeCategoryParamter = (PluginParameter<SingleChoiceParameterValue>) parameters.get(TYPE_CATEGORY_PARAMETER_ID);
                types.sort(String::compareTo);
                SingleChoiceParameterType.setOptions(typeCategoryParamter, types);
            }
        }
    });
    params.addController(TYPE_CATEGORY_PARAMETER_ID, (PluginParameter<?> master, Map<String, PluginParameter<?>> parameters, ParameterChange change) -> {
        if (change == ParameterChange.VALUE) {
            final String mode = parameters.get(MODE_PARAMETER_ID).getStringValue();
            final String typeCategory = parameters.get(TYPE_CATEGORY_PARAMETER_ID).getStringValue();
            if (mode != null && typeCategory != null) {
                final List<String> types = new ArrayList<>();
                switch(mode) {
                    case NODE:
                        final SchemaVertexType typeCategoryVertexType = SchemaVertexTypeUtilities.getType(typeCategory);
                        for (final SchemaVertexType type : SchemaVertexTypeUtilities.getTypes()) {
                            if (type.getSuperType().equals(typeCategoryVertexType)) {
                                types.add(type.getName());
                            }
                        }
                        break;
                    case TRANSACTION:
                        final SchemaTransactionType typeCategoryTransactionType = SchemaTransactionTypeUtilities.getType(typeCategory);
                        for (final SchemaTransactionType type : SchemaTransactionTypeUtilities.getTypes()) {
                            if (type.getSuperType().equals(typeCategoryTransactionType)) {
                                types.add(type.getName());
                            }
                        }
                        break;
                    default:
                        break;
                }
                // update the sub level types
                // TYPE_PARAMETER will always be of type MultiChoiceParameter
                @SuppressWarnings("unchecked") final PluginParameter<MultiChoiceParameterValue> typeParamter = (PluginParameter<MultiChoiceParameterValue>) parameters.get(TYPE_PARAMETER_ID);
                types.sort(String::compareTo);
                MultiChoiceParameterType.setOptions(typeParamter, types);
                MultiChoiceParameterType.setChoices(typeParamter, types);
            }
        }
    });
    return params;
}
Also used : ParameterChange(au.gov.asd.tac.constellation.plugins.parameters.ParameterChange) SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) ArrayList(java.util.ArrayList) SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) IntegerParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.IntegerParameterType.IntegerParameterValue) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue)

Example 67 with PluginParameter

use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter 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)

Example 68 with PluginParameter

use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter in project constellation by constellation-app.

the class TestParametersPluginNGTest method testCreateParametersGraphElementType2.

/**
 * Test of query method, of class TestParametersPlugin. Tests throwing
 * runtime exception
 */
@Test
public void testCreateParametersGraphElementType2() throws Exception {
    System.out.println("test CreateParameters graph element type2");
    final TestParametersPlugin instance = new TestParametersPlugin();
    final PluginParameters result = instance.createParameters();
    // Set plugin query name here before execution
    result.getParameters().get(CoreGlobalParameters.QUERY_NAME_PARAMETER_ID).setStringValue("TESTPARAMETERSPLUGIN");
    // Set plugin parameters here before execution
    final GraphElementTypeParameterValue graphElementType = new GraphElementTypeParameterValue();
    for (final GraphElementType elementType : GraphElementType.values()) {
        graphElementType.setObjectValue(elementType);
        result.getParameters().get(TestParametersPlugin.ELEMENT_TYPE_PARAMETER_ID).setObjectValue(graphElementType);
        // Ensure it is still selected as the correct value
        assertEquals(SingleChoiceParameterType.getChoice((PluginParameter<SingleChoiceParameterType.SingleChoiceParameterValue>) result.getParameters().get(TestParametersPlugin.ELEMENT_TYPE_PARAMETER_ID)), elementType.getShortLabel());
    }
}
Also used : SingleChoiceParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType) GraphElementTypeParameterValue(au.gov.asd.tac.constellation.views.dataaccess.plugins.experimental.TestParametersPlugin.GraphElementTypeParameterValue) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) Test(org.testng.annotations.Test)

Example 69 with PluginParameter

use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter in project constellation by constellation-app.

the class MergeNodesBySuffixNGTest method testUpdateParameters.

/**
 * Test of updateParameters method, of class MergeNodesBySuffix.
 */
@Test
public void testUpdateParameters() {
    System.out.println("testUpdateParameters");
    final MergeNodesBySuffix instance = new MergeNodesBySuffix();
    final PluginParameters parameters = new PluginParameters();
    final PluginParameter<BooleanParameterType.BooleanParameterValue> mergeTypeParameter = BooleanParameterType.build(MERGE_TYPE_PARAMETER_ID);
    parameters.addParameter(mergeTypeParameter);
    final PluginParameter<IntegerParameterType.IntegerParameterValue> thresholdParameter = IntegerParameterType.build(THRESHOLD_PARAMETER_ID);
    parameters.addParameter(thresholdParameter);
    final PluginParameter<BooleanParameterType.BooleanParameterValue> mergeParameter = BooleanParameterType.build(MERGER_PARAMETER_ID);
    parameters.addParameter(mergeParameter);
    final PluginParameter<BooleanParameterType.BooleanParameterValue> leadParameter = BooleanParameterType.build(LEAD_PARAMETER_ID);
    parameters.addParameter(leadParameter);
    final PluginParameter<BooleanParameterType.BooleanParameterValue> selectedParameter = BooleanParameterType.build(SELECTED_PARAMETER_ID);
    parameters.addParameter(selectedParameter);
    final Map<String, PluginParameter<?>> parametersMap = parameters.getParameters();
    instance.updateParameters(parametersMap);
    assertEquals(parametersMap.size(), 5);
    assertTrue(parametersMap.get(MERGE_TYPE_PARAMETER_ID).isEnabled());
    assertTrue(parametersMap.get(THRESHOLD_PARAMETER_ID).isEnabled());
    assertEquals(parametersMap.get(THRESHOLD_PARAMETER_ID).getDescription(), "The suffix length to consider");
    assertEquals(parametersMap.get(THRESHOLD_PARAMETER_ID).getIntegerValue(), 9);
    assertTrue(parametersMap.get(MERGER_PARAMETER_ID).isEnabled());
    assertTrue(parametersMap.get(LEAD_PARAMETER_ID).isEnabled());
    assertTrue(parametersMap.get(SELECTED_PARAMETER_ID).isEnabled());
}
Also used : PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) Test(org.testng.annotations.Test)

Example 70 with PluginParameter

use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter in project constellation by constellation-app.

the class MergeNodesPluginNGTest method edit.

@Test
public void edit() throws InterruptedException, PluginException, MergeNodeType.MergeException {
    final GraphWriteMethods graph = mock(GraphWriteMethods.class);
    final PluginInteraction interaction = mock(PluginInteraction.class);
    final PluginParameters parameters = mock(PluginParameters.class);
    final PluginExecution pluginExecution = mock(PluginExecution.class);
    final PluginParameter mergeTypeParameter = mock(PluginParameter.class);
    final PluginParameter thresholdParameter = mock(PluginParameter.class);
    final PluginParameter mergerParameter = mock(PluginParameter.class);
    final PluginParameter leadParameter = mock(PluginParameter.class);
    final PluginParameter selectedParameter = mock(PluginParameter.class);
    final Map<String, PluginParameter<?>> pluginParameters = Map.of("MergeNodesPlugin.merge_type", mergeTypeParameter, "MergeNodesPlugin.threshold", thresholdParameter, "MergeNodesPlugin.merger", mergerParameter, "MergeNodesPlugin.lead", leadParameter, "MergeNodesPlugin.selected", selectedParameter);
    when(parameters.getParameters()).thenReturn(pluginParameters);
    when(mergeTypeParameter.getStringValue()).thenReturn(TestMergeType.NAME);
    when(thresholdParameter.getIntegerValue()).thenReturn(TestMergeType.MERGE_SUCCESS_THRESHOLD);
    when(mergerParameter.getStringValue()).thenReturn("Retain lead vertex attributes if present");
    when(leadParameter.getStringValue()).thenReturn("Longest Value");
    when(selectedParameter.getBooleanValue()).thenReturn(true);
    doReturn(null).when(pluginExecution).executeNow(graph);
    try (MockedStatic<PluginExecution> pluginExecutionMockedStatic = Mockito.mockStatic(PluginExecution.class)) {
        pluginExecutionMockedStatic.when(() -> PluginExecution.withPlugin(VisualSchemaPluginRegistry.COMPLETE_SCHEMA)).thenReturn(pluginExecution);
        mergeNodesPlugin.edit(graph, interaction, parameters);
        verify(pluginExecution).executeNow(graph);
        verify(interaction).setProgress(1, 0, "Merged 2 nodes.", true);
    // Due to accessibility issues the call to mergeVerticies and its follow
    // on logic cannot be verified without tying this test to the logic of
    // one of the concrete implementations of GraphElementMerger.
    }
}
Also used : PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) Test(org.testng.annotations.Test)

Aggregations

PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)93 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)53 Test (org.testng.annotations.Test)52 ArrayList (java.util.ArrayList)36 MultiChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue)25 SingleChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue)21 Map (java.util.Map)16 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)15 IntegerParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.IntegerParameterType.IntegerParameterValue)13 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)12 SchemaTransactionType (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType)11 ParameterChange (au.gov.asd.tac.constellation.plugins.parameters.ParameterChange)11 Graph (au.gov.asd.tac.constellation.graph.Graph)10 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)10 BooleanParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType.BooleanParameterValue)10 HashMap (java.util.HashMap)10 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)9 List (java.util.List)9 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)8 StringParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.StringParameterValue)8