Search in sources :

Example 51 with NodeSettingsRO

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

the class ColSetting method loadSubConfigs.

/*
     * Get ColSetting objects in a map, mapping name to ColSetting.
     */
private static Map<String, ColSetting> loadSubConfigs(final NodeSettingsRO settings) throws InvalidSettingsException {
    LinkedHashMap<String, ColSetting> result = new LinkedHashMap<String, ColSetting>();
    for (String key : settings.keySet()) {
        // TODO CONFIG
        NodeSettingsRO subConfig = settings.getNodeSettings(key);
        ColSetting local = new ColSetting();
        try {
            local.loadSettings(subConfig);
        } catch (InvalidSettingsException ise) {
            throw new InvalidSettingsException("Unable to load sub config for key '" + key + "'", ise);
        }
        result.put(key, local);
    }
    return result;
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) LinkedHashMap(java.util.LinkedHashMap)

Example 52 with NodeSettingsRO

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

the class HiLiteCollectorNodeModel method loadInternals.

/**
 * {@inheritDoc}
 */
@Override
protected void loadInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    this.reset();
    File f = new File(nodeInternDir, KEY_ANNOTATIONS);
    NodeSettingsRO sett = NodeSettings.loadFromXML(new FileInputStream(f));
    RowKey[] rowKeys = sett.getRowKeyArray("row_keys", (RowKey[]) null);
    if (rowKeys != null) {
        for (RowKey key : rowKeys) {
            try {
                NodeSettingsRO subSett = sett.getNodeSettings(key.toString());
                Map<Integer, String> map = new LinkedHashMap<Integer, String>();
                for (String i : subSett.keySet()) {
                    try {
                        int idx = Integer.parseInt(i);
                        m_lastIndex = (m_lastIndex == null ? idx : Math.max(m_lastIndex, idx));
                        map.put(idx, subSett.getString(i));
                    } catch (InvalidSettingsException ise) {
                    // ignored
                    }
                }
                m_annotationMap.put(key, map);
            } catch (InvalidSettingsException ise) {
            // ignored
            }
        }
    }
}
Also used : RowKey(org.knime.core.data.RowKey) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) File(java.io.File) FileInputStream(java.io.FileInputStream) LinkedHashMap(java.util.LinkedHashMap)

Example 53 with NodeSettingsRO

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

the class RowKeyNodeModel method loadInternals.

/**
 * {@inheritDoc}
 */
