use of org.knime.core.node.config.Config in project knime-core by knime.
the class ParameterizedDatabaseConnectionSettings method loadValidatedConnection.
// introduced with KNIME 3.2
// /**
// * {@inheritDoc}
// */
// @Override
// public void validateConnection(final ConfigRO settings, final CredentialsProvider cp)
// throws InvalidSettingsException {
// super.validateConnection(settings, cp);
// final Config config = settings.getConfig(CFG_KEY);
// config.getBoolean(CFG_USE_SSL);
// }
/**
* {@inheritDoc}
*/
@Override
public boolean loadValidatedConnection(final ConfigRO settings, final CredentialsProvider cp) throws InvalidSettingsException {
boolean b = super.loadValidatedConnection(settings, cp);
if (settings.containsKey(CFG_KEY)) {
final Config config = settings.getConfig(CFG_KEY);
m_parameter = config.getString(CFG_PARAMETER);
} else {
// parameter support added with KNIME 3.2
m_parameter = "";
}
return b;
}
use of org.knime.core.node.config.Config in project knime-core by knime.
the class ColumnAggregator method saveColumnAggregators.
/**
* @param settings the settings object to write to
* @param key the unique settings key or <code>null</code> if the default should be used
* @param aggregators the {@link ColumnAggregator} objects to save
* @since 2.11
*/
public static void saveColumnAggregators(final NodeSettingsWO settings, final String key, final List<ColumnAggregator> aggregators) {
if (settings == null) {
throw new NullPointerException("settings must not be null");
}
if (aggregators == null) {
throw new NullPointerException("aggregators must not be null");
}
final String[] colNames = new String[aggregators.size()];
final String[] aggrMethods = new String[aggregators.size()];
final boolean[] inclMissingVals = new boolean[aggregators.size()];
final DataType[] types = new DataType[aggregators.size()];
final Config cnfg;
if (key == null || key.isEmpty()) {
cnfg = settings.addConfig(CNFG_AGGR_COL_SECTION);
} else {
cnfg = settings.addConfig(key);
}
final NodeSettingsWO operatorSettings = settings.addNodeSettings(CNFG_OPERATOR_SETTINGS);
final Map<String, MutableInteger> idMap = new HashMap<>();
for (int i = 0, length = aggregators.size(); i < length; i++) {
final ColumnAggregator colAggr = aggregators.get(i);
colNames[i] = colAggr.getOriginalColName();
final AggregationMethod method = colAggr.getMethodTemplate();
aggrMethods[i] = colAggr.getId();
types[i] = colAggr.getOriginalDataType();
inclMissingVals[i] = colAggr.inclMissingCells();
if (colAggr.hasOptionalSettings()) {
try {
final NodeSettingsWO operatorSetting = operatorSettings.addNodeSettings(createSettingsKey(idMap, colAggr));
method.saveSettingsTo(operatorSetting);
} catch (Exception e) {
LOGGER.error("Exception while saving settings for aggreation operator '" + colAggr.getId() + "', reason: " + e.getMessage());
}
}
}
cnfg.addStringArray(CNFG_COL_NAMES, colNames);
cnfg.addDataTypeArray(CNFG_COL_TYPES, types);
cnfg.addStringArray(CNFG_AGGR_METHODS, aggrMethods);
cnfg.addBooleanArray(CNFG_INCL_MISSING_VALS, inclMissingVals);
}
use of org.knime.core.node.config.Config in project knime-core by knime.
the class BinDataModel method loadFromFile.
/**
* @param config the config object to use
* @param exec the {@link ExecutionMonitor} to provide progress messages
* @return the {@link ColorColumn}
* @throws CanceledExecutionException if the operation is canceled
* @throws InvalidSettingsException if the config object is invalid
*/
public static BinDataModel loadFromFile(final ConfigRO config, final ExecutionMonitor exec) throws CanceledExecutionException, InvalidSettingsException {
final String caption = config.getString(CFG_X_CAPTION);
final Double lowerBound;
final Double upperBound;
if (config.getBoolean(CFG_HAS_BOUNDARIES)) {
lowerBound = new Double(config.getDouble(CFG_LOWER_BOUND));
upperBound = new Double(config.getDouble(CFG_UPPER_BOUND));
} else {
lowerBound = null;
upperBound = null;
}
final ConfigRO barsConf = config.getConfig(CFG_BARS);
final int barCounter = barsConf.getInt(CFG_BAR_COUNTER);
final Map<Color, BarDataModel> bars = new HashMap<Color, BarDataModel>(barCounter);
for (int i = 0; i < barCounter; i++) {
final Config binConf = barsConf.getConfig(CFG_BAR + i);
final BarDataModel bar = BarDataModel.loadFromFile(binConf, exec);
bars.put(bar.getColor(), bar);
}
exec.checkCanceled();
return new BinDataModel(caption, lowerBound, upperBound, bars);
}
use of org.knime.core.node.config.Config in project knime-core by knime.
the class FixedHistogramDataModel method loadFromFile.
/**
* @param directory the directory to write to
* @param exec the {@link ExecutionMonitor} to provide progress messages; must not be <code>null</code>
* @return the histogram data model
* @throws InvalidSettingsException if the x column specification
* wasn't valid
* @throws IOException if a file exception occurs
* @throws CanceledExecutionException if the operation is canceled
*/
public static FixedHistogramDataModel loadFromFile(final File directory, final ExecutionMonitor exec) throws InvalidSettingsException, IOException, CanceledExecutionException {
exec.setProgress(0.0, "Start reading data from file");
final ConfigRO config;
final FileInputStream is;
final GZIPInputStream inData;
try {
final File settingsFile = new File(directory, CFG_DATA_FILE);
is = new FileInputStream(settingsFile);
inData = new GZIPInputStream(is);
config = NodeSettings.loadFromXML(inData);
} catch (final FileNotFoundException e) {
throw e;
} catch (final IOException e) {
LOGGER.error("Unable to load histogram data: " + e.getMessage());
throw new IOException("Please reexecute the histogram node. " + "(For details see log file)");
}
final Config xConfig = config.getConfig(CFG_X_COL_SPEC);
final DataColumnSpec xColSpec = DataColumnSpec.load(xConfig);
final boolean binNominal = config.getBoolean(CFG_NOMINAL);
AggregationMethod aggrMethod = AggregationMethod.getDefaultMethod();
try {
aggrMethod = AggregationMethod.getMethod4Command(config.getString(CFG_AGGR_METHOD));
} catch (final Exception e) {
// Take the default method
}
exec.setProgress(0.1, "Binning column specification loaded");
exec.setProgress("Loading aggregation columns...");
final Config aggrConf = config.getConfig(CFG_AGGR_COLS);
final int aggrColCounter = aggrConf.getInt(CFG_AGGR_COL_COUNTER);
final ArrayList<ColorColumn> aggrCols = new ArrayList<ColorColumn>(aggrColCounter);
for (int i = 0; i < aggrColCounter; i++) {
final Config aggrColConf = aggrConf.getConfig(CFG_COLOR_COL + i);
aggrCols.add(ColorColumn.loadFromFile(aggrColConf, exec));
}
exec.setProgress(0.3, "Loading bins...");
final ConfigRO binsConf = config.getConfig(CFG_BINS);
final int binCounter = binsConf.getInt(CFG_BIN_COUNTER);
final List<BinDataModel> bins = new ArrayList<BinDataModel>(binCounter);
for (int i = 0; i < binCounter; i++) {
final Config binConf = binsConf.getConfig(CFG_BIN + i);
bins.add(BinDataModel.loadFromFile(binConf, exec));
}
final Config missingConfig = binsConf.getConfig(CFG_MISSING_BIN);
final BinDataModel missingBin = BinDataModel.loadFromFile(missingConfig, exec);
BinDataModel invalidBin = null;
if (binsConf.containsKey(CFG_INVALID_BIN)) {
final Config invalidConfig = binsConf.getConfig(CFG_INVALID_BIN);
invalidBin = BinDataModel.loadFromFile(invalidConfig, exec);
}
exec.setProgress(0.9, "Loading element colors...");
final ConfigRO colorColsConf = config.getConfig(CFG_COLOR_COLS);
final int counter = colorColsConf.getInt(CFG_ROW_COLOR_COUNTER);
final SortedSet<Color> rowColors = new TreeSet<Color>(HSBColorComparator.getInstance());
for (int i = 0; i < counter; i++) {
rowColors.add(new Color(colorColsConf.getInt(CFG_ROW_COLOR + i)));
}
exec.setProgress(1.0, "Histogram data model loaded ");
// close the stream
inData.close();
is.close();
return new FixedHistogramDataModel(xColSpec, aggrMethod, aggrCols, binNominal, bins, missingBin, invalidBin, rowColors);
}
use of org.knime.core.node.config.Config in project knime-core by knime.
the class InteractiveHistogramDataModel method save2File.
/**
* @param dataDir the data directory to write to
* @param exec the {@link ExecutionMonitor}
* @throws IOException if the file can't be created
* @throws CanceledExecutionException if the process was canceled
*/
public void save2File(final File dataDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
final File settingFile = new File(dataDir, CFG_SETTING_FILE);
final FileOutputStream os = new FileOutputStream(settingFile);
final GZIPOutputStream dataOS = new GZIPOutputStream(os);
final Config config = new NodeSettings(CFG_SETTING);
final List<Color> rowColors = getRowColors();
final ConfigWO colorColsConf = config.addConfig(CFG_COLOR_COLS);
colorColsConf.addInt(CFG_ROW_COLOR_COUNTER, rowColors.size());
int idx = 0;
for (final Color color : rowColors) {
colorColsConf.addInt(CFG_ROW_COLOR + idx++, color.getRGB());
}
config.saveToXML(dataOS);
exec.checkCanceled();
final File dataFile = new File(dataDir, CFG_DATA_FILE);
DataContainer.writeToZip(m_data, dataFile, exec);
}
Aggregations