use of org.knime.core.node.workflow.MetaNodeTemplateInformation.UpdateStatus in project knime-core by knime.
the class WorkflowManager method checkUpdateMetaNodeLinkWithCache.
/**
* Implementation of #checkUpdateMetaNodeLink that uses a cache of already checked metanode links.
*
* @param loadResult Errors while loading the template are added here
* @param visitedTemplateMap avoids repeated checks for copies of the same metanode link.
* @param recurseInto Should linked metanodes contained in the metanode also be checked.
*/
private boolean checkUpdateMetaNodeLinkWithCache(final NodeID id, final WorkflowLoadHelper loadHelper, final LoadResult loadResult, final Map<URI, NodeContainerTemplate> visitedTemplateMap, final boolean recurseInto) throws IOException {
NodeContainer nc = m_workflow.getNode(id);
if (!(nc instanceof NodeContainerTemplate)) {
return false;
}
NodeContainerTemplate tnc = (NodeContainerTemplate) nc;
Map<NodeID, NodeContainerTemplate> idsToCheck = new LinkedHashMap<NodeID, NodeContainerTemplate>();
if (tnc.getTemplateInformation().getRole().equals(Role.Link)) {
idsToCheck.put(id, tnc);
}
if (recurseInto) {
idsToCheck = tnc.fillLinkedTemplateNodesList(idsToCheck, true, false);
}
boolean hasUpdate = false;
for (NodeContainerTemplate linkedMeta : idsToCheck.values()) {
MetaNodeTemplateInformation linkInfo = linkedMeta.getTemplateInformation();
final URI uri = linkInfo.getSourceURI();
NodeContainerTemplate tempLink = visitedTemplateMap.get(uri);
if (tempLink == null) {
try {
final LoadResult templateLoadResult = new LoadResult("Template to " + uri);
tempLink = loadMetaNodeTemplate(linkedMeta, loadHelper, templateLoadResult);
loadResult.addChildError(templateLoadResult);
visitedTemplateMap.put(uri, tempLink);
} catch (Exception e) {
if (linkInfo.setUpdateStatusInternal(UpdateStatus.Error)) {
linkedMeta.notifyTemplateConnectionChangedListener();
}
if (e instanceof IOException) {
throw new IOException("Could not update metanode '" + tnc + "': " + e.getMessage(), e);
} else if (e instanceof CanceledExecutionException) {
throw new IOException("Canceled while loading from template", e);
} else if (e instanceof RuntimeException) {
throw (RuntimeException) e;
} else {
throw new RuntimeException(e);
}
}
}
boolean hasThisOneAnUpdate = tempLink.getTemplateInformation().isNewerThan(linkInfo);
UpdateStatus updateStatus = hasThisOneAnUpdate ? UpdateStatus.HasUpdate : UpdateStatus.UpToDate;
hasUpdate = hasUpdate || hasThisOneAnUpdate;
if (linkInfo.setUpdateStatusInternal(updateStatus)) {
linkedMeta.notifyTemplateConnectionChangedListener();
}
}
return hasUpdate;
}
Aggregations