Search in sources :

Example 86 with Config

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

the class MappingFrameworkTest method consumptionPathSerializeTest.

/**
 * Test serialization of consumption path
 *
 * @throws InvalidSettingsException
 */
@Test
public void consumptionPathSerializeTest() throws InvalidSettingsException {
    MappingFramework.forDestinationType(H2ODestination.class).register(stringConsumer);
    final ConsumptionPath path = new ConsumptionPath(DataCellToJavaConverterRegistry.getInstance().getConverterFactories(StringCell.TYPE, String.class).stream().findFirst().get(), MappingFramework.forDestinationType(H2ODestination.class).getFactory("java.lang.String->STR").get());
    final Config config = new NodeSettings("Test");
    SerializeUtil.storeConsumptionPath(path, config, "the_path");
    final Optional<ConsumptionPath> loadedPath = SerializeUtil.loadConsumptionPath(config, MappingFramework.forDestinationType(H2ODestination.class), "the_path");
    assertTrue(loadedPath.isPresent());
    assertEquals(path, loadedPath.get());
}
Also used : ConsumptionPath(org.knime.core.data.convert.map.ConsumptionPath) NodeSettings(org.knime.core.node.NodeSettings) Config(org.knime.core.node.config.Config) Test(org.junit.Test)

Example 87 with Config

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

the class DataCellSerializerFactory method loadFrom.

/**
 * Load state of object
 *
 * @param settings used to store the object
 * @throws InvalidSettingsException
 */
public void loadFrom(final ConfigRO settings) throws InvalidSettingsException {
    final Config childConfig = settings.getConfig(CFG_SERIALIZER_MAPPINGS);
    final String[] cells = childConfig.getStringArray(CFG_SERIALIZER_CELL_TYPES);
    final byte[] indices = childConfig.getByteArray(CFG_SERIALIZER_INDICES);
    for (int i = 0; i < indices.length; i++) {
        // NOSONAR
        final Class<? extends DataCell> type = REGISTRY.getCellClass(cells[i]).get();
        final DataCellSerializerInfo info = // NOSONAR
        new DataCellSerializerInfo(type, indices[i], REGISTRY.getSerializer(type).get());
        m_byIdx[indices[i]] = info;
        m_byType.put(type, info);
    }
}
Also used : Config(org.knime.core.node.config.Config)

Example 88 with Config

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

the class WorkflowPortObjectSpec method loadOutputs.

private static Pair<List<Output>, List<String>> loadOutputs(final ModelContentRO model) throws InvalidSettingsException {
    int size = model.getInt("num_outputs");
    List<Output> outputs = new ArrayList<>(size);
    List<String> outputIDs = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
        Config outputConf = model.getConfig("output_" + i);
        PortID connectedPort = null;
        if (outputConf.containsKey("connected_port")) {
            connectedPort = loadPortID(outputConf.getConfig("connected_port"));
        }
        Output output = new Output(outputConf.containsKey("type") ? loadPortType(outputConf.getConfig("type")) : null, outputConf.containsKey("spec") ? loadTableSpec(outputConf.getConfig("spec")) : null, connectedPort);
        outputs.add(output);
        outputIDs.add(outputConf.getString("id"));
    }
    return Pair.create(outputs, outputIDs);
}
Also used : Config(org.knime.core.node.config.Config) Output(org.knime.core.node.workflow.capture.WorkflowSegment.Output) ArrayList(java.util.ArrayList) PortID(org.knime.core.node.workflow.capture.WorkflowSegment.PortID)

Example 89 with Config

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

the class WorkflowPortObjectSpec method saveOutputs.

private static void saveOutputs(final ModelContentWO model, final List<Output> outputs, final List<String> outputIDs) {
    model.addInt("num_outputs", outputs.size());
    for (int i = 0; i < outputs.size(); i++) {
        Output output = outputs.get(i);
        Config outputConf = model.addConfig("output_" + i);
        if (output.getType().isPresent()) {
            Config type = outputConf.addConfig("type");
            savePortType(type, output.getType().get());
        }
        Optional<DataTableSpec> optionalSpec = output.getSpec();
        if (optionalSpec.isPresent()) {
            Config spec = outputConf.addConfig("spec");
            saveSpec(spec, output.getSpec().get());
        }
        Optional<PortID> connectedPort = output.getConnectedPort();
        if (connectedPort.isPresent()) {
            Config portConf = outputConf.addConfig("connected_port");
            savePortID(portConf, connectedPort.get());
        }
        outputConf.addString("id", outputIDs.get(i));
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) Config(org.knime.core.node.config.Config) Output(org.knime.core.node.workflow.capture.WorkflowSegment.Output) PortID(org.knime.core.node.workflow.capture.WorkflowSegment.PortID)

Example 90 with Config

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

the class VirtualSubNodeInputNodeFactory method loadPortTypeList.

/**
 * @param config
 * @return TODO
 * @throws InvalidSettingsException
 */
static PortType[] loadPortTypeList(final ConfigRO config) throws InvalidSettingsException {
    Set<String> keySet = config.keySet();
    PortType[] outTypes = new PortType[keySet.size()];
    for (String s : keySet) {
        ConfigRO portConfig = config.getConfig(s);
        int index = portConfig.getInt("index");
        CheckUtils.checkSetting(index >= 0 && index < outTypes.length, "Invalid port index must be in [0, %d]: %d", keySet.size() - 1, index);
        Config portTypeConfig = portConfig.getConfig("type");
        PortType type = PortType.load(portTypeConfig);
        outTypes[index] = type;
    }
    int invalidIndex = Arrays.asList(outTypes).indexOf(null);
    if (invalidIndex >= 0) {
        throw new InvalidSettingsException("Unassigned port type at index " + invalidIndex);
    }
    return outTypes;
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) Config(org.knime.core.node.config.Config) ConfigRO(org.knime.core.node.config.ConfigRO) PortType(org.knime.core.node.port.PortType)

Aggregations

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