@Override
protected void loadInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException {
    if (m_enableHilite.getBooleanValue()) {
        final NodeSettingsRO config = NodeSettings.loadFromXML(new FileInputStream(new File(nodeInternDir, INTERNALS_FILE_NAME)));
        try {
            m_hilite.setMapper(DefaultHiLiteMapper.load(config));
            m_hilite.addToHiLiteHandler(getInHiLiteHandler(0));
        } catch (final InvalidSettingsException ex) {
            throw new IOException(ex.getMessage());
        }
    }
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 54 with NodeSettingsRO

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

the class FlowVariable method load.

/**
 * Read a flow variable from a settings object. This is the counterpart
 * to {@link #save(NodeSettingsWO)}.
 * @param sub To load from.
 * @return A new {@link FlowVariable} read from the settings object.
 * @throws InvalidSettingsException If that fails for any reason.
 */
static FlowVariable load(final NodeSettingsRO sub) throws InvalidSettingsException {
    String name = sub.getString("name");
    String typeS = sub.getString("class");
    if (typeS == null || name == null) {
        throw new InvalidSettingsException("name or type is null");
    }
    Type varType;
    try {
        varType = Type.valueOf(typeS);
    } catch (final IllegalArgumentException e) {
        throw new InvalidSettingsException("invalid type " + typeS);
    }
    FlowVariable v;
    switch(varType) {
        case DOUBLE:
            v = new FlowVariable(name, sub.getDouble("value"));
            break;
        case INTEGER:
            v = new FlowVariable(name, sub.getInt("value"));
            break;
        case STRING:
            v = new FlowVariable(name, sub.getString("value"));
            break;
        case CREDENTIALS:
            NodeSettingsRO subSettings = sub.getNodeSettings("value");
            CredentialsFlowVariableValue credentialsValue = CredentialsFlowVariableValue.load(subSettings);
            v = new FlowVariable(name, credentialsValue);
            break;
        default:
            throw new InvalidSettingsException("Unknown type " + varType);
    }
    return v;
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) CredentialsFlowVariableValue(org.knime.core.node.workflow.CredentialsStore.CredentialsFlowVariableValue)

Example 55 with NodeSettingsRO

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

the class FileSubNodeContainerPersistor method preLoadNodeContainer.

/**
 * {@inheritDoc}
 */
@Override
public void preLoadNodeContainer(final WorkflowPersistor parentPersistor, final NodeSettingsRO parentSettings, final LoadResult result) throws InvalidSettingsException, IOException {
    super.preLoadNodeContainer(parentPersistor, parentSettings, result);
    // assigned by super
    NodeSettingsRO nodeSettings = getNodeSettings();
    m_workflowPersistor = createWorkflowPersistor(getMetaPersistor().getNodeSettingsFile(), getWorkflowDataRepository());
    if (m_nameOverwrite != null) {
        m_workflowPersistor.setNameOverwrite(m_nameOverwrite);
        m_nameOverwrite = null;
    }
    try {
        int i = nodeSettings.getInt("virtual-in-ID");
        CheckUtils.checkSetting(i >= 0, "Node ID < 0: %d", i);
        m_virtualInNodeIDSuffix = i;
    } catch (InvalidSettingsException e) {
        String error = "Can't load virtual input node ID: " + e.getMessage();
        result.addError(error);
        getLogger().error(error, e);
        setDirtyAfterLoad();
    }
    try {
        int i = nodeSettings.getInt("virtual-in-ID");
        CheckUtils.checkSetting(i >= 0, "Node ID < 0: %d", i);
        m_virtualInNodeIDSuffix = i;
    } catch (InvalidSettingsException e) {
        String error = "Can't load virtual input node ID: " + e.getMessage();
        result.addError(error);
        getLogger().error(error, e);
        setDirtyAfterLoad();
    }
    Set<String> inportSetKeys = Collections.emptySet();
    NodeSettingsRO inportsSettings = null;
    try {
        inportsSettings = nodeSettings.getNodeSettings("inports");
        // input of subnode is represented by output of virtual in node.
        inportSetKeys = inportsSettings.keySet();
        // an extra for hidden flow var port
        m_inPortTemplates = new WorkflowPortTemplate[inportSetKeys.size() + 1];
        m_inPortTemplates[0] = new WorkflowPortTemplate(0, FlowVariablePortObject.TYPE_OPTIONAL);
        for (int i = 1; i < m_inPortTemplates.length; i++) {
            // fallback values, correctly set below
            m_inPortTemplates[i] = new WorkflowPortTemplate(i, BufferedDataTable.TYPE);
        }
    } catch (InvalidSettingsException e) {
        String error = "Can't load virtual input port information: " + e.getMessage();
        result.addError(error);
        getLogger().error(error, e);
        setDirtyAfterLoad();
        m_inPortTemplates = new WorkflowPortTemplate[0];
    }
    for (String key : inportSetKeys) {
        try {
            @SuppressWarnings("null") NodeSettingsRO inportSetting = inportsSettings.getNodeSettings(key);
            WorkflowPortTemplate portTemplate = loadPort(inportSetting, inportSetKeys.size());
            m_inPortTemplates[portTemplate.getPortIndex()] = portTemplate;
        } catch (InvalidSettingsException e) {
            String error = "Could not load input port information: " + e.getMessage();
            result.addError(error);
            getLogger().error(error, e);
            setDirtyAfterLoad();
            continue;
        }
    }
    try {
        m_componentMetadata = ComponentMetadata.load(nodeSettings, getLoadVersion());
    } catch (InvalidSettingsException e) {
        String error = "Unable to load component metadata: " + e.getMessage();
        getLogger().debug(error, e);
        setDirtyAfterLoad();
        result.addError(error);
        m_componentMetadata = ComponentMetadata.NONE;
    }
    try {
        if (m_templateInformation != null) {
            // template information was set after construction (this node is a link created from a template)
            assert m_templateInformation.getRole() == Role.Link;
        } else {
            m_templateInformation = MetaNodeTemplateInformation.load(nodeSettings, getLoadVersion());
            CheckUtils.checkSettingNotNull(m_templateInformation, "No template information");
        }
    } catch (InvalidSettingsException e) {
        String error = "Unable to load workflow template information: " + e.getMessage();
        getLogger().debug(error, e);
        setDirtyAfterLoad();
        result.addError(error);
        m_templateInformation = MetaNodeTemplateInformation.NONE;
    }
    try {
        int i = nodeSettings.getInt("virtual-out-ID");
        CheckUtils.checkSetting(i >= 0, "Node ID < 0: %d", i);
        m_virtualOutNodeIDSuffix = i;
    } catch (InvalidSettingsException e) {
        String error = "Can't load virtual output node ID: " + e.getMessage();
        result.addError(error);
        getLogger().error(error, e);
        setDirtyAfterLoad();
    }
    Set<String> outportSetKeys = Collections.emptySet();
    NodeSettingsRO outportsSettings = null;
    try {
        outportsSettings = nodeSettings.getNodeSettings("outports");
        // output of subnode is represented by input of virtual out node.
        outportSetKeys = outportsSettings.keySet();
        m_outPortTemplates = new WorkflowPortTemplate[outportSetKeys.size() + 1];
        m_outPortTemplates[0] = new WorkflowPortTemplate(0, FlowVariablePortObject.TYPE_OPTIONAL);
        for (int i = 1; i < m_outPortTemplates.length; i++) {
            // fallback values, correctly set below
            m_outPortTemplates[i] = new WorkflowPortTemplate(i, BufferedDataTable.TYPE);
        }
    } catch (InvalidSettingsException e) {
        String error = "Can't load virtual output port information: " + e.getMessage();
        result.addError(error);
        getLogger().error(error, e);
        setDirtyAfterLoad();
        m_outPortTemplates = new WorkflowPortTemplate[0];
    }
    for (String key : outportSetKeys) {
        try {
            @SuppressWarnings("null") NodeSettingsRO outportSetting = outportsSettings.getNodeSettings(key);
            WorkflowPortTemplate portTemplate = loadPort(outportSetting, outportSetKeys.size());
            m_outPortTemplates[portTemplate.getPortIndex()] = portTemplate;
        } catch (InvalidSettingsException e) {
            String error = "Could not load output port information: " + e.getMessage();
            result.addError(error);
            getLogger().error(error, e);
            setDirtyAfterLoad();
            continue;
        }
    }
    // added in 3.1, updated with 4.2
    m_subnodeLayoutStringProvider = new SubnodeContainerLayoutStringProvider(nodeSettings.getString("layoutJSON", ""));
    // added in 3.7, load with default values
    m_customCSS = nodeSettings.getString("customCSS", "");
    m_hideInWizard = nodeSettings.getBoolean("hideInWizard", false);
    m_workflowPersistor.preLoadNodeContainer(parentPersistor, parentSettings, result);
    // added in 4.3
    m_subnodeConfigurationStringProvider = new SubnodeContainerConfigurationStringProvider(nodeSettings.getString("configurationLayoutJSON", ""));
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) WorkflowPortTemplate(org.knime.core.node.workflow.WorkflowPersistor.WorkflowPortTemplate)

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