Search in sources :

Example 1 with MissingNodeFactory

use of org.knime.core.node.missing.MissingNodeFactory in project knime-core by knime.

the class FileNativeNodeContainerPersistor method guessPortTypesFromConnectedNodes.

/**
 * {@inheritDoc}
 */
@Override
public void guessPortTypesFromConnectedNodes(final NodeAndBundleInformation nodeInfo, final NodeSettingsRO additionalFactorySettings, final ArrayList<PersistorWithPortIndex> upstreamNodes, final ArrayList<List<PersistorWithPortIndex>> downstreamNodes) {
    if (m_node == null) {
        /* Input ports from the connection table. */
        // first is flow var port
        PortType[] inPortTypes = new PortType[Math.max(upstreamNodes.size() - 1, 0)];
        // default to BDT for unconnected ports
        Arrays.fill(inPortTypes, BufferedDataTable.TYPE);
        for (int i = 0; i < inPortTypes.length; i++) {
            // first is flow var port
            PersistorWithPortIndex p = upstreamNodes.get(i + 1);
            if (p != null) {
                PortType portTypeFromUpstreamNode = p.getPersistor().getUpstreamPortType(p.getPortIndex());
                if (portTypeFromUpstreamNode != null) {
                    // null if upstream is missing, too
                    inPortTypes[i] = portTypeFromUpstreamNode;
                }
            }
        }
        /* Output ports from node settings (saved ports) -- if possible (executed) */
        String nodeName = nodeInfo.getNodeNameNotNull();
        PortType[] outPortTypes;
        try {
            LoadResult guessLoadResult = new LoadResult("Port type guessing for missing node \"" + nodeName + "\"");
            NodeSettingsRO settingsForNode = loadSettingsForNode(guessLoadResult);
            FileNodePersistor nodePersistor = createNodePersistor(settingsForNode);
            outPortTypes = nodePersistor.guessOutputPortTypes(guessLoadResult, nodeName);
            if (guessLoadResult.hasErrors()) {
                getLogger().debug("Errors guessing port types for missing node \"" + nodeName + "\": " + guessLoadResult.getFilteredError("", LoadResultEntryType.Error));
            }
        } catch (Exception e) {
            getLogger().debug("Unable to guess port types for missing node \"" + nodeName + "\"", e);
            outPortTypes = null;
        }
        if (outPortTypes == null) {
            // couldn't guess port types from looking at node settings (e.g. not executed)
            // default to BDT for unconnected ports
            outPortTypes = new PortType[Math.max(downstreamNodes.size() - 1, 0)];
        }
        for (int i = 0; i < outPortTypes.length; i++) {
            PortType type = outPortTypes[i];
            // output types may be partially filled by settings guessing above, list may be empty or too short
            List<PersistorWithPortIndex> list = i < downstreamNodes.size() - 1 ? downstreamNodes.get(i + 1) : null;
            if (list != null) {
                assert !list.isEmpty();
                for (PersistorWithPortIndex p : list) {
                    PortType current = p.getPersistor().getDownstreamPortType(p.getPortIndex());
                    if (current == null) {
                    // ignore, downstream node is also missing
                    } else if (type == null) {
                        type = current;
                    } else if (type.equals(current)) {
                    // keep type
                    } else {
                        // this shouldn't really happen - someone changed port types between versions
                        type = PortObject.TYPE;
                    }
                }
                outPortTypes[i] = type;
            }
            if (outPortTypes[i] == null) {
                // might still be null if missing node is only connected to missing node, fallback: BDT
                outPortTypes[i] = BufferedDataTable.TYPE;
            }
        }
        MissingNodeFactory nodefactory = new MissingNodeFactory(nodeInfo, additionalFactorySettings, inPortTypes, outPortTypes);
        if (getLoadVersion().ordinal() < FileWorkflowPersistor.VERSION_LATEST.ordinal()) {
            nodefactory.setCopyInternDirForWorkflowVersionChange(true);
        }
        nodefactory.init();
        m_node = new Node((NodeFactory) nodefactory);
    }
}
Also used : Node(org.knime.core.node.Node) FileNodePersistor(org.knime.core.node.FileNodePersistor) LoadResult(org.knime.core.node.workflow.WorkflowPersistor.LoadResult) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) NodeFactoryUnknownException(org.knime.core.node.workflow.WorkflowPersistor.NodeFactoryUnknownException) IOException(java.io.IOException) NodeFactory(org.knime.core.node.NodeFactory) MissingNodeFactory(org.knime.core.node.missing.MissingNodeFactory) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) MissingNodeFactory(org.knime.core.node.missing.MissingNodeFactory) PortType(org.knime.core.node.port.PortType)

