Search in sources :

Example 56 with NodeSettingsRO

use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.

the class FileWorkflowPersistor method loadEditorUIInformation.

/**
 * Load editor information (grid settings & zoom level).
 *
 * @param settings ...
 * @return null
 * @since 2.6
 * @throws InvalidSettingsException ...
 */
EditorUIInformation loadEditorUIInformation(final NodeSettingsRO settings) throws InvalidSettingsException {
    final LoadVersion loadVersion = getLoadVersion();
    if (loadVersion.isOlderThan(LoadVersion.V260) || !settings.containsKey(CFG_EDITOR_INFO)) {
        return EditorUIInformation.builder().build();
    }
    NodeSettingsRO editorCfg = settings.getNodeSettings(CFG_EDITOR_INFO);
    EditorUIInformation.Builder builder = EditorUIInformation.builder();
    builder.setSnapToGrid(editorCfg.getBoolean(CFG_EDITOR_SNAP_GRID));
    builder.setShowGrid(editorCfg.getBoolean(CFG_EDITOR_SHOW_GRID));
    builder.setGridX(editorCfg.getInt(CFG_EDITOR_X_GRID));
    builder.setGridY(editorCfg.getInt(CFG_EDITOR_Y_GRID));
    builder.setZoomLevel(editorCfg.getDouble(CFG_EDITOR_ZOOM));
    if (editorCfg.containsKey(CFG_EDITOR_CURVED_CONNECTIONS)) {
        builder.setHasCurvedConnections(editorCfg.getBoolean(CFG_EDITOR_CURVED_CONNECTIONS));
    }
    if (editorCfg.containsKey(CFG_EDITOR_CONNECTION_WIDTH)) {
        builder.setConnectionLineWidth(editorCfg.getInt(CFG_EDITOR_CONNECTION_WIDTH));
    }
    return builder.build();
}
Also used : NodeSettingsRO(org.knime.core.node.NodeSettingsRO) LoadVersion(org.knime.core.util.LoadVersion)

Example 57 with NodeSettingsRO

use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.

the class FileWorkflowPersistor method loadUIInfoSettings.

void loadUIInfoSettings(final UIInformation uiInfo, final NodeSettingsRO settings) throws InvalidSettingsException {
    // in previous releases, the settings were directly written to the
    // top-most node settings object; since 2.0 they are put into a
    // separate sub-settings object
    NodeSettingsRO subSettings = getLoadVersion().isOlderThan(LoadVersion.V200) ? settings : settings.getNodeSettings(CFG_UIINFO_SUB_CONFIG);
    uiInfo.load(subSettings, getLoadVersion());
}
Also used : NodeSettingsRO(org.knime.core.node.NodeSettingsRO)

Example 58 with NodeSettingsRO

use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.

the class FileWorkflowPersistor method loadNodeContainer.

/**
 * {@inheritDoc}
 */
