Search in sources :

Example 71 with NodeSettingsRO

use of org.knime.core.node.NodeSettingsRO 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 72 with NodeSettingsRO

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

the class FileNativeNodeContainerPersistor method loadSettingsForNode.

/**
 * {@inheritDoc}
 */
@Override
NodeSettingsRO loadSettingsForNode(final LoadResult loadResult) throws IOException {
    NodeSettingsRO nodeSettings = getNodeSettings();
    if (getLoadVersion().ordinal() < LoadVersion.V280.ordinal()) {
        FileNodeContainerMetaPersistor metaPersistor = getMetaPersistor();
        ReferencedFile nodeFile;
        try {
            nodeFile = loadNodeFile(nodeSettings);
        } catch (InvalidSettingsException e) {
            String error = "Unable to load node settings file for node with ID suffix " + metaPersistor.getNodeIDSuffix() + " (node \"" + m_node.getName() + "\"): " + e.getMessage();
            loadResult.addError(error);
            getLogger().debug(error, e);
            setDirtyAfterLoad();
            return new NodeSettings("empty");
        }
        File configFile = nodeFile.getFile();
        if (configFile == null || !configFile.isFile() || !configFile.canRead()) {
            String error = "Unable to read node settings file for node with ID suffix " + metaPersistor.getNodeIDSuffix() + " (node \"" + m_node.getName() + "\"), file \"" + configFile + "\"";
            loadResult.addError(error);
            // also implies dirty
            setNeedsResetAfterLoad();
            return new NodeSettings("empty");
        } else {
            InputStream in = new FileInputStream(configFile);
            try {
                in = getParentPersistor().decipherInput(in);
                return NodeSettings.loadFromXML(new BufferedInputStream(in));
            } finally {
                try {
                    in.close();
                } catch (IOException e) {
                    getLogger().error("Failed to close input stream on \"" + configFile.getAbsolutePath() + "\"", e);
                }
            }
        }
    } else {
        return nodeSettings;
    }
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) IOException(java.io.IOException) ReferencedFile(org.knime.core.internal.ReferencedFile) ReferencedFile(org.knime.core.internal.ReferencedFile) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 73 with NodeSettingsRO

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

the class DataColumnSpecFilterConfiguration method loadConfigurationInDialogChild.

/**
 * {@inheritDoc}
 */
@Override
protected void loadConfigurationInDialogChild(final NodeSettingsRO settings, final String[] names) {
    super.loadConfigurationInDialogChild(settings, names);
    NodeSettingsRO configSettings;
    try {
        configSettings = settings.getNodeSettings(TypeFilterConfigurationImpl.TYPE);
    } catch (InvalidSettingsException e) {
        configSettings = new NodeSettings("empty");
    }
    m_typeConfig.loadConfigurationInDialog(configSettings, m_lastSpec);
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO)

Example 74 with NodeSettingsRO

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

the class AnnotationData method load.

/**
 * loads new values.
 * @param config To load from
 * @param loadVersion Version to load
 * @throws InvalidSettingsException If fails
 * @since 3.7
 */
public void load(final NodeSettingsRO config, final LoadVersion loadVersion) throws InvalidSettingsException {
    setText(config.getString("text"));
    setBgColor(config.getInt("bgcolor"));
    int x = config.getInt("x-coordinate");
    int y = config.getInt("y-coordinate");
    int width = config.getInt("width");
    int height = config.getInt("height");
    // default to 0 for backward compatibility
    int borderSize = config.getInt("borderSize", 0);
    // default for backward compatibility
    int borderColor = config.getInt("borderColor", 0);
    // default for backward compatibility
    int defFontSize = config.getInt("defFontSize", -1);
    // added in 3.0
    m_version = config.getInt("annotation-version", VERSION_OLD);
    TextAlignment alignment = TextAlignment.LEFT;
    if (loadVersion.ordinal() >= LoadVersion.V250.ordinal()) {
        String alignmentS = config.getString("alignment");
        try {
            alignment = TextAlignment.valueOf(alignmentS);
        } catch (Exception e) {
            throw new InvalidSettingsException("Invalid alignment: " + alignmentS, e);
        }
    }
    setDimension(x, y, width, height);
    setAlignment(alignment);
    setBorderSize(borderSize);
    setBorderColor(borderColor);
    setDefaultFontSize(defFontSize);
    NodeSettingsRO styleConfigs = config.getNodeSettings("styles");
    StyleRange[] styles = new StyleRange[styleConfigs.getChildCount()];
    int i = 0;
    for (String key : styleConfigs.keySet()) {
        NodeSettingsRO cur = styleConfigs.getNodeSettings(key);
        styles[i++] = StyleRange.load(cur);
    }
    setStyleRanges(styles);
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Example 75 with NodeSettingsRO

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

the class PMMLPortObjectSpec method loadFrom.

/**
 * @param in stream reading the relevant files
 * @return a completely loaded port object spec with {@link DataTableSpec},
 *         and the sets of learning, ignored and target columns.
 * @throws IOException if something goes wrong
 * @throws InvalidSettingsException if something goes wrong
 */
public static PMMLPortObjectSpec loadFrom(final PortObjectSpecZipInputStream in) throws IOException, InvalidSettingsException {
    NonClosableInputStream noCloseIn = new NonClosableInputStream(in);
    // the data table spec
    in.getNextEntry();
    // TODO: sanitycheck if name is the same
    NodeSettingsRO settings = NodeSettings.loadFromXML(noCloseIn);
    DataTableSpec dataTableSpec = DataTableSpec.load(settings);
    // the mining schema
    in.getNextEntry();
    // TODO: sanity check if names are consistent
    NodeSettingsRO miningSchemaSettings = NodeSettings.loadFromXML(noCloseIn);
    List<String> learningCols = new LinkedList<String>();
    for (String colName : miningSchemaSettings.getStringArray(LEARNING_KEY)) {
        DataColumnSpec colSpec = dataTableSpec.getColumnSpec(colName);
        if (colSpec == null) {
            throw new InvalidSettingsException("Column " + colName + " is not in DataTableSpec");
        }
        learningCols.add(colName);
    }
    List<String> targetCols = new LinkedList<String>();
    for (String colName : miningSchemaSettings.getStringArray(TARGET_KEY)) {
        DataColumnSpec colSpec = dataTableSpec.getColumnSpec(colName);
        if (colSpec == null) {
            throw new InvalidSettingsException("Column " + colName + " is not in DataTableSpec");
        }
        targetCols.add(colName);
    }
    // the preprocessing settings if existent
    ZipEntry preprocEntry = in.getNextEntry();
    List<String> activeCols = null;
    if (preprocEntry != null) {
        NodeSettingsRO preprocSettings = NodeSettings.loadFromXML(noCloseIn);
        activeCols = new LinkedList<String>();
        for (String colName : preprocSettings.getStringArray(PREPROC_COL_KEY)) {
            DataColumnSpec colSpec = dataTableSpec.getColumnSpec(colName);
            if (colSpec == null) {
                throw new InvalidSettingsException("Column " + colName + " is not in DataTableSpec");
            }
            activeCols.add(colName);
        }
    }
    return new PMMLPortObjectSpec(dataTableSpec, activeCols, learningCols, targetCols);
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NonClosableInputStream(org.knime.core.data.util.NonClosableInputStream) ZipEntry(java.util.zip.ZipEntry) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) LinkedList(java.util.LinkedList)

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