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();
}
}
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);
}
}
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;
}
}
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);
}
}
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;
}
Aggregations