use of org.knime.core.node.InvalidSettingsException in project knime-core by knime.
the class DateTimeToStringNodeModel method createStreamableOperator.
/**
* {@inheritDoc}
*/
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
return new StreamableOperator() {
@Override
public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
final RowInput in = (RowInput) inputs[0];
final RowOutput out = (RowOutput) outputs[0];
final DataTableSpec inSpec = in.getDataTableSpec();
final String[] includeList = m_colSelect.applyTo(inSpec).getIncludes();
final int[] includeIndeces = Arrays.stream(m_colSelect.applyTo(inSpec).getIncludes()).mapToInt(s -> inSpec.findColumnIndex(s)).toArray();
final boolean isReplace = m_isReplaceOrAppend.getStringValue().equals(OPTION_REPLACE);
DataRow row;
while ((row = in.poll()) != null) {
exec.checkCanceled();
DataCell[] datacells = new DataCell[includeIndeces.length];
for (int i = 0; i < includeIndeces.length; i++) {
if (isReplace) {
final DataColumnSpecCreator dataColumnSpecCreator = new DataColumnSpecCreator(includeList[i], StringCell.TYPE);
final TimeToStringCellFactory cellFac = new TimeToStringCellFactory(dataColumnSpecCreator.createSpec(), includeIndeces[i]);
datacells[i] = cellFac.getCell(row);
} else {
final DataColumnSpec dataColSpec = new UniqueNameGenerator(inSpec).newColumn(includeList[i] + m_suffix.getStringValue(), StringCell.TYPE);
final TimeToStringCellFactory cellFac = new TimeToStringCellFactory(dataColSpec, includeIndeces[i]);
datacells[i] = cellFac.getCell(row);
}
}
if (isReplace) {
out.push(new ReplacedColumnsDataRow(row, datacells, includeIndeces));
} else {
out.push(new AppendedColumnRow(row, datacells));
}
}
in.close();
out.close();
}
};
}
use of org.knime.core.node.InvalidSettingsException in project knime-core by knime.
the class JavaSnippetTemplate method loadSettings.
/**
* Loads parameters.
* @param settings to load from
*/
@Override
public void loadSettings(final NodeSettingsRO settings) {
try {
String metaCategory = settings.getString(META_CATEGORY, null);
m_metaCategory = getMetaCategoryClass(metaCategory);
m_category = settings.getString(CATEGORY, "default");
m_name = settings.getString(NAME, "?");
m_description = settings.getString(DESCRIPTION, "");
m_version = settings.getString(m_version, JavaSnippetTemplate.VERSION_1_X);
NodeSettingsRO snippet = settings.getNodeSettings(SNIPPET);
m_snippetSettings = new JavaSnippetSettings();
m_snippetSettings.loadSettingsForDialog(snippet);
m_uuid = m_snippetSettings.getTemplateUUID();
} catch (ClassNotFoundException e) {
throw new IllegalStateException(e);
} catch (InvalidSettingsException e) {
throw new IllegalStateException(e);
}
}
use of org.knime.core.node.InvalidSettingsException in project knime-core by knime.
the class StringManipulationNodeDialog method saveSettingsTo.
/**
* {@inheritDoc}
*/
@Override
protected void saveSettingsTo(final NodeSettingsWO settings) throws InvalidSettingsException {
StringManipulationSettings s = new StringManipulationSettings();
String newColName = null;
boolean isReplace = m_replaceRadio.isSelected();
if (isReplace) {
if (m_isOnlyVariables) {
newColName = ((FlowVariable) m_replaceVariableCombo.getModel().getSelectedItem()).getName();
} else {
newColName = m_replaceColumnCombo.getSelectedColumn();
}
} else {
newColName = m_newNameField.getText();
}
s.setReplace(isReplace);
s.setColName(newColName);
String exp = m_snippetPanel.getExpression();
s.setExpression(exp);
boolean isTestCompilation = m_compileOnCloseChecker.isSelected();
s.setTestCompilationOnDialogClose(isTestCompilation);
if (isTestCompilation && m_currentSpec != null) {
try {
Expression.compile(s.createJavaScriptingSettings(), m_currentSpec);
} catch (CompilationFailedException cfe) {
throw new InvalidSettingsException(cfe.getMessage(), cfe);
}
}
s.setInsertMissingAsNull(m_insertMissingAsNullChecker.isSelected());
s.saveSettingsTo(settings);
}
use of org.knime.core.node.InvalidSettingsException in project knime-core by knime.
the class StringManipulationSettings method determineReturnType.
private Class<?> determineReturnType(final String expression) throws InvalidSettingsException {
if (expression.isEmpty()) {
throw new InvalidSettingsException("Empty expressions are not supported.");
}
int endIndex = StringUtils.indexOf(expression, '(');
if (endIndex < 0) {
throw new InvalidSettingsException(getAmbigiousReturnTypeMessage());
}
String function = expression.substring(0, endIndex);
StringManipulatorProvider provider = StringManipulatorProvider.getDefault();
// Add StringManipulators to the imports
Collection<Manipulator> manipulators = provider.getManipulators(ManipulatorProvider.ALL_CATEGORY);
Class<?> returnType = null;
for (Manipulator manipulator : manipulators) {
if (function.equals(manipulator.getName())) {
returnType = manipulator.getReturnType();
}
}
if (null == returnType) {
throw new InvalidSettingsException(getAmbigiousReturnTypeMessage());
}
return returnType;
}
use of org.knime.core.node.InvalidSettingsException in project knime-core by knime.
the class ModifyTimeNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
if (!m_hasValidatedConfiguration) {
throw new InvalidSettingsException("Node must be configured!");
}
DataTableSpec in = inSpecs[0];
ColumnRearranger r = createColumnRearranger(in);
DataTableSpec out = r.createSpec();
return new DataTableSpec[] { out };
}
Aggregations