@Override
public void loadNodeContainer(final Map<Integer, BufferedDataTable> tblRep, final ExecutionMonitor exec, final LoadResult loadResult) throws CanceledExecutionException, IOException {
    ReferencedFile workflowKNIMEFile = getWorkflowKNIMEFile();
    if (workflowKNIMEFile == null || m_workflowSett == null) {
        setDirtyAfterLoad();
        throw new IllegalStateException("The method preLoadNodeContainer has either not been called or failed");
    }
    /* read nodes */
    NodeSettingsRO nodes;
    try {
        nodes = loadSettingsForNodes(m_workflowSett);
    } catch (InvalidSettingsException e) {
        String error = "Can't load nodes in workflow, config not found: " + e.getMessage();
        getLogger().debug(error, e);
        loadResult.addError(error);
        setDirtyAfterLoad();
        setNeedsResetAfterLoad();
        // stop loading here
        return;
    }
    // ids of nodes that failed to load. Used to suppress superfluous errors when reading the connections
    Set<Integer> failingNodeIDSet = new HashSet<Integer>();
    // ids of nodes whose factory can't be loaded (e.g. node extension not installed)
    Map<Integer, NodeFactoryUnknownException> missingNodeIDMap = new HashMap<Integer, NodeFactoryUnknownException>();
    exec.setMessage("node information");
    final ReferencedFile workflowDirRef = workflowKNIMEFile.getParent();
    /* Load nodes */
    for (String nodeKey : nodes.keySet()) {
        exec.checkCanceled();
        NodeSettingsRO nodeSetting;
        try {
            nodeSetting = nodes.getNodeSettings(nodeKey);
        } catch (InvalidSettingsException e) {
            String error = "Unable to load settings for node with internal " + "id \"" + nodeKey + "\": " + e.getMessage();
            getLogger().debug(error, e);
            setDirtyAfterLoad();
            loadResult.addError(error);
            continue;
        }
        if (shouldSkipThisNode(nodeSetting)) {
            continue;
        }
        int nodeIDSuffix;
        try {
            nodeIDSuffix = loadNodeIDSuffix(nodeSetting);
        } catch (InvalidSettingsException e) {
            nodeIDSuffix = getRandomNodeID();
            String error = "Unable to load node ID (internal id \"" + nodeKey + "\"), trying random number " + nodeIDSuffix + "instead: " + e.getMessage();
            getLogger().debug(error, e);
            setDirtyAfterLoad();
            loadResult.addError(error);
        }
        NodeType nodeType;
        try {
            nodeType = loadNodeType(nodeSetting);
        } catch (InvalidSettingsException e) {
            String error = "Can't retrieve node type for contained node with id suffix " + nodeIDSuffix + ", attempting to read ordinary (native) node: " + e.getMessage();
            getLogger().debug(error, e);
            setDirtyAfterLoad();
            loadResult.addError(error);
            nodeType = NodeType.NativeNode;
        }
        NodeUIInformation nodeUIInfo = null;
        String uiInfoClassName;
        try {
            uiInfoClassName = loadUIInfoClassName(nodeSetting);
        } catch (InvalidSettingsException e) {
            String error = "Unable to load UI information class name " + "to node with ID suffix " + nodeIDSuffix + ", no UI information available: " + e.getMessage();
            getLogger().debug(error, e);
            setDirtyAfterLoad();
            loadResult.addError(error);
            uiInfoClassName = null;
        }
        if (uiInfoClassName != null) {
            try {
                // load node ui info
                nodeUIInfo = loadNodeUIInformation(nodeSetting);
            } catch (InvalidSettingsException e) {
                String error = "Unable to load UI information to " + "node with ID suffix " + nodeIDSuffix + ", no UI information available: " + e.getMessage();
                getLogger().debug(error, e);
                setDirtyAfterLoad();
                loadResult.addError(error);
            }
        }
        ReferencedFile nodeFile;
        try {
            nodeFile = loadNodeFile(nodeSetting, workflowDirRef);
        } catch (InvalidSettingsException e) {
            String error = "Unable to load settings for node " + "with ID suffix " + nodeIDSuffix + ": " + e.getMessage();
            getLogger().debug(error, e);
            setDirtyAfterLoad();
            loadResult.addError(error);
            failingNodeIDSet.add(nodeIDSuffix);
            continue;
        }
        FromFileNodeContainerPersistor persistor;
        switch(nodeType) {
            case MetaNode:
                persistor = createWorkflowPersistorLoad(nodeFile);
                break;
            case NativeNode:
                persistor = createNativeNodeContainerPersistorLoad(nodeFile);
                break;
            case SubNode:
                persistor = createSubNodeContainerPersistorLoad(nodeFile);
                break;
            default:
                throw new IllegalStateException("Unknown node type: " + nodeType);
        }
        try {
            LoadResult childResult = new LoadResult(nodeType.toString() + " with ID suffix " + nodeIDSuffix);
            persistor.preLoadNodeContainer(this, nodeSetting, childResult);
            loadResult.addChildError(childResult);
        } catch (Throwable e) {
            String error = "Unable to load node with ID suffix " + nodeIDSuffix + " into workflow, skipping it: " + e.getMessage();
            String loadErrorString;
            if (e instanceof NodeFactoryUnknownException) {
                loadErrorString = e.getMessage();
            } else {
                loadErrorString = error;
            }
            if (e instanceof InvalidSettingsException || e instanceof IOException || e instanceof NodeFactoryUnknownException) {
                getLogger().debug(error, e);
            } else {
                getLogger().error(error, e);
            }
            loadResult.addError(loadErrorString);
            if (e instanceof NodeFactoryUnknownException) {
                missingNodeIDMap.put(nodeIDSuffix, (NodeFactoryUnknownException) e);
            // don't set dirty
            } else {
                setDirtyAfterLoad();
                failingNodeIDSet.add(nodeIDSuffix);
                // node directory is the parent of the settings.xml
                m_obsoleteNodeDirectories.add(nodeFile.getParent());
                continue;
            }
        }
        NodeContainerMetaPersistor meta = persistor.getMetaPersistor();
        if (m_nodeContainerLoaderMap.containsKey(nodeIDSuffix)) {
            int randomID = getRandomNodeID();
            setDirtyAfterLoad();
            loadResult.addError("Duplicate id encountered in workflow: " + nodeIDSuffix + ", uniquifying to random id " + randomID + ", this possibly screws the connections");
            nodeIDSuffix = randomID;
        }
        meta.setNodeIDSuffix(nodeIDSuffix);
        meta.setUIInfo(nodeUIInfo);
        if (persistor.isDirtyAfterLoad()) {
            setDirtyAfterLoad();
        }
        m_nodeContainerLoaderMap.put(nodeIDSuffix, persistor);
    }
    /* read connections */
    exec.setMessage("connection information");
    NodeSettingsRO connections;
    try {
        connections = loadSettingsForConnections(m_workflowSett);
        if (connections == null) {
            connections = EMPTY_SETTINGS;
        }
    } catch (InvalidSettingsException e) {
        String error = "Can't load workflow connections, config not found: " + e.getMessage();
        getLogger().debug(error, e);
        setDirtyAfterLoad();
        loadResult.addError(error);
        connections = EMPTY_SETTINGS;
    }
    for (String connectionKey : connections.keySet()) {
        exec.checkCanceled();
        ConnectionContainerTemplate c;
        try {
            c = loadConnection(connections.getNodeSettings(connectionKey));
        } catch (InvalidSettingsException e) {
            String error = "Can't load connection with internal ID \"" + connectionKey + "\": " + e.getMessage();
            getLogger().debug(error, e);
            setDirtyAfterLoad();
            loadResult.addError(error);
            continue;
        }
        int sourceIDSuffix = c.getSourceSuffix();
        NodeContainerPersistor sourceNodePersistor = m_nodeContainerLoaderMap.get(sourceIDSuffix);
        if (sourceNodePersistor == null && sourceIDSuffix != -1) {
            setDirtyAfterLoad();
            if (!failingNodeIDSet.contains(sourceIDSuffix)) {
                loadResult.addError("Unable to load node connection " + c + ", source node does not exist");
            }
            continue;
        }
        fixSourcePortIfNecessary(sourceNodePersistor, c);
        int destIDSuffix = c.getDestSuffix();
        NodeContainerPersistor destNodePersistor = m_nodeContainerLoaderMap.get(destIDSuffix);
        if (destNodePersistor == null && destIDSuffix != -1) {
            setDirtyAfterLoad();
            if (!failingNodeIDSet.contains(destIDSuffix)) {
                loadResult.addError("Unable to load node connection " + c + ", destination node does not exist");
            }
            continue;
        }
        fixDestPortIfNecessary(destNodePersistor, c);
        if (!m_connectionSet.add(c)) {
            setDirtyAfterLoad();
            loadResult.addError("Duplicate connection information: " + c);
        }
    }
    for (Map.Entry<Integer, NodeFactoryUnknownException> missingNode : missingNodeIDMap.entrySet()) {
        exec.checkCanceled();
        int missingNodeSuffix = missingNode.getKey();
        NodeAndBundleInformationPersistor nodeInfo = missingNode.getValue().getNodeAndBundleInformation();
        loadResult.addMissingNode(nodeInfo);
        NodeSettingsRO additionalFactorySettings = missingNode.getValue().getAdditionalFactorySettings();
        ArrayList<PersistorWithPortIndex> upstreamNodes = new ArrayList<PersistorWithPortIndex>();
        ArrayList<List<PersistorWithPortIndex>> downstreamNodes = new ArrayList<List<PersistorWithPortIndex>>();
        for (ConnectionContainerTemplate t : m_connectionSet) {
            // check upstream nodes
            int sourceSuffix = t.getSourceSuffix();
            int destSuffix = t.getDestSuffix();
            int sourcePort = t.getSourcePort();
            int destPort = t.getDestPort();
            if (destSuffix == missingNodeSuffix) {
                FromFileNodeContainerPersistor persistor;
                if (sourceSuffix == -1) {
                    // connected to this metanode's input port bar
                    persistor = this;
                } else {
                    persistor = m_nodeContainerLoaderMap.get(sourceSuffix);
                }
                ensureArrayListIndexValid(upstreamNodes, destPort);
                upstreamNodes.set(destPort, new PersistorWithPortIndex(persistor, sourcePort));
            }
            // check downstream nodes
            if (sourceSuffix == missingNodeSuffix) {
                FromFileNodeContainerPersistor persistor;
                if (destSuffix == -1) {
                    // connect to this metanode's output port bar
                    persistor = this;
                } else {
                    persistor = m_nodeContainerLoaderMap.get(destSuffix);
                }
                ensureArrayListIndexValid(downstreamNodes, sourcePort);
                List<PersistorWithPortIndex> downstreamNodesAtPort = downstreamNodes.get(sourcePort);
                if (downstreamNodesAtPort == null) {
                    downstreamNodesAtPort = new ArrayList<PersistorWithPortIndex>();
                    downstreamNodes.set(sourcePort, downstreamNodesAtPort);
                }
                downstreamNodesAtPort.add(new PersistorWithPortIndex(persistor, destPort));
            }
        }
        FromFileNodeContainerPersistor failingNodePersistor = m_nodeContainerLoaderMap.get(missingNodeSuffix);
        failingNodePersistor.guessPortTypesFromConnectedNodes(nodeInfo, additionalFactorySettings, upstreamNodes, downstreamNodes);
    }
    exec.setProgress(1.0);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ReferencedFile(org.knime.core.internal.ReferencedFile) ArrayList(java.util.ArrayList) List(java.util.List) NodeAndBundleInformationPersistor(org.knime.core.node.NodeAndBundleInformationPersistor) HashSet(java.util.HashSet) IOException(java.io.IOException) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 59 with NodeSettingsRO

use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.

the class FileWorkflowPersistor method loadOutPortTemplate.

/**
 * Sub class hook o read port settings.
 *
 * @param settings Ignored.
 * @return null
 * @throws InvalidSettingsException Not actually thrown here.
 */
WorkflowPortTemplate loadOutPortTemplate(final NodeSettingsRO settings) throws InvalidSettingsException {
    if (getLoadVersion().isOlderThan(LoadVersion.V200)) {
        throw new InvalidSettingsException("No ports for metanodes in version 1.x.x");
    } else {
        int index = settings.getInt("index");
        String name = settings.getString("name");
        NodeSettingsRO portTypeSettings = settings.getNodeSettings("type");
        PortType type = PortType.load(portTypeSettings);
        WorkflowPortTemplate result = new WorkflowPortTemplate(index, type);
        result.setPortName(name);
        return result;
    }
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) PortType(org.knime.core.node.port.PortType)

Example 60 with NodeSettingsRO

use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.

the class MetaNodeTemplateInformation method load.

/**
 * Load information from argument, throws a {@link InvalidSettingsException} if that fails.
 *
 * @param settings To load from.
 * @param version The version this workflow is loading from
 * @param withExampleInputDataInfo if the info about example input data should be loaded too (only makes sense if
 *            template is directly opened in the workflow editor as a project and not embedded in a workflow)
 * @return a new template loading from the argument settings.
 * @throws InvalidSettingsException If that fails.
 */
static MetaNodeTemplateInformation load(final NodeSettingsRO settings, final LoadVersion version, final boolean withExampleInputDataInfo) throws InvalidSettingsException {
    if (!settings.containsKey(CFG_TEMPLATE_INFO)) {
        return NONE;
    }
    NodeSettingsRO nestedSettings = settings.getNodeSettings(CFG_TEMPLATE_INFO);
    String roleS = nestedSettings.getString("role");
    Role role;
    OffsetDateTime timestamp;
    URI sourceURI;
    TemplateType templateType;
    try {
        role = Role.valueOf(roleS);
    } catch (Exception e) {
        throw new InvalidSettingsException("Cannot parse template role \"" + roleS + "\": " + e.getMessage(), e);
    }
    switch(role) {
        case None:
            return NONE;
        case Template:
            sourceURI = null;
            timestamp = readTimestamp(nestedSettings);
            templateType = readTemplateType(nestedSettings, version);
            break;
        case Link:
            sourceURI = readURI(nestedSettings);
            templateType = null;
            timestamp = readTimestamp(nestedSettings);
            break;
        default:
            throw new InvalidSettingsException("Unsupported role: " + role);
    }
    NodeSettingsRO exampleInputDataInfo = null;
    List<FlowVariable> incomingFlowVariables = Collections.emptyList();
    if (withExampleInputDataInfo) {
        // added in 4.1, load example input data meta info
        if (nestedSettings.containsKey("exampleInputDataInfo")) {
            exampleInputDataInfo = nestedSettings.getNodeSettings("exampleInputDataInfo");
        }
        if (nestedSettings.containsKey("incomingFlowVariables")) {
            NodeSettingsRO flowVarSettings = nestedSettings.getNodeSettings("incomingFlowVariables");
            incomingFlowVariables = new ArrayList<>();
            for (String key : flowVarSettings.keySet()) {
                incomingFlowVariables.add(FlowVariable.load(flowVarSettings.getNodeSettings(key)));
            }
        }
    }
    return new MetaNodeTemplateInformation(role, templateType, sourceURI, timestamp, exampleInputDataInfo, incomingFlowVariables);
}
Also used : OffsetDateTime(java.time.OffsetDateTime) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) URI(java.net.URI) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DateTimeParseException(java.time.format.DateTimeParseException)

Aggregations

NodeSettingsRO (org.knime.core.node.NodeSettingsRO)208 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)125 File (java.io.File)49 FileInputStream (java.io.FileInputStream)47 IOException (java.io.IOException)43 InputStream (java.io.InputStream)22 LinkedHashMap (java.util.LinkedHashMap)20 NodeSettings (org.knime.core.node.NodeSettings)20 BufferedInputStream (java.io.BufferedInputStream)19 ArrayList (java.util.ArrayList)16 GZIPInputStream (java.util.zip.GZIPInputStream)15 DataTableSpec (org.knime.core.data.DataTableSpec)14 Map (java.util.Map)11 ReferencedFile (org.knime.core.internal.ReferencedFile)11 BufferedDataTable (org.knime.core.node.BufferedDataTable)10 HashMap (java.util.HashMap)9 DataColumnSpec (org.knime.core.data.DataColumnSpec)9 RowKey (org.knime.core.data.RowKey)9 DataType (org.knime.core.data.DataType)8 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)8