Search in sources :

Example 6 with WorkflowLock

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

the class SinglePageManager method applyValidatedValuesAndReexecute.

/**
 * Applies a given map of view values to a given subnode which have already been validated and triggers reexecution
 * subsequently.
 *
 * @param valueMap 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 applyValidatedValuesAndReexecute(final Map<String, String> valueMap, final NodeID containerNodeId, final boolean useAsDefault) throws IOException {
    try (WorkflowLock lock = getWorkflowManager().assertLock()) {
        applyValidatedViewValues(valueMap, containerNodeId, useAsDefault);
        getController(containerNodeId).reexecuteSinglePage();
    }
}
Also used : WorkflowLock(org.knime.core.node.workflow.WorkflowLock)

Example 7 with WorkflowLock

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

the class SubnodeViewableModel method loadViewValue.

/**
 * {@inheritDoc}
 */
@Override
public void loadViewValue(final SubnodeViewValue value, final boolean useAsDefault) {
    try {
        CheckUtils.checkState(m_container.getNodeContainerState().isExecuted(), "Node needs to be in executed state to apply new view values.");
        m_isReexecuteInProgress.set(true);
        try (WorkflowLock lock = m_container.getParent().lock()) {
            m_spm.applyValidatedValuesAndReexecute(value.getViewValues(), m_container.getID(), useAsDefault);
            m_value = value;
        } finally {
            m_isReexecuteInProgress.set(false);
            NodeContainerState state = m_container.getNodeContainerState();
            if (state.isExecuted()) {
            // the framework refused to reset the node (because there are downstream nodes still executing);
            // ignore it.
            } else if (!m_container.getNodeContainerState().isExecutionInProgress()) {
                // this happens if after the reset the execution can't be triggered, e.g. because #configure of
                // a node rejects the current settings -> #onNodeStateChange has been called as part of the reset
                // but was ignored due to the m_isReexecuteInProgress = true.
                onNodeStateChange();
            }
        }
    } catch (IOException e) {
        logErrorAndReset("Loading view values for node " + m_container.getID() + " failed: ", e);
    }
}
Also used : WorkflowLock(org.knime.core.node.workflow.WorkflowLock) NodeContainerState(org.knime.core.node.workflow.NodeContainerState) IOException(java.io.IOException)

Example 8 with WorkflowLock

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

the class AbstractPageManager method serializeValidationResult.

/**
 * Serializes a map of validation errors into a single JSON string.
 * @param validationResults the map of errors to serialize
 * @return the JSON serialized string
 * @throws IOException on serialization error
 */
protected String serializeValidationResult(final Map<String, ValidationError> validationResults) throws IOException {
    try (WorkflowLock lock = m_wfm.lock()) {
        ObjectMapper mapper = new ObjectMapper();
        String jsonString = null;
        if (validationResults != null && !validationResults.isEmpty()) {
            jsonString = mapper.writeValueAsString(validationResults);
        }
        return jsonString;
    }
}
Also used : WorkflowLock(org.knime.core.node.workflow.WorkflowLock) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 9 with WorkflowLock

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

the class WizardPageManager method applyViewValuesToCurrentPage.

/**
 * Applies a given map of view values to the current subnode in wizard execution.
 *
 * @param valueMap a map with {@link NodeIDSuffix} string as key and parsed view value as value
 * @return A JSON-serialized string containing the validation result, null if validation succeeded.
 * @throws IOException on JSON serialization errors
 */
public String applyViewValuesToCurrentPage(final Map<String, String> valueMap) throws IOException {
    try (WorkflowLock lock = getWorkflowManager().lock()) {
        Map<String, String> viewContentMap = validateValueMap(valueMap);
        Map<String, ValidationError> validationResults = null;
        if (!valueMap.isEmpty()) {
            WizardExecutionController wec = getWizardExecutionController();
            validationResults = wec.loadValuesIntoCurrentPage(viewContentMap);
        }
        return serializeValidationResult(validationResults);
    }
}
Also used : WorkflowLock(org.knime.core.node.workflow.WorkflowLock) WizardExecutionController(org.knime.core.node.workflow.WizardExecutionController) ValidationError(org.knime.core.node.web.ValidationError)

Example 10 with WorkflowLock

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

the class SubnodeLayoutJSONEditorPage method applyUsageChanges.

boolean applyUsageChanges() {
    try (WorkflowLock lock = m_subNodeContainer.lock()) {
        // each node will cause lock acquisition, do it as bulk
        for (Entry<NodeID, Button> wUsage : m_nodeUsageComposite.getWizardUsageMap().entrySet()) {
            NodeID id = wUsage.getKey();
            boolean hide = !wUsage.getValue().getSelection();
            try {
                m_subNodeContainer.setHideNodeFromWizard(id, hide);
            } catch (IllegalArgumentException e) {
                LOGGER.error("Unable to set hide in wizard flag on node: " + e.getMessage(), e);
                return false;
            }
        }
        for (Entry<NodeID, Button> dUsage : m_nodeUsageComposite.getDialogUsageMap().entrySet()) {
            NodeID id = dUsage.getKey();
            boolean hide = !dUsage.getValue().getSelection();
            try {
                m_subNodeContainer.setHideNodeFromDialog(id, hide);
            } catch (IllegalArgumentException e) {
                LOGGER.error("Unable to set hide in dialog flag on node: " + e.getMessage(), e);
                return false;
            }
        }
    }
    return true;
}
Also used : WorkflowLock(org.knime.core.node.workflow.WorkflowLock) Button(org.eclipse.swt.widgets.Button) NodeID(org.knime.core.node.workflow.NodeID)

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