Example 2 with MissingNodeFactory

use of org.knime.core.node.missing.MissingNodeFactory in project knime-core by knime.

the class FileNativeNodeContainerPersistor method guessPortTypesFromConnectedNodes.

/**
 * {@inheritDoc}
 */
@Override
public void guessPortTypesFromConnectedNodes(final NodeAndBundleInformationPersistor nodeInfo, final NodeSettingsRO additionalFactorySettings, final ArrayList<PersistorWithPortIndex> upstreamNodes, final ArrayList<List<PersistorWithPortIndex>> downstreamNodes) {
    if (m_node == null) {
        /* Input ports from the connection table. */
        // first is flow var port
        PortType[] inPortTypes = new PortType[Math.max(upstreamNodes.size() - 1, 0)];
        // default to BDT for unconnected ports
        Arrays.fill(inPortTypes, BufferedDataTable.TYPE);
        for (int i = 0; i < inPortTypes.length; i++) {
            // first is flow var port
            PersistorWithPortIndex p = upstreamNodes.get(i + 1);
            if (p != null) {
                PortType portTypeFromUpstreamNode = p.getPersistor().getUpstreamPortType(p.getPortIndex());
                if (portTypeFromUpstreamNode != null) {
                    // null if upstream is missing, too
                    inPortTypes[i] = portTypeFromUpstreamNode;
                }
            }
        }
        /* Output ports from node settings (saved ports) -- if possible (executed) */
        String nodeName = nodeInfo.getNodeNameNotNull();
        PortType[] outPortTypes;
        try {
            LoadResult guessLoadResult = new LoadResult("Port type guessing for missing node \"" + nodeName + "\"");
            NodeSettingsRO settingsForNode = loadSettingsForNode(guessLoadResult);
            FileNodePersistor nodePersistor = createNodePersistor(settingsForNode);
            outPortTypes = nodePersistor.guessOutputPortTypes(guessLoadResult, nodeName);
            if (guessLoadResult.hasErrors()) {
                getLogger().debug("Errors guessing port types for missing node \"" + nodeName + "\": " + guessLoadResult.getFilteredError("", LoadResultEntryType.Error));
            }
        } catch (Exception e) {
            getLogger().debug("Unable to guess port types for missing node \"" + nodeName + "\"", e);
            outPortTypes = null;
        }
        if (outPortTypes == null) {
            // couldn't guess port types from looking at node settings (e.g. not executed)
            // default to BDT for unconnected ports
            outPortTypes = new PortType[Math.max(downstreamNodes.size() - 1, 0)];
        }
        for (int i = 0; i < outPortTypes.length; i++) {
            PortType type = outPortTypes[i];
            // output types may be partially filled by settings guessing above, list may be empty or too short
            List<PersistorWithPortIndex> list = i < downstreamNodes.size() - 1 ? downstreamNodes.get(i + 1) : null;
            if (list != null) {
                assert !list.isEmpty();
                for (PersistorWithPortIndex p : list) {
                    PortType current = p.getPersistor().getDownstreamPortType(p.getPortIndex());
                    if (current == null) {
                    // ignore, downstream node is also missing
                    } else if (type == null) {
                        type = current;
                    } else if (type.equals(current)) {
                    // keep type
                    } else {
                        // this shouldn't really happen - someone changed port types between versions
                        type = PortObject.TYPE;
                    }
                }
                outPortTypes[i] = type;
            }
            if (outPortTypes[i] == null) {
                // might still be null if missing node is only connected to missing node, fallback: BDT
                outPortTypes[i] = BufferedDataTable.TYPE;
            }
        }
        MissingNodeFactory nodefactory = new MissingNodeFactory(nodeInfo, additionalFactorySettings, inPortTypes, outPortTypes);
        if (getLoadVersion().ordinal() < FileWorkflowPersistor.VERSION_LATEST.ordinal()) {
            nodefactory.setCopyInternDirForWorkflowVersionChange(true);
        }
        nodefactory.init();
        m_node = new Node((NodeFactory) nodefactory);
    }
}
Also used : Node(org.knime.core.node.Node) FileNodePersistor(org.knime.core.node.FileNodePersistor) LoadResult(org.knime.core.node.workflow.WorkflowPersistor.LoadResult) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) InvalidNodeFactoryExtensionException(org.knime.core.node.extension.InvalidNodeFactoryExtensionException) NodeFactoryUnknownException(org.knime.core.node.workflow.WorkflowPersistor.NodeFactoryUnknownException) IOException(java.io.IOException) ConfigurableNodeFactory(org.knime.core.node.ConfigurableNodeFactory) NodeFactory(org.knime.core.node.NodeFactory) MissingNodeFactory(org.knime.core.node.missing.MissingNodeFactory) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) MissingNodeFactory(org.knime.core.node.missing.MissingNodeFactory) PortType(org.knime.core.node.port.PortType)

