use of org.knime.core.node.dialog.ExternalNodeData in project knime-core by knime.
the class WizardPageManager method applyWorkflowParameters.
/**
* Applies a given map of workflow parameters to the current workflow
*
* @param parameterMap a map with parameter name as key and parameter string value as value
* @throws InvalidSettingsException If a parameter name is not valid or a not uniquely defined in the workflow or if the parameter value does not validate.
*/
public void applyWorkflowParameters(final Map<String, String> parameterMap) throws InvalidSettingsException {
try (WorkflowLock lock = getWorkflowManager().lock()) {
if (parameterMap.size() > 0) {
Map<String, ExternalNodeData> inputData = new HashMap<String, ExternalNodeData>(parameterMap.size());
for (String key : parameterMap.keySet()) {
ExternalNodeDataBuilder dataBuilder = ExternalNodeData.builder(key);
dataBuilder.stringValue(parameterMap.get(key));
inputData.put(key, dataBuilder.build());
}
try {
// FIXME: This call should happen on the WizardExecutionController, once there is no potential version issues
getWorkflowManager().setInputNodes(inputData);
} catch (Exception ex) {
String errorPrefix = "Could not set workflow parameters: ";
String errorMessage = ex.getMessage();
if (!errorMessage.startsWith(errorPrefix)) {
errorMessage = errorPrefix + ex.getMessage();
}
throw new InvalidSettingsException(errorMessage, ex);
}
}
}
}
use of org.knime.core.node.dialog.ExternalNodeData in project knime-core by knime.
the class TestSRV559_RecursiveInputNodesViaREST method testAmbigiousParameterName.
@Test
public void testAmbigiousParameterName() 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).stringValue("bar").build());
inputMap.put(credsInputKey, ExternalNodeData.builder(credsInputKey).stringValue("bar-login:bar-password").build());
manager.setInputNodes(inputMap);
checkStateOfMany(CONFIGURED, m_credInputTopLevel_2, m_stringInputTopLevel_1);
executeAllAndWait();
checkStateOfMany(EXECUTED, m_credInputTopLevel_2, m_stringInputTopLevel_1, m_javaEditValidateTopLevelBar_3, m_credValidateTopLevelBar_6);
checkStateOfMany(IDLE, m_javaEditValidateTopLevelFoo_4, m_credValidateTopLevelFoo_5);
Map<String, ExternalNodeData> outputs = manager.getExternalOutputs();
ExternalNodeData outputData = outputs.get("top-level-json-output-7");
assertThat(outputData.getJSONValue(), is(toJson("{\"top-level-string-input\":\"bar\"," + "\"metanode-level-string-input\":\"foo\"}")));
}
use of org.knime.core.node.dialog.ExternalNodeData in project knime-core by knime.
the class TestSRV559_RecursiveInputNodesViaREST method testSetInputNodesViaJSON.
@Test
public void testSetInputNodesViaJSON() throws Exception {
WorkflowManager manager = getManager();
// should work either way - executed or not
executeAllAndWait();
Map<String, ExternalNodeData> inputMap = new HashMap<>();
final String toplevelStringInputKey;
final String toplevelCredsInputKey;
final String metanodelevelStringInputKey;
final String metanodelevelCredsInputKey;
if (m_useSuffix) {
toplevelStringInputKey = "top-level-string-input-1";
toplevelCredsInputKey = "top-level-credentials-input-2";
metanodelevelStringInputKey = "metanode-level-string-input-21:10";
metanodelevelCredsInputKey = "metanode-level-credentials-input-21:11";
} else {
toplevelStringInputKey = "top-level-string-input";
toplevelCredsInputKey = "top-level-credentials-input";
metanodelevelStringInputKey = "metanode-level-string-input";
metanodelevelCredsInputKey = "metanode-level-credentials-input";
}
inputMap.put(toplevelStringInputKey, ExternalNodeData.builder(toplevelStringInputKey).jsonValue(toJson("{\"string\":\"bar\"}")).build());
inputMap.put(toplevelCredsInputKey, ExternalNodeData.builder(toplevelCredsInputKey).jsonValue(toJson("{\"username\":\"bar-login\", \"password\":\"bar-password\"}")).build());
inputMap.put(metanodelevelStringInputKey, ExternalNodeData.builder(toplevelStringInputKey).jsonValue(toJson("{\"string\":\"bar\"}")).build());
inputMap.put(metanodelevelCredsInputKey, ExternalNodeData.builder(toplevelCredsInputKey).jsonValue(toJson("{\"username\":\"bar-login\", \"password\":\"bar-password\"}")).build());
manager.setInputNodes(inputMap);
checkStateOfMany(CONFIGURED, m_credInputTopLevel_2, m_stringInputTopLevel_1);
executeAllAndWait();
checkStateOfMany(EXECUTED, m_credInputTopLevel_2, m_stringInputTopLevel_1, m_javaEditValidateTopLevelBar_3, m_credValidateTopLevelBar_6);
checkStateOfMany(IDLE, m_javaEditValidateTopLevelFoo_4, m_credValidateTopLevelFoo_5);
Map<String, ExternalNodeData> outputs = manager.getExternalOutputs();
ExternalNodeData outputDataTopLevel = outputs.get("top-level-json-output-7");
assertThat(outputDataTopLevel.getJSONValue(), is(toJson("{\"top-level-string-input\":\"bar\"," + "\"metanode-level-string-input\":\"bar\"}")));
ExternalNodeData outputDataMetanodeLevel = outputs.get("metanode-level-json-output-21:16");
assertThat(outputDataMetanodeLevel.getJSONValue(), is(toJson("{\"metanode-level-string-input\":\"bar\"}")));
}
use of org.knime.core.node.dialog.ExternalNodeData in project knime-core by knime.
the class TestSRV559_RecursiveInputNodesViaREST method testSetInvalidValueViaString.
@Test(expected = InvalidSettingsException.class)
public void testSetInvalidValueViaString() 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).stringValue("invalid").build());
inputMap.put(credsInputKey, ExternalNodeData.builder(credsInputKey).stringValue("bar-login:bar-password").build());
manager.setInputNodes(inputMap);
}
use of org.knime.core.node.dialog.ExternalNodeData 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);
}
Aggregations