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