use of org.knime.core.node.NodeSettings in project knime-core by knime.
the class DataColumnSpecFilterConfiguration method loadConfigurationInDialogChild.
/**
* {@inheritDoc}
*/
@Override
protected void loadConfigurationInDialogChild(final NodeSettingsRO settings, final String[] names) {
super.loadConfigurationInDialogChild(settings, names);
NodeSettingsRO configSettings;
try {
configSettings = settings.getNodeSettings(TypeFilterConfigurationImpl.TYPE);
} catch (InvalidSettingsException e) {
configSettings = new NodeSettings("empty");
}
m_typeConfig.loadConfigurationInDialog(configSettings, m_lastSpec);
}
use of org.knime.core.node.NodeSettings in project knime-core by knime.
the class BatchExecutor method setNodeOptions.
private static void setNodeOptions(final Collection<Option> options, final WorkflowManager wfm) throws InvalidSettingsException, IllegalOptionException {
for (Option o : options) {
int[] idPath = o.m_nodeIDs;
NodeID subID = new NodeID(wfm.getID(), idPath[0]);
NodeContainer cont = null;
try {
cont = wfm.getNodeContainer(subID);
for (int i = 1; i < idPath.length; i++) {
if (cont instanceof WorkflowManager) {
WorkflowManager subWM = (WorkflowManager) cont;
subID = new NodeID(subID, idPath[i]);
cont = subWM.getNodeContainer(subID);
} else {
cont = null;
}
}
} catch (IllegalArgumentException ex) {
// throw by getNodeContainer if no node with the id exists
cont = null;
}
if (cont == null) {
LOGGER.warn("No node with id " + Arrays.toString(idPath) + " found.");
} else {
WorkflowManager parent = cont.getParent();
NodeSettings settings = new NodeSettings("something");
parent.saveNodeSettings(cont.getID(), settings);
NodeSettings model = settings.getNodeSettings(Node.CFG_MODEL);
String[] splitName = o.m_name.split("/");
String name = splitName[splitName.length - 1];
String[] pathElements = new String[splitName.length - 1];
System.arraycopy(splitName, 0, pathElements, 0, pathElements.length);
for (String s : pathElements) {
model = model.getNodeSettings(s);
}
if ("int".equals(o.m_type)) {
model.addInt(name, Integer.parseInt(o.m_value));
} else if ("long".equals(o.m_type)) {
model.addLong(name, Long.parseLong(o.m_value));
} else if ("short".equals(o.m_type)) {
model.addShort(name, Short.parseShort(o.m_value));
} else if ("byte".equals(o.m_type)) {
model.addByte(name, Byte.parseByte(o.m_value));
} else if ("boolean".equals(o.m_type)) {
model.addBoolean(name, Boolean.parseBoolean(o.m_value));
} else if ("char".equals(o.m_type)) {
model.addChar(name, o.m_value.charAt(0));
} else if ("float".equals(o.m_type) || ("double".equals(o.m_type))) {
model.addDouble(name, Double.parseDouble(o.m_value));
} else if ("String".equals(o.m_type)) {
model.addString(name, o.m_value);
} else if ("StringCell".equals(o.m_type)) {
model.addDataCell(name, new StringCell(o.m_value));
} else if ("DoubleCell".equals(o.m_type)) {
double d = Double.parseDouble(o.m_value);
model.addDataCell(name, new DoubleCell(d));
} else if ("IntCell".equals(o.m_type)) {
int i = Integer.parseInt(o.m_value);
model.addDataCell(name, new IntCell(i));
} else if ("LongCell".equals(o.m_type)) {
long i = Long.parseLong(o.m_value);
model.addDataCell(name, new LongCell(i));
} else {
throw new IllegalOptionException("Unknown option type for " + o.m_name + ": " + o.m_type);
}
parent.loadNodeSettings(cont.getID(), settings);
}
}
}
use of org.knime.core.node.NodeSettings in project knime-core by knime.
the class DataColumnSpecFilterPanel method updateWithNewConfiguration.
/**
* Updates the panel by using the given {@link DataColumnSpecFilterConfiguration} object.
* This method allows for example to change the allowed column type on the fly.
* @param newConfig the new {@link DataColumnSpecFilterConfiguration} to use
* @since 2.10
*/
public void updateWithNewConfiguration(final DataColumnSpecFilterConfiguration newConfig) {
DataColumnSpecFilterConfiguration tempConfiguration = new DataColumnSpecFilterConfiguration(newConfig.getConfigRootName());
saveConfiguration(tempConfiguration);
NodeSettings tempSettings = new NodeSettings("tempSettings");
tempConfiguration.saveConfiguration(tempSettings);
newConfig.loadConfigurationInDialog(tempSettings, m_spec);
loadConfiguration(newConfig, m_spec);
}
use of org.knime.core.node.NodeSettings in project knime-core by knime.
the class FileWorkflowPersistor method preLoadNodeContainer.
/**
* {@inheritDoc}
*/
@Override
public void preLoadNodeContainer(final WorkflowPersistor parentPersistor, final NodeSettingsRO parentSettings, final LoadResult loadResult) throws InvalidSettingsException, IOException {
m_parentPersistor = parentPersistor;
final ReferencedFile knimeFile = getWorkflowKNIMEFile();
if (knimeFile == null || !knimeFile.getFile().isFile()) {
setDirtyAfterLoad();
String error = "Can't read workflow file \"" + knimeFile + "\"";
throw new IOException(error);
}
// workflow.knime (or template.knime)
File nodeFile = knimeFile.getFile();
ReferencedFile parentRef = knimeFile.getParent();
if (parentRef == null) {
setDirtyAfterLoad();
throw new IOException("Parent directory of file \"" + knimeFile + "\" is not represented by " + ReferencedFile.class.getSimpleName() + " object");
}
m_mustWarnOnDataLoadError = loadIfMustWarnOnDataLoadError(parentRef.getFile());
NodeSettingsRO subWFSettings;
try {
InputStream in = new FileInputStream(nodeFile);
if (m_parentPersistor != null) {
// real metanode, not a project
// the workflow.knime (or template.knime) file is not encrypted
// with this metanode's cipher but possibly with a parent
// cipher
in = m_parentPersistor.decipherInput(in);
}
in = new BufferedInputStream(in);
subWFSettings = NodeSettings.loadFromXML(in);
} catch (IOException ioe) {
setDirtyAfterLoad();
throw ioe;
}
m_workflowSett = subWFSettings;
try {
if (m_nameOverwrite != null) {
m_name = m_nameOverwrite;
} else {
m_name = loadWorkflowName(m_workflowSett);
}
} catch (InvalidSettingsException e) {
String error = "Unable to load workflow name: " + e.getMessage();
getLogger().debug(error, e);
setDirtyAfterLoad();
loadResult.addError(error);
m_name = null;
}
try {
m_workflowCipher = loadWorkflowCipher(getLoadVersion(), m_workflowSett);
} catch (InvalidSettingsException e) {
String error = "Unable to load workflow cipher: " + e.getMessage();
getLogger().debug(error, e);
setDirtyAfterLoad();
loadResult.addError(error);
m_workflowCipher = WorkflowCipher.NULL_CIPHER;
}
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(m_workflowSett, 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();
loadResult.addError(error);
m_templateInformation = MetaNodeTemplateInformation.NONE;
}
try {
m_authorInformation = loadAuthorInformation(m_workflowSett);
} catch (InvalidSettingsException e) {
String error = "Unable to load workflow author information: " + e.getMessage();
getLogger().debug(error, e);
setDirtyAfterLoad();
loadResult.addError(error);
m_authorInformation = AuthorInformation.UNKNOWN;
}
try {
m_workflowVariables = loadWorkflowVariables(m_workflowSett);
} catch (InvalidSettingsException e) {
String error = "Unable to load workflow variables: " + e.getMessage();
getLogger().debug(error, e);
setDirtyAfterLoad();
loadResult.addError(error);
m_workflowVariables = Collections.emptyList();
}
try {
m_credentials = loadCredentials(m_workflowSett);
// request to initialize credentials - if available
if (m_credentials != null && !m_credentials.isEmpty()) {
m_credentials = getLoadHelper().loadCredentials(m_credentials);
}
} catch (InvalidSettingsException e) {
String error = "Unable to load credentials: " + e.getMessage();
getLogger().debug(error, e);
setDirtyAfterLoad();
loadResult.addError(error);
m_credentials = Collections.emptyList();
}
try {
m_workflowAnnotations = loadWorkflowAnnotations(m_workflowSett);
} catch (InvalidSettingsException e) {
String error = "Unable to load workflow annotations: " + e.getMessage();
getLogger().debug(error, e);
setDirtyAfterLoad();
loadResult.addError(error);
m_workflowAnnotations = Collections.emptyList();
}
try {
m_wizardState = loadWizardState(m_workflowSett);
} catch (InvalidSettingsException e) {
String error = "Unable to load wizard state: " + e.getMessage();
getLogger().debug(error, e);
setDirtyAfterLoad();
loadResult.addError(error);
m_wizardState = null;
}
NodeSettingsRO metaFlowParentSettings = new NodeSettings("fake_parent_settings");
try {
metaFlowParentSettings = readParentSettings();
} catch (IOException e1) {
String error = "Errors reading settings file: " + e1.getMessage();
getLogger().warn(error, e1);
setDirtyAfterLoad();
loadResult.addError(error);
}
boolean isResetRequired = m_metaPersistor.load(subWFSettings, metaFlowParentSettings, loadResult);
if (isResetRequired) {
setNeedsResetAfterLoad();
}
if (m_metaPersistor.isDirtyAfterLoad()) {
setDirtyAfterLoad();
}
/* read in and outports */
NodeSettingsRO inPortsEnum = EMPTY_SETTINGS;
try {
NodeSettingsRO inPorts = loadInPortsSetting(m_workflowSett);
if (inPorts != null) {
inPortsEnum = loadInPortsSettingsEnum(inPorts);
}
} catch (InvalidSettingsException e) {
String error = "Can't load workflow ports, config not found";
getLogger().debug(error, e);
setDirtyAfterLoad();
loadResult.addError(error);
setNeedsResetAfterLoad();
}
int inPortCount = inPortsEnum.keySet().size();
m_inPortTemplates = new WorkflowPortTemplate[inPortCount];
for (String key : inPortsEnum.keySet()) {
WorkflowPortTemplate p;
try {
NodeSettingsRO sub = inPortsEnum.getNodeSettings(key);
p = loadInPortTemplate(sub);
} catch (InvalidSettingsException e) {
String error = "Can't load workflow inport (internal ID \"" + key + "\", skipping it: " + e.getMessage();
getLogger().debug(error, e);
setDirtyAfterLoad();
loadResult.addError(error);
setNeedsResetAfterLoad();
continue;
}
int index = p.getPortIndex();
if (index < 0 || index >= inPortCount) {
setDirtyAfterLoad();
loadResult.addError("Invalid inport index " + index);
setNeedsResetAfterLoad();
continue;
}
if (m_inPortTemplates[index] != null) {
setDirtyAfterLoad();
loadResult.addError("Duplicate inport definition for index: " + index);
}
m_inPortTemplates[index] = p;
}
for (int i = 0; i < m_inPortTemplates.length; i++) {
if (m_inPortTemplates[i] == null) {
setDirtyAfterLoad();
loadResult.addError("Assigning fallback port type for " + "missing input port " + i);
m_inPortTemplates[i] = new WorkflowPortTemplate(i, FALLBACK_PORTTYPE);
}
}
NodeSettingsRO outPortsEnum = EMPTY_SETTINGS;
try {
NodeSettingsRO outPorts = loadOutPortsSetting(m_workflowSett);
if (outPorts != null) {
outPortsEnum = loadOutPortsSettingsEnum(outPorts);
}
} catch (InvalidSettingsException e) {
String error = "Can't load workflow out ports, config not found: " + e.getMessage();
getLogger().debug(error, e);
setDirtyAfterLoad();
loadResult.addError(error);
}
int outPortCount = outPortsEnum.keySet().size();
m_outPortTemplates = new WorkflowPortTemplate[outPortCount];
for (String key : outPortsEnum.keySet()) {
WorkflowPortTemplate p;
try {
NodeSettingsRO sub = outPortsEnum.getNodeSettings(key);
p = loadOutPortTemplate(sub);
} catch (InvalidSettingsException e) {
String error = "Can't load workflow outport (internal ID \"" + key + "\", skipping it: " + e.getMessage();
getLogger().debug(error, e);
setDirtyAfterLoad();
loadResult.addError(error);
setNeedsResetAfterLoad();
continue;
}
int index = p.getPortIndex();
if (index < 0 || index >= outPortCount) {
setDirtyAfterLoad();
loadResult.addError("Invalid inport index " + index);
setNeedsResetAfterLoad();
continue;
}
if (m_outPortTemplates[index] != null) {
setDirtyAfterLoad();
loadResult.addError("Duplicate outport definition for index: " + index);
}
m_outPortTemplates[index] = p;
}
for (int i = 0; i < m_outPortTemplates.length; i++) {
if (m_outPortTemplates[i] == null) {
setDirtyAfterLoad();
loadResult.addError("Assigning fallback port type for " + "missing output port " + i);
m_outPortTemplates[i] = new WorkflowPortTemplate(i, FALLBACK_PORTTYPE);
}
}
boolean hasPorts = inPortCount > 0 || outPortCount > 0;
if (hasPorts && m_isProject) {
throw new InvalidSettingsException(String.format("Workflow \"%s\"" + " is not a project as it has ports (%d in, %d out)", nodeFile.getAbsoluteFile(), inPortCount, outPortCount));
}
NodeSettingsRO inPorts = EMPTY_SETTINGS;
NodeUIInformation inPortsBarUIInfo = null;
String uiInfoClassName = null;
try {
inPorts = loadInPortsSetting(m_workflowSett);
if (inPorts != null) {
uiInfoClassName = loadInPortsBarUIInfoClassName(inPorts);
}
} catch (InvalidSettingsException e) {
String error = "Unable to load class name for inport bar's " + "UI information: " + e.getMessage();
getLogger().debug(error, e);
setDirtyAfterLoad();
loadResult.addError(error);
}
if (uiInfoClassName != null) {
try {
if (!getLoadVersion().isOlderThan(LoadVersion.V200)) {
inPortsBarUIInfo = loadNodeUIInformation(inPorts);
}
} catch (InvalidSettingsException e) {
String error = "Unable to load inport bar's UI information: " + e.getMessage();
getLogger().debug(error, e);
setDirtyAfterLoad();
loadResult.addError(error);
inPortsBarUIInfo = null;
}
}
NodeSettingsRO outPorts = null;
m_inPortsBarUIInfo = inPortsBarUIInfo;
NodeUIInformation outPortsBarUIInfo = null;
uiInfoClassName = null;
try {
// TODO probably not necessary anymore to store the ui information class name (it's node ui information anyway)
outPorts = loadOutPortsSetting(m_workflowSett);
if (outPorts != null) {
uiInfoClassName = loadOutPortsBarUIInfoClassName(outPorts);
}
} catch (InvalidSettingsException e) {
String error = "Unable to load class name for outport bar's UI information" + ", no UI information available: " + e.getMessage();
setDirtyAfterLoad();
getLogger().debug(error, e);
loadResult.addError(error);
}
if (uiInfoClassName != null) {
try {
if (!getLoadVersion().isOlderThan(LoadVersion.V200)) {
outPortsBarUIInfo = loadNodeUIInformation(outPorts);
}
} catch (InvalidSettingsException e) {
String error = "Unable to load outport bar's UI information: " + e.getMessage();
getLogger().debug(error, e);
setDirtyAfterLoad();
loadResult.addError(error);
outPortsBarUIInfo = null;
}
}
m_outPortsBarUIInfo = outPortsBarUIInfo;
try {
m_editorUIInfo = loadEditorUIInformation(m_workflowSett);
} catch (InvalidSettingsException e) {
String error = "Unable to load editor UI information: " + e.getMessage();
getLogger().debug(error, e);
setDirtyAfterLoad();
loadResult.addError(error);
m_editorUIInfo = null;
}
}
use of org.knime.core.node.NodeSettings in project knime-core by knime.
the class NodeExecutorJobManagerDialogTab method loadSettings.
/**
* Takes over the settings from the argument and displays them in the panel.
*
* @param settings the settings to load into the components
* @param inSpecs the specs of the input port objects
*/
public void loadSettings(final NodeContainerSettings settings, final PortObjectSpec[] inSpecs) {
// we must store the port specs in case job manager selection changes
m_lastPortSpecs = inSpecs;
// select the job manager in the combo box
NodeExecutionJobManager newMgr = settings.getJobManager();
String id = newMgr == null ? DEFAULT_ENTRY : newMgr.getID();
m_jobManagerSelect.setSelectedItem(id);
if (DEFAULT_ENTRY.equals(id)) {
// must also have selected this entry
assert DEFAULT_ENTRY.equals(m_jobManagerSelect.getSelectedItem());
} else if (m_jobManagerSelect.getSelectedItem().equals(id)) {
// if the job manager exists in the list apply the settings
NodeSettings s = new NodeSettings("job_manager_settings");
m_currentPanel.updateInputSpecs(inSpecs);
newMgr.save(s);
m_currentPanel.loadSettings(s);
} else {
// seems we got a manager we currently don't have
LOGGER.warn("Unable to find job manager '" + id + "'; using parent manager");
m_jobManagerSelect.setSelectedItem(DEFAULT_ENTRY);
}
// show the proper panel
jobManagerSelectionChanged();
}
Aggregations