use of org.knime.core.node.config.Config in project knime-core by knime.
the class DefaultDatabaseConnectionSettings method validateConnection.
/**
* {@inheritDoc}
*/
@Override
public void validateConnection(final ConfigRO settings, final CredentialsProvider cp) throws InvalidSettingsException {
super.validateConnection(settings, cp);
Config conf = settings.getConfig("default-connection");
conf.getString("hostname");
conf.getInt("port");
conf.getString("databaseName");
}
use of org.knime.core.node.config.Config in project knime-core by knime.
the class DefaultDatabaseConnectionSettings method saveConnection.
/**
* {@inheritDoc}
*/
@Override
public void saveConnection(final ConfigWO settings) {
super.saveConnection(settings);
Config conf = settings.addConfig("default-connection");
conf.addString("hostname", m_host);
conf.addInt("port", m_port);
conf.addString("databaseName", m_databaseName);
}
use of org.knime.core.node.config.Config in project knime-core by knime.
the class ParameterizedDatabaseConnectionSettings method saveConnection.
/**
* {@inheritDoc}
*/
@Override
public void saveConnection(final ConfigWO settings) {
super.saveConnection(settings);
final Config config = settings.addConfig(CFG_KEY);
config.addString(CFG_PARAMETER, m_parameter);
}
use of org.knime.core.node.config.Config in project knime-core by knime.
the class ColumnAggregator method loadColumnAggregators.
/**
* Creates a {@link List} with all {@link ColumnAggregator}s that were
* stored in the settings.
*
* @param settings the settings object to read from
* @param key the unique settings key or <code>null</code> if the default should be used
* @param spec {@link DataTableSpec} of the input table if available
* @return {@link List} with the {@link ColumnAggregator}s
* @throws InvalidSettingsException if the settings are invalid
* @since 2.11
*/
public static List<ColumnAggregator> loadColumnAggregators(final NodeSettingsRO settings, final String key, final DataTableSpec spec) throws InvalidSettingsException {
final Config cnfg;
if (key == null || key.isEmpty()) {
cnfg = settings.getConfig(CNFG_AGGR_COL_SECTION);
} else {
cnfg = settings.getConfig(key);
}
final String[] colNames = cnfg.getStringArray(CNFG_COL_NAMES);
final DataType[] colTypes = cnfg.getDataTypeArray(CNFG_COL_TYPES);
final String[] aggrMethods = cnfg.getStringArray(CNFG_AGGR_METHODS);
boolean[] inclMissingVals = null;
try {
inclMissingVals = cnfg.getBooleanArray(CNFG_INCL_MISSING_VALS);
} catch (final InvalidSettingsException e) {
// be compatible to version 2.3 and earlier
}
final List<ColumnAggregator> colAggrList = new LinkedList<>();
if (aggrMethods.length != colNames.length) {
throw new InvalidSettingsException("Column name array and aggregation method array should be of equal size");
}
final NodeSettingsRO operatorSettings;
if (settings.containsKey(CNFG_OPERATOR_SETTINGS)) {
operatorSettings = settings.getNodeSettings(CNFG_OPERATOR_SETTINGS);
} else {
operatorSettings = settings;
}
final Map<String, MutableInteger> idMap = new HashMap<>();
for (int i = 0, length = aggrMethods.length; i < length; i++) {
final AggregationMethod method = AggregationMethods.getMethod4Id(aggrMethods[i]);
final boolean inclMissingVal;
if (inclMissingVals != null) {
inclMissingVal = inclMissingVals[i];
} else {
// get the default behavior of the method
inclMissingVal = method.inclMissingCells();
}
final DataColumnSpec resultSpec = new DataColumnSpecCreator(colNames[i], colTypes[i]).createSpec();
final ColumnAggregator aggrCol = new ColumnAggregator(resultSpec, method, inclMissingVal);
if (aggrCol.hasOptionalSettings()) {
try {
// TK_TODO: We should use a settings key but a running number to allow the user to change the columns
// to aggregate via flow variables. However we cannot do this now because of backward compatibility
NodeSettingsRO operatorSetting = operatorSettings.getNodeSettings(createSettingsKey(idMap, aggrCol));
if (spec != null) {
// this method is called from the dialog
aggrCol.loadSettingsFrom(operatorSetting, spec);
} else {
// this method is called from the node model where we do not
// have the DataTableSpec
aggrCol.loadValidatedSettings(operatorSetting);
}
} catch (Exception e) {
LOGGER.error("Exception while loading settings for aggreation operator '" + aggrCol.getId() + "', reason: " + e.getMessage());
}
}
colAggrList.add(aggrCol);
}
return colAggrList;
}
use of org.knime.core.node.config.Config in project knime-core by knime.
the class DefaultDatabaseConnectionSettings method loadValidatedConnection.
/**
* {@inheritDoc}
*/
@Override
public boolean loadValidatedConnection(final ConfigRO settings, final CredentialsProvider cp) throws InvalidSettingsException {
boolean b = super.loadValidatedConnection(settings, cp);
Config conf = settings.getConfig("default-connection");
m_host = conf.getString("hostname");
m_port = conf.getInt("port");
m_databaseName = conf.getString("databaseName");
return b;
}
Aggregations