Search in sources :

Example 1 with UpdateStatus

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;
}
Also used : UpdateStatus(org.knime.core.node.workflow.MetaNodeTemplateInformation.UpdateStatus) IOException(java.io.IOException) URI(java.net.URI) WorkflowLoadResult(org.knime.core.node.workflow.WorkflowPersistor.WorkflowLoadResult) LoadResult(org.knime.core.node.workflow.WorkflowPersistor.LoadResult) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) CoreException(org.eclipse.core.runtime.CoreException) LockFailedException(org.knime.core.util.LockFailedException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NotConfigurableException(org.knime.core.node.NotConfigurableException) IOException(java.io.IOException) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) URISyntaxException(java.net.URISyntaxException) LinkedHashMap(java.util.LinkedHashMap) CanceledExecutionException(org.knime.core.node.CanceledExecutionException)

Aggregations

IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 LinkedHashMap (java.util.LinkedHashMap)1 CoreException (org.eclipse.core.runtime.CoreException)1 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)1 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1 NotConfigurableException (org.knime.core.node.NotConfigurableException)1 UpdateStatus (org.knime.core.node.workflow.MetaNodeTemplateInformation.UpdateStatus)1 LoadResult (org.knime.core.node.workflow.WorkflowPersistor.LoadResult)1 WorkflowLoadResult (org.knime.core.node.workflow.WorkflowPersistor.WorkflowLoadResult)1 LockFailedException (org.knime.core.util.LockFailedException)1