use of org.knime.core.node.dialog.ExternalNodeData in project knime-core by knime.
the class WorkflowManager method getExternalNodeDataHandles.
/**
* Implementation of {@link #getInputNodes()} and {@link #getExternalOutputs()}.
*
* @param nodeModelClass either {@link InputNode}.class or {@link OutputNode}.class.
* @param retriever resolves the data object from the input or output.
* @return List of nodes with their parameter names unified.
*/
// package scope for tests
<T> List<ExternalNodeDataHandle> getExternalNodeDataHandles(final Class<T> nodeModelClass, final Function<T, ExternalNodeData> retriever) {
List<ExternalNodeDataHandle> result = new ArrayList<>();
try (WorkflowLock lock = lock()) {
Map<NodeID, T> externalNodeDataMap = findNodes(nodeModelClass, NodeModelFilter.all(), true, true);
// get all "parameter names" from all nodes in the workflow in order to see if there are name conflicts;
// occurrence map like {"string-input" -> 1, "foo" -> 1, "bar" -> 3}
Map<String, Long> parameterNamesToCountMap = externalNodeDataMap.values().stream().map(retriever).map(extNodeData -> extNodeData.getID()).collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
parameterNamesToCountMap.values().removeAll(Collections.singleton(Long.valueOf(1L)));
Set<String> nonUniqueParameterNames = parameterNamesToCountMap.keySet();
if (!nonUniqueParameterNames.isEmpty()) {
LOGGER.warnWithFormat("Workflow contains nodes with duplicate parameter name " + "(will be made unique by appending node IDs): %s", ConvenienceMethods.getShortStringFrom(nonUniqueParameterNames, 5));
}
// create result list, make keys unique where needed but also retain the fully qualified parameter name
for (Map.Entry<NodeID, T> entry : externalNodeDataMap.entrySet()) {
NodeID nodeID = entry.getKey();
ExternalNodeData nodeData = retriever.apply(entry.getValue());
String parameterNameShort = nodeData.getID();
// this ID = 0:3, nodeID = 0:3:5:0:2:2 => nodeIDRelativePath = 5:0:2:2
String nodeIDRelativePath = StringUtils.removeStart(nodeID.toString(), getID().toString() + ":");
// nodeIDRelativePath = 5:0:2:2 --> 5:2:2 (':0' are internals of a subnode)
nodeIDRelativePath = StringUtils.remove(nodeIDRelativePath, ":0");
String parameterNameFullyQualified = (parameterNameShort.isEmpty() ? "" : parameterNameShort + "-") + nodeIDRelativePath;
if (nonUniqueParameterNames.contains(parameterNameShort)) {
parameterNameShort = parameterNameFullyQualified;
}
result.add(new ExternalNodeDataHandle(parameterNameShort, parameterNameFullyQualified, (NativeNodeContainer) findNodeContainer(nodeID), nodeData));
}
return result;
}
}
use of org.knime.core.node.dialog.ExternalNodeData in project knime-core by knime.
the class OpenAPIDefinitionGenerator method createParametersDescription.
private static JsonObject createParametersDescription(final Map<String, ExternalNodeData> nodes) {
JsonObjectBuilder root = Json.createObjectBuilder();
if (!nodes.isEmpty()) {
JsonObjectBuilder properties = Json.createObjectBuilder();
for (Map.Entry<String, ExternalNodeData> e : nodes.entrySet()) {
if (e.getValue().getJSONValue() != null) {
JsonObjectBuilder input = translateToSchema(e.getValue().getJSONValue());
e.getValue().getDescription().ifPresent(d -> input.add("description", d));
input.add("example", e.getValue().getJSONValue());
properties.add(e.getKey(), input);
}
}
root.add("type", "object");
root.add("properties", properties);
}
return root.build();
}
use of org.knime.core.node.dialog.ExternalNodeData in project knime-core by knime.
the class TestSRV559_RecursiveInputNodesViaREST method testListExternalDataNodes.
@Test
public void testListExternalDataNodes() throws Exception {
assumeRunOnlyOnce();
WorkflowManager manager = getManager();
executeAllAndWait();
Map<String, ExternalNodeData> inputNodes = manager.getInputNodes();
assertThat("Wrong number inputs", inputNodes.size(), is(4));
assertThat("Input parameter list wrong", inputNodes.keySet(), containsInAnyOrder("top-level-string-input-1", "top-level-credentials-input-2", "metanode-level-string-input-21:10", "metanode-level-credentials-input-21:11"));
ExternalNodeData topLevelStringInputData = inputNodes.get("top-level-string-input-1");
assertThat(topLevelStringInputData.getJSONValue().toString(), is("\"foo\""));
ExternalNodeData topLevelCredInputData = inputNodes.get("top-level-credentials-input-2");
assertThat(topLevelCredInputData.getJSONValue(), is(toJson("{\"username\":\"foo-login\", \"password\":null}")));
ExternalNodeData metanodeLevelStringInputData = inputNodes.get("metanode-level-string-input-21:10");
assertThat(metanodeLevelStringInputData.getJSONValue().toString(), is("\"foo\""));
ExternalNodeData metanodeLevelCredInputData = inputNodes.get("metanode-level-credentials-input-21:11");
assertThat(metanodeLevelCredInputData.getJSONValue(), is(toJson("{\"username\":\"foo-login\",\"password\":null}")));
Map<String, ExternalNodeData> outputs = manager.getExternalOutputs();
assertThat(outputs.size(), is(2));
assertThat(outputs.keySet(), containsInAnyOrder("top-level-json-output-7", "metanode-level-json-output-21:16"));
ExternalNodeData outputDataTopLevel = outputs.get("top-level-json-output-7");
assertThat(outputDataTopLevel.getID(), is("top-level-json-output"));
assertThat(outputDataTopLevel.getJSONValue(), is(toJson("{\"top-level-string-input\":\"foo\", \"metanode-level-string-input\":\"foo\"}")));
ExternalNodeData outputDataMetanodeLevel = outputs.get("metanode-level-json-output-21:16");
assertThat(outputDataMetanodeLevel.getID(), is("metanode-level-json-output"));
assertThat(outputDataMetanodeLevel.getJSONValue(), is(toJson("{\"metanode-level-string-input\":\"foo\"}")));
}
use of org.knime.core.node.dialog.ExternalNodeData in project knime-core by knime.
the class TestSRV559_RecursiveInputNodesViaREST method testSetInvalidViaJSON.
@Test(expected = InvalidSettingsException.class)
public void testSetInvalidViaJSON() throws Exception {
WorkflowManager manager = getManager();
// should work either way - executed or not
executeAllAndWait();
Map<String, ExternalNodeData> inputMap = new HashMap<>();
final String stringInputKey = m_useSuffix ? "top-level-string-input-1" : "top-level-string-input";
final String credsInputKey = m_useSuffix ? "top-level-credentials-input-2" : "top-level-credentials-input";
inputMap.put(stringInputKey, ExternalNodeData.builder(stringInputKey).jsonValue(toJson("{\"string\":\"valid\"}")).build());
inputMap.put(credsInputKey, ExternalNodeData.builder(credsInputKey).jsonValue(toJson("{\"username\":\"bar-login\", \"password\":\"bar-password\"}")).build());
manager.setInputNodes(inputMap);
}
Aggregations