Search in sources :

Example 1 with WorkflowLock

use of org.knime.core.node.workflow.WorkflowLock in project knime-core by knime.

the class SinglePageManager method applyValidatedViewValues.

/**
 * Applies a given map of view values to a given subnode which have already been validated.
 * @param viewValues an already validated map with {@link NodeIDSuffix} string as key and parsed view value as value
 * @param containerNodeId the {@link NodeID} of the subnode
 * @param useAsDefault true, if values are supposed to be applied as new defaults, false if applied temporarily
 * @throws IOException on serialization error
 */
public void applyValidatedViewValues(final Map<String, String> viewValues, final NodeID containerNodeId, final boolean useAsDefault) throws IOException {
    try (WorkflowLock lock = getWorkflowManager().lock()) {
        /*ObjectMapper mapper = new ObjectMapper();
            for (String key : viewValues.keySet()) {
                String content = mapper.writeValueAsString(viewValues.get(key));
                viewValues.put(key, content);
            }*/
        if (!viewValues.isEmpty()) {
            SinglePageWebResourceController sec = getController(containerNodeId);
            sec.loadValuesIntoPage(viewValues, false, useAsDefault);
        }
    }
}
Also used : WorkflowLock(org.knime.core.node.workflow.WorkflowLock) SinglePageWebResourceController(org.knime.core.node.workflow.SinglePageWebResourceController)

Example 2 with WorkflowLock

use of org.knime.core.node.workflow.WorkflowLock in project knime-core by knime.

the class AbstractPageManager method validateValueMap.

/**
 * Validates a value map using a JSON mapper.
 * @param valueMap the map to validate
 * @return a validated map of view values
 * @throws IOException on serialization error
 */
protected Map<String, String> validateValueMap(final Map<String, String> valueMap) throws IOException {
    try (WorkflowLock lock = m_wfm.lock()) {
        ObjectMapper mapper = new ObjectMapper();
        for (String key : valueMap.keySet()) {
            String content = mapper.writeValueAsString(valueMap.get(key));
            valueMap.put(key, content);
        }
        return valueMap;
    }
}
Also used : WorkflowLock(org.knime.core.node.workflow.WorkflowLock) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with WorkflowLock

use of org.knime.core.node.workflow.WorkflowLock 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)

Example 4 with WorkflowLock

use of org.knime.core.node.workflow.WorkflowLock in project knime-core by knime.

the class MetaNodeToSubNodeResult method undo.

/**
 * Perform the undo.
 */
public void undo() {
    try (WorkflowLock lock = m_wfm.lock()) {
        // prevent events to be sent too early
        m_wfm.removeNode(m_nodeID);
        m_wfm.paste(m_undoPersistor);
    }
}
Also used : WorkflowLock(org.knime.core.node.workflow.WorkflowLock)

Example 5 with WorkflowLock

use of org.knime.core.node.workflow.WorkflowLock in project knime-core by knime.

the class CollapseIntoMetaNodeResult method undo.

public void undo() {
    WorkflowManager hostWFM = m_hostWFM;
    try (WorkflowLock l = m_hostWFM.lock()) {
        m_hostWFM.removeNode(m_collapsedMetanodeID);
        hostWFM.paste(m_undoCopyPersistor);
    }
}
Also used : WorkflowLock(org.knime.core.node.workflow.WorkflowLock) WorkflowManager(org.knime.core.node.workflow.WorkflowManager)

Aggregations

WorkflowLock (org.knime.core.node.workflow.WorkflowLock)11 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 IOException (java.io.IOException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 HashMap (java.util.HashMap)1 Button (org.eclipse.swt.widgets.Button)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 ValidationError (org.knime.core.node.web.ValidationError)1 NodeContainerState (org.knime.core.node.workflow.NodeContainerState)1 NodeID (org.knime.core.node.workflow.NodeID)1 SinglePageWebResourceController (org.knime.core.node.workflow.SinglePageWebResourceController)1 WizardExecutionController (org.knime.core.node.workflow.WizardExecutionController)1 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)1