use of org.knime.core.node.InvalidSettingsException in project knime-core by knime.
the class DurationPeriodToStringNodeModel method createColumnRearranger.
/**
* {@inheritDoc}
*/
@Override
protected ColumnRearranger createColumnRearranger(final DataTableSpec spec) throws InvalidSettingsException {
if (!m_hasValidatedConfiguration) {
m_colSelect.loadDefaults(spec);
}
final ColumnRearranger rearranger = new ColumnRearranger(spec);
final String[] includeList = m_colSelect.applyTo(spec).getIncludes();
final int[] includeIndices = Arrays.stream(m_colSelect.applyTo(spec).getIncludes()).mapToInt(s -> spec.findColumnIndex(s)).toArray();
int i = 0;
for (String includedCol : includeList) {
if (m_isReplaceOrAppend.getStringValue().equals(OPTION_REPLACE)) {
DataColumnSpecCreator dataColumnSpecCreator = new DataColumnSpecCreator(includedCol, StringCell.TYPE);
DurationPeriodToStringCellFactory cellFac = new DurationPeriodToStringCellFactory(dataColumnSpecCreator.createSpec(), includeIndices[i++]);
rearranger.replace(cellFac, includedCol);
} else {
DataColumnSpec dataColSpec = new UniqueNameGenerator(spec).newColumn(includedCol + m_suffix.getStringValue(), StringCell.TYPE);
DurationPeriodToStringCellFactory cellFac = new DurationPeriodToStringCellFactory(dataColSpec, includeIndices[i++]);
rearranger.append(cellFac);
}
}
return rearranger;
}
use of org.knime.core.node.InvalidSettingsException in project knime-core by knime.
the class DurationToNumberNodeModel method createColumnRearranger.
/**
* {@inheritDoc}
*/
@Override
protected ColumnRearranger createColumnRearranger(final DataTableSpec spec) throws InvalidSettingsException {
final ColumnRearranger rearranger = new ColumnRearranger(spec);
if (m_colSelectModel.getStringValue() == null) {
throw new InvalidSettingsException("Node must be configured!");
}
if (spec.findColumnIndex(m_colSelectModel.getStringValue()) < 0) {
throw new InvalidSettingsException("Column '" + m_colSelectModel.getStringValue() + "' not found in the input table.");
}
final boolean exact = m_typeSelectModel.getStringValue().equals(DataTypeMode.Exact.name());
final DataColumnSpec colSpec = new UniqueNameGenerator(spec).newColumn((m_durationFieldSelectModel.getStringValue()), exact ? DoubleCell.TYPE : LongCell.TYPE);
final CellFactory cellFac = new ExtractDurationSingleFieldCellFactory(spec.findColumnIndex(m_colSelectModel.getStringValue()), exact, colSpec);
rearranger.append(cellFac);
return rearranger;
}
use of org.knime.core.node.InvalidSettingsException in project knime-core by knime.
the class TimestampToDateTimeNodeModel method createColumnRearranger.
/**
* @param inSpec table input spec
* @return the CR describing the output
*/
@Override
protected ColumnRearranger createColumnRearranger(final DataTableSpec inSpec) throws InvalidSettingsException {
CheckUtils.checkSetting(m_hasValidatedConfiguration, "Node must be configured!");
final ColumnRearranger rearranger = new ColumnRearranger(inSpec);
final String[] includeList = m_colSelect.applyTo(inSpec).getIncludes();
final int[] includeIndeces = Arrays.stream(m_colSelect.applyTo(inSpec).getIncludes()).mapToInt(s -> inSpec.findColumnIndex(s)).toArray();
int i = 0;
final boolean isReplace = m_isReplaceOrAppend.getStringValue().equals(OPTION_REPLACE);
UniqueNameGenerator uniqueNameGenerator = new UniqueNameGenerator(inSpec);
for (String includedCol : includeList) {
if (isReplace) {
final DataColumnSpecCreator dataColumnSpecCreator = new DataColumnSpecCreator(includedCol, DateTimeType.valueOf(m_selectedType).getDataType());
final TimestampToTimeCellFactory cellFac = new TimestampToTimeCellFactory(dataColumnSpecCreator.createSpec(), includeIndeces[i++]);
rearranger.replace(cellFac, includedCol);
} else {
final DataColumnSpec dataColSpec = uniqueNameGenerator.newColumn(includedCol + m_suffix.getStringValue(), DateTimeType.valueOf(m_selectedType).getDataType());
final TimestampToTimeCellFactory cellFac = new TimestampToTimeCellFactory(dataColSpec, includeIndeces[i++]);
rearranger.append(cellFac);
}
}
return rearranger;
}
use of org.knime.core.node.InvalidSettingsException 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();
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 {
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;
}
}
Set<String> layoutSetKeys = Collections.emptySet();
m_layoutInfo = new HashMap<Integer, WizardNodeLayoutInfo>();
NodeSettingsRO layoutSettings = null;
try {
layoutSettings = nodeSettings.getNodeSettings("layoutInfos");
layoutSetKeys = layoutSettings.keySet();
for (String key : layoutSetKeys) {
NodeSettingsRO singleLayoutSetting = layoutSettings.getNodeSettings(key);
int nodeID = singleLayoutSetting.getInt("nodeID");
WizardNodeLayoutInfo layoutInfo = WizardNodeLayoutInfo.loadFromNodeSettings(singleLayoutSetting);
m_layoutInfo.put(nodeID, layoutInfo);
}
} catch (InvalidSettingsException e) {
String error = "Could not load Wrapped Metanode layout information: " + e.getMessage();
result.addError(error);
getLogger().error(error, e);
setDirtyAfterLoad();
}
// added in 3.1, load with default value
m_layoutJSONString = nodeSettings.getString("layoutJSON", "");
m_workflowPersistor.preLoadNodeContainer(parentPersistor, parentSettings, result);
}
use of org.knime.core.node.InvalidSettingsException 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
*/
public void load(final NodeSettingsRO config, final FileWorkflowPersistor.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() >= FileWorkflowPersistor.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);
}
Aggregations