use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.
the class FileNativeNodeContainerPersistor method guessPortTypesFromConnectedNodes.
/**
* {@inheritDoc}
*/
@Override
public void guessPortTypesFromConnectedNodes(final NodeAndBundleInformationPersistor nodeInfo, final NodeSettingsRO additionalFactorySettings, final ArrayList<PersistorWithPortIndex> upstreamNodes, final ArrayList<List<PersistorWithPortIndex>> downstreamNodes) {
if (m_node == null) {
/* Input ports from the connection table. */
// first is flow var port
PortType[] inPortTypes = new PortType[Math.max(upstreamNodes.size() - 1, 0)];
// default to BDT for unconnected ports
Arrays.fill(inPortTypes, BufferedDataTable.TYPE);
for (int i = 0; i < inPortTypes.length; i++) {
// first is flow var port
PersistorWithPortIndex p = upstreamNodes.get(i + 1);
if (p != null) {
PortType portTypeFromUpstreamNode = p.getPersistor().getUpstreamPortType(p.getPortIndex());
if (portTypeFromUpstreamNode != null) {
// null if upstream is missing, too
inPortTypes[i] = portTypeFromUpstreamNode;
}
}
}
/* Output ports from node settings (saved ports) -- if possible (executed) */
String nodeName = nodeInfo.getNodeNameNotNull();
PortType[] outPortTypes;
try {
LoadResult guessLoadResult = new LoadResult("Port type guessing for missing node \"" + nodeName + "\"");
NodeSettingsRO settingsForNode = loadSettingsForNode(guessLoadResult);
FileNodePersistor nodePersistor = createNodePersistor(settingsForNode);
outPortTypes = nodePersistor.guessOutputPortTypes(guessLoadResult, nodeName);
if (guessLoadResult.hasErrors()) {
getLogger().debug("Errors guessing port types for missing node \"" + nodeName + "\": " + guessLoadResult.getFilteredError("", LoadResultEntryType.Error));
}
} catch (Exception e) {
getLogger().debug("Unable to guess port types for missing node \"" + nodeName + "\"", e);
outPortTypes = null;
}
if (outPortTypes == null) {
// couldn't guess port types from looking at node settings (e.g. not executed)
// default to BDT for unconnected ports
outPortTypes = new PortType[Math.max(downstreamNodes.size() - 1, 0)];
}
for (int i = 0; i < outPortTypes.length; i++) {
PortType type = outPortTypes[i];
// output types may be partially filled by settings guessing above, list may be empty or too short
List<PersistorWithPortIndex> list = i < downstreamNodes.size() - 1 ? downstreamNodes.get(i + 1) : null;
if (list != null) {
assert !list.isEmpty();
for (PersistorWithPortIndex p : list) {
PortType current = p.getPersistor().getDownstreamPortType(p.getPortIndex());
if (current == null) {
// ignore, downstream node is also missing
} else if (type == null) {
type = current;
} else if (type.equals(current)) {
// keep type
} else {
// this shouldn't really happen - someone changed port types between versions
type = PortObject.TYPE;
}
}
outPortTypes[i] = type;
}
if (outPortTypes[i] == null) {
// might still be null if missing node is only connected to missing node, fallback: BDT
outPortTypes[i] = BufferedDataTable.TYPE;
}
}
MissingNodeFactory nodefactory = new MissingNodeFactory(nodeInfo, additionalFactorySettings, inPortTypes, outPortTypes);
if (getLoadVersion().ordinal() < FileWorkflowPersistor.VERSION_LATEST.ordinal()) {
nodefactory.setCopyInternDirForWorkflowVersionChange(true);
}
nodefactory.init();
m_node = new Node((NodeFactory) nodefactory);
}
}
use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.
the class FileNativeNodeContainerPersistor method loadSettingsForNode.
/**
* {@inheritDoc}
*/
@Override
NodeSettingsRO loadSettingsForNode(final LoadResult loadResult) throws IOException {
NodeSettingsRO nodeSettings = getNodeSettings();
if (getLoadVersion().ordinal() < LoadVersion.V280.ordinal()) {
FileNodeContainerMetaPersistor metaPersistor = getMetaPersistor();
ReferencedFile nodeFile;
try {
nodeFile = loadNodeFile(nodeSettings);
} catch (InvalidSettingsException e) {
String error = "Unable to load node settings file for node with ID suffix " + metaPersistor.getNodeIDSuffix() + " (node \"" + m_node.getName() + "\"): " + e.getMessage();
loadResult.addError(error);
getLogger().debug(error, e);
setDirtyAfterLoad();
return new NodeSettings("empty");
}
File configFile = nodeFile.getFile();
if (configFile == null || !configFile.isFile() || !configFile.canRead()) {
String error = "Unable to read node settings file for node with ID suffix " + metaPersistor.getNodeIDSuffix() + " (node \"" + m_node.getName() + "\"), file \"" + configFile + "\"";
loadResult.addError(error);
// also implies dirty
setNeedsResetAfterLoad();
return new NodeSettings("empty");
} else {
InputStream in = new FileInputStream(configFile);
try {
in = getParentPersistor().decipherInput(in);
return NodeSettings.loadFromXML(new BufferedInputStream(in));
} finally {
try {
in.close();
} catch (IOException e) {
getLogger().error("Failed to close input stream on \"" + configFile.getAbsolutePath() + "\"", e);
}
}
}
} else {
return nodeSettings;
}
}
use of org.knime.core.node.NodeSettingsRO 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.NodeSettingsRO in project knime-core by knime.
the class AnnotationData method load.
/**
* loads new values.
* @param config To load from
* @param loadVersion Version to load
* @throws InvalidSettingsException If fails
* @since 3.7
*/
public void load(final NodeSettingsRO config, final LoadVersion loadVersion) throws InvalidSettingsException {
setText(config.getString("text"));
setBgColor(config.getInt("bgcolor"));
int x = config.getInt("x-coordinate");
int y = config.getInt("y-coordinate");
int width = config.getInt("width");
int height = config.getInt("height");
// default to 0 for backward compatibility
int borderSize = config.getInt("borderSize", 0);
// default for backward compatibility
int borderColor = config.getInt("borderColor", 0);
// default for backward compatibility
int defFontSize = config.getInt("defFontSize", -1);
// added in 3.0
m_version = config.getInt("annotation-version", VERSION_OLD);
TextAlignment alignment = TextAlignment.LEFT;
if (loadVersion.ordinal() >= LoadVersion.V250.ordinal()) {
String alignmentS = config.getString("alignment");
try {
alignment = TextAlignment.valueOf(alignmentS);
} catch (Exception e) {
throw new InvalidSettingsException("Invalid alignment: " + alignmentS, e);
}
}
setDimension(x, y, width, height);
setAlignment(alignment);
setBorderSize(borderSize);
setBorderColor(borderColor);
setDefaultFontSize(defFontSize);
NodeSettingsRO styleConfigs = config.getNodeSettings("styles");
StyleRange[] styles = new StyleRange[styleConfigs.getChildCount()];
int i = 0;
for (String key : styleConfigs.keySet()) {
NodeSettingsRO cur = styleConfigs.getNodeSettings(key);
styles[i++] = StyleRange.load(cur);
}
setStyleRanges(styles);
}
use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.
the class PMMLPortObjectSpec method loadFrom.
/**
* @param in stream reading the relevant files
* @return a completely loaded port object spec with {@link DataTableSpec},
* and the sets of learning, ignored and target columns.
* @throws IOException if something goes wrong
* @throws InvalidSettingsException if something goes wrong
*/
public static PMMLPortObjectSpec loadFrom(final PortObjectSpecZipInputStream in) throws IOException, InvalidSettingsException {
NonClosableInputStream noCloseIn = new NonClosableInputStream(in);
// the data table spec
in.getNextEntry();
// TODO: sanitycheck if name is the same
NodeSettingsRO settings = NodeSettings.loadFromXML(noCloseIn);
DataTableSpec dataTableSpec = DataTableSpec.load(settings);
// the mining schema
in.getNextEntry();
// TODO: sanity check if names are consistent
NodeSettingsRO miningSchemaSettings = NodeSettings.loadFromXML(noCloseIn);
List<String> learningCols = new LinkedList<String>();
for (String colName : miningSchemaSettings.getStringArray(LEARNING_KEY)) {
DataColumnSpec colSpec = dataTableSpec.getColumnSpec(colName);
if (colSpec == null) {
throw new InvalidSettingsException("Column " + colName + " is not in DataTableSpec");
}
learningCols.add(colName);
}
List<String> targetCols = new LinkedList<String>();
for (String colName : miningSchemaSettings.getStringArray(TARGET_KEY)) {
DataColumnSpec colSpec = dataTableSpec.getColumnSpec(colName);
if (colSpec == null) {
throw new InvalidSettingsException("Column " + colName + " is not in DataTableSpec");
}
targetCols.add(colName);
}
// the preprocessing settings if existent
ZipEntry preprocEntry = in.getNextEntry();
List<String> activeCols = null;
if (preprocEntry != null) {
NodeSettingsRO preprocSettings = NodeSettings.loadFromXML(noCloseIn);
activeCols = new LinkedList<String>();
for (String colName : preprocSettings.getStringArray(PREPROC_COL_KEY)) {
DataColumnSpec colSpec = dataTableSpec.getColumnSpec(colName);
if (colSpec == null) {
throw new InvalidSettingsException("Column " + colName + " is not in DataTableSpec");
}
activeCols.add(colName);
}
}
return new PMMLPortObjectSpec(dataTableSpec, activeCols, learningCols, targetCols);
}
Aggregations