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());
}
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);
}
}
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);
}
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));
}
}
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;
}
Aggregations