use of org.knime.core.node.dialog.InputNode in project knime-core by knime.
the class WorkflowManager method setInputNodes.
/**
* Counterpart to {@link #getInputNodes()} - it sets new values into input nodes on the root level. All nodes as per
* map argument will be reset as part of this call.
*
* @param input a map from node's parameter name to its (JSON or string object value). Invalid entries cause an
* exception.
* @throws InvalidSettingsException If parameter name is not valid or a not uniquely defined in the workflow.
* @since 2.12
*/
public void setInputNodes(final Map<String, ExternalNodeData> input) throws InvalidSettingsException {
final CheckedExceptionBiConsumer<InputNode, ExternalNodeData, InvalidSettingsException> validateParamValue = (n, v) -> {
if (n.isInputDataRequired() && v == null) {
throw new InvalidSettingsException("An input for parameter '" + n.getInputData().getID() + "' is required.");
}
n.validateInputData(v);
};
setExternalParameterValues(input, InputNode.class, i -> i.getInputData().getID(), validateParamValue, (n, v) -> n.setInputData(v), true, true);
}
use of org.knime.core.node.dialog.InputNode 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;
}
}
Aggregations