Example 3 with MissingNodeFactory

use of org.knime.core.node.missing.MissingNodeFactory in project knime-core by knime.

the class NodeFactory method addBundleInformation.

/**
 * Adds information about the bundle/feature in which this node resides to the XML description tree. Note that the
 * bundle information does not have a namespace!
 */
private void addBundleInformation() {
    Element root = m_nodeDescription.getXMLDescription();
    if ((root != null) && !(this instanceof MissingNodeFactory)) {
        // for running in non-osgi context
        NodeAndBundleInformationPersistor nodeInfo = NodeAndBundleInformationPersistor.create(this);
        Document doc = root.getOwnerDocument();
        Element bundleElement = doc.createElement("osgi-info");
        bundleElement.setAttribute("bundle-symbolic-name", nodeInfo.getFeatureSymbolicName().orElse(nodeInfo.getBundleSymbolicName().orElse("<Unknown>")));
        bundleElement.setAttribute("bundle-name", nodeInfo.getFeatureName().orElse(nodeInfo.getBundleName().orElse("<Unknown>")));
        bundleElement.setAttribute("bundle-vendor", nodeInfo.getFeatureVendor().orElse(nodeInfo.getBundleVendor().orElse("<Unknown>")));
        bundleElement.setAttribute("factory-package", this.getClass().getPackage().getName());
        root.appendChild(bundleElement);
    }
}
Also used : Element(org.w3c.dom.Element) MissingNodeFactory(org.knime.core.node.missing.MissingNodeFactory) Document(org.w3c.dom.Document)

Aggregations

MissingNodeFactory (org.knime.core.node.missing.MissingNodeFactory)3 IOException (java.io.IOException)2 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)2 FileNodePersistor (org.knime.core.node.FileNodePersistor)2 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 Node (org.knime.core.node.Node)2 NodeFactory (org.knime.core.node.NodeFactory)2 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)2 PortType (org.knime.core.node.port.PortType)2 LoadResult (org.knime.core.node.workflow.WorkflowPersistor.LoadResult)2 NodeFactoryUnknownException (org.knime.core.node.workflow.WorkflowPersistor.NodeFactoryUnknownException)2 ConfigurableNodeFactory (org.knime.core.node.ConfigurableNodeFactory)1 InvalidNodeFactoryExtensionException (org.knime.core.node.extension.InvalidNodeFactoryExtensionException)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1