Search in sources :

Example 26 with Config

use of org.knime.core.node.config.Config in project knime-core by knime.

the class SettingsModelColorNameColumns method saveColorColumns.

private static void saveColorColumns(final String configName, final NodeSettingsWO settings, final ColorColumn[] columns) {
    final Config config = settings.addConfig(configName);
    if (columns == null || columns.length < 1) {
        config.addStringArray(CFG_COLOR_COLUMN_NAMES, new String[0]);
        return;
    }
    final String[] columnNames = new String[columns.length];
    for (int i = 0, length = columns.length; i < length; i++) {
        columnNames[i] = columns[i].getColumnName();
    }
    config.addStringArray(CFG_COLOR_COLUMN_NAMES, columnNames);
    for (ColorColumn column : columns) {
        config.addInt(column.getColumnName(), column.getColor().getRGB());
    }
}
Also used : Config(org.knime.core.node.config.Config)

Example 27 with Config

use of org.knime.core.node.config.Config in project knime-core by knime.

the class DataTableSpec method save.

/**
 * Saves the table spec name and all {@link DataColumnSpec}s to the given
 * {@link ConfigWO} object.
 *
 * @param config the config object to save this table specs to
 */
public void save(final ConfigWO config) {
    config.addString(CFG_SPEC_NAME, m_name);
    config.addInt(CFG_NR_COLUMNS, m_columnSpecs.length);
    for (int i = 0; i < m_columnSpecs.length; i++) {
        ConfigWO column = config.addConfig(CFG_COLUMN_SPEC + i);
        m_columnSpecs[i].save(column);
    }
    if (!m_properties.isEmpty()) {
        Config propertiesConfig = config.addConfig(CFG_PROPERTIES);
        int i = 0;
        for (Map.Entry<String, String> entry : m_properties.entrySet()) {
            Config entryConfig = propertiesConfig.addConfig("prop-" + (i++));
            entryConfig.addString(CFG_PROPERTY_KEY, entry.getKey());
            entryConfig.addString(CFG_PROPERTY_VALUE, entry.getValue());
        }
    }
}
Also used : Config(org.knime.core.node.config.Config) ConfigWO(org.knime.core.node.config.ConfigWO) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 28 with Config

use of org.knime.core.node.config.Config in project knime-core by knime.

the class NodeSettingsTest method testBasicJSONIO.

@Test
public void testBasicJSONIO() throws IOException {
    m_settings.addBoolean("key-bool", true);
    m_settings.addBooleanArray("key-bool-arr", new boolean[] { true, false });
    m_settings.addString("key-string", "Sequence of Characters");
    m_settings.addStringArray("key-string-arr", new String[] { "Sequence", "of", "Characters" });
    m_settings.addDouble("key-double", 27.6);
    m_settings.addDoubleArray("key-double-arr", new double[] { 12.2, 15.0, -2.7 });
    m_settings.addInt("key-int", 12);
    m_settings.addIntArray("key-int-arr", new int[] { 1, 2, 3 });
    m_settings.addPassword("key-int", "secret", "the-real-password");
    m_settings.addTransientString("key-transient", "transient-string-value");
    Config subtree = m_settings.addConfig("key-subtree");
    subtree.addString("key-subtree-string", "value-subtree-string");
    subtree.addInt("key-subtree-int", 391);
    subtree.addDouble("key-subtree-double", -13.2);
    String jsonString = JSONConfig.toJSONString(m_settings, WriterConfig.PRETTY);
    System.out.println(jsonString);
    NodeSettings newCopy = JSONConfig.readJSON(new NodeSettings("test-settings"), new StringReader(jsonString));
    // transient strings are ... transient so not saved and we restore the original value.
    newCopy.addTransientString("key-transient", "transient-string-value");
    Assert.assertEquals(m_settings, newCopy);
    // there is more testing done in 'teardown', which includes save/load
    m_settings.addString("key-transient", "overwritten-for-persistable-string");
}
Also used : JSONConfig(org.knime.core.node.config.base.JSONConfig) WriterConfig(org.knime.core.node.config.base.JSONConfig.WriterConfig) Config(org.knime.core.node.config.Config) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 29 with Config

use of org.knime.core.node.config.Config in project knime-core by knime.

the class AttributeModel method loadModel.

/**
 * @param config the <code>Config</code> object to read from
 * @return the attribute model for the given <code>Config</code> object
 * @throws InvalidSettingsException if the settings are invalid
 */
static AttributeModel loadModel(final Config config) throws InvalidSettingsException {
    final String attrName = config.getString(ATTRIBUTE_NAME);
    final String modelType = config.getString(MODEL_TYPE);
    final boolean skipMissing = config.getBoolean(IGNORE_MISSING_VALUES);
    final int noOfMissingVals = config.getInt(NO_OF_MISSING_VALUES);
    final String invalidCause = config.getString(INVALID_CAUSE);
    final Config modelConfig = config.getConfig(MODEL_DATA_SECTION);
    final AttributeModel model;
    if (NominalAttributeModel.MODEL_TYPE.equals(modelType)) {
        model = new NominalAttributeModel(attrName, noOfMissingVals, skipMissing, modelConfig);
    } else if (NumericalAttributeModel.MODEL_TYPE.equals(modelType)) {
        model = new NumericalAttributeModel(attrName, skipMissing, noOfMissingVals, modelConfig);
    } else if (ClassAttributeModel.MODEL_TYPE.equals(modelType)) {
        model = new ClassAttributeModel(attrName, noOfMissingVals, skipMissing, modelConfig);
    } else if (BitVectorAttributeModel.MODEL_TYPE.equals(modelType)) {
        model = new BitVectorAttributeModel(attrName, skipMissing, noOfMissingVals, modelConfig);
    } else {
        throw new InvalidSettingsException("Invalid model type: " + modelType);
    }
    model.setInvalidCause(invalidCause);
    return model;
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) Config(org.knime.core.node.config.Config)

Example 30 with Config

use of org.knime.core.node.config.Config in project knime-core by knime.

the class AttributeModel method saveModel.

/**
 * @param config the <code>Config</code> object to write to
 */
void saveModel(final Config config) {
    config.addString(ATTRIBUTE_NAME, getAttributeName());
    config.addString(MODEL_TYPE, getType());
    config.addBoolean(IGNORE_MISSING_VALUES, m_ignoreMissingVals);
    config.addInt(NO_OF_MISSING_VALUES, m_noOfMissingVals);
    config.addString(INVALID_CAUSE, getInvalidCause());
    final Config internalConfig = config.addConfig(MODEL_DATA_SECTION);
    saveModelInternal(internalConfig);
}
Also used : Config(org.knime.core.node.config.Config)

Aggregations

Config (org.knime.core.node.config.Config)84 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)25 Color (java.awt.Color)10 File (java.io.File)10 FileOutputStream (java.io.FileOutputStream)8 NodeSettings (org.knime.core.node.NodeSettings)8 ArrayList (java.util.ArrayList)7 DataColumnSpec (org.knime.core.data.DataColumnSpec)7 ConfigRO (org.knime.core.node.config.ConfigRO)7 HashMap (java.util.HashMap)6 GZIPOutputStream (java.util.zip.GZIPOutputStream)6 LinkedHashMap (java.util.LinkedHashMap)5 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)5 DataTableSpec (org.knime.core.data.DataTableSpec)5 SimpleStreamableOperatorInternals (org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals)5 FileInputStream (java.io.FileInputStream)4 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 GZIPInputStream (java.util.zip.GZIPInputStream)4 DataCell (org.knime.core.data.DataCell)4