Search in sources :

Example 1 with ExternalNodeDataBuilder

use of org.knime.core.node.dialog.ExternalNodeData.ExternalNodeDataBuilder 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);
            }
        }
    }
}
Also used : WorkflowLock(org.knime.core.node.workflow.WorkflowLock) ExternalNodeData(org.knime.core.node.dialog.ExternalNodeData) HashMap(java.util.HashMap) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ExternalNodeDataBuilder(org.knime.core.node.dialog.ExternalNodeData.ExternalNodeDataBuilder) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1 ExternalNodeData (org.knime.core.node.dialog.ExternalNodeData)1 ExternalNodeDataBuilder (org.knime.core.node.dialog.ExternalNodeData.ExternalNodeDataBuilder)1 WorkflowLock (org.knime.core.node.workflow.WorkflowLock)1