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;
}
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;
}
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());
}
}
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());
}
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.
}
}
Aggregations