Search in sources :

Example 36 with NodeSettingsRO

use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.

the class RowFilter2PortNodeModel method loadOrValidateSettingsFrom.

private void loadOrValidateSettingsFrom(final NodeSettingsRO settings, final boolean verifyOnly) throws InvalidSettingsException {
    IRowFilter tmpFilter = null;
    if (settings.containsKey(CFGFILTER)) {
        NodeSettingsRO filterCfg = settings.getNodeSettings(CFGFILTER);
        tmpFilter = RowFilterFactory.createRowFilter(filterCfg);
    } else {
        throw new InvalidSettingsException("Row Filter config contains no" + " row filter.");
    }
    if (verifyOnly) {
        return;
    }
    // take over settings
    m_rowFilter = tmpFilter;
    return;
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) IRowFilter(org.knime.base.node.preproc.filter.row.rowfilter.IRowFilter)

Example 37 with NodeSettingsRO

use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.

the class DBPatternAggregationFunctionRow method loadFunctions.

/**
 * Loads the functions and handles invalid aggregation functions graceful.
 * @param settings {@link NodeSettingsRO}
 * @param key the config key
 * @param dbIdentifier the {@link AggregationFunctionProvider}
 * @param tableSpec the input {@link DataTableSpec}
 * @return {@link List} of {@link DBPatternAggregationFunctionRow}s
 * @throws InvalidSettingsException if the settings are invalid
 */
public static List<DBPatternAggregationFunctionRow> loadFunctions(final NodeSettingsRO settings, final String key, final String dbIdentifier, final DataTableSpec tableSpec) throws InvalidSettingsException {
    if (key == null || key.isEmpty()) {
        throw new IllegalArgumentException("key must not be null");
    }
    if (dbIdentifier == null || dbIdentifier.isEmpty()) {
        throw new IllegalArgumentException("dbIdentifier must not be empty");
    }
    if (settings == null || !settings.containsKey(key)) {
        return Collections.EMPTY_LIST;
    }
    final DatabaseUtility utility = DatabaseUtility.getUtility(dbIdentifier);
    DBAggregationFunctionProvider functionProvider = new DBAggregationFunctionProvider(utility);
    final NodeSettingsRO root = settings.getNodeSettings(key);
    final Set<String> settingsKeys = root.keySet();
    final List<DBPatternAggregationFunctionRow> colAggrList = new ArrayList<>(settingsKeys.size());
    for (String settingsKey : settingsKeys) {
        final NodeSettingsRO cfg = root.getNodeSettings(settingsKey);
        final String inputPattern = cfg.getString(CNFG_INPUT_PATTERN);
        final boolean isRegex = cfg.getBoolean(CNFG_IS_REGEX);
        final DBAggregationFunction function = AbstractDBAggregationFunctionRow.loadFunction(tableSpec, functionProvider, cfg);
        final DBPatternAggregationFunctionRow aggrFunctionRow = new DBPatternAggregationFunctionRow(inputPattern, isRegex, function);
        colAggrList.add(aggrFunctionRow);
    }
    return colAggrList;
}
Also used : DatabaseUtility(org.knime.core.node.port.database.DatabaseUtility) DBAggregationFunctionProvider(org.knime.base.node.io.database.groupby.dialog.DBAggregationFunctionProvider) ArrayList(java.util.ArrayList) DBAggregationFunction(org.knime.core.node.port.database.aggregation.DBAggregationFunction) NodeSettingsRO(org.knime.core.node.NodeSettingsRO)

Example 38 with NodeSettingsRO

use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.

the class DBTableCreatorConfiguration method loadSettingsForRowElements.

/**
 * A helper method to load settings for all RowElements
 *
 * @param cfgKey key used to retrieve the RowElement list from the map
 * @param settings NodeSettingsRO instance to load from
 * @throws InvalidSettingsException
 */
private void loadSettingsForRowElements(final String cfgKey, final NodeSettingsRO settings) throws InvalidSettingsException {
    final NodeSettingsRO root = settings.getNodeSettings(cfgKey);
    List<RowElement> elements = m_tableMap.get(cfgKey);
    elements.clear();
    for (String settingsKey : root.keySet()) {
        final NodeSettingsRO cfg = root.getNodeSettings(settingsKey);
        final RowElement elem = createRowElement(cfgKey, cfg);
        if (elem != null) {
            elements.add(elem);
        }
    }
}
Also used : NodeSettingsRO(org.knime.core.node.NodeSettingsRO) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 39 with NodeSettingsRO

use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.

the class KeyElement method loadSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings) {
    try {
        final String name = settings.getString(CFG_KEY_NAME);
        // Load all columns
        final NodeSettingsRO cfg = settings.getNodeSettings(CFG_KEY_COLUMNS);
        final Set<DBColumn> dbColumns = new LinkedHashSet<>();
        for (String settingsKey : cfg.keySet()) {
            final String colName = cfg.getString(settingsKey);
            DBColumn col = new DBColumn(colName, "", false);
            dbColumns.add(col);
        }
        final boolean primaryKey = settings.getBoolean(CFG_KEY_PRIMARY);
        m_key = new DBKey(name, dbColumns, primaryKey);
    } catch (InvalidSettingsException ex) {
    // Do nothing if no settings are found
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) DBColumn(org.knime.core.node.port.database.tablecreator.DBColumn) DBKey(org.knime.core.node.port.database.tablecreator.DBKey)

Example 40 with NodeSettingsRO

use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.

the class DBWriterDialogPane method loadSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
    // get workflow credentials
    m_loginPane.loadSettingsFrom(settings, specs, getCredentialsProvider());
    // table name
    m_table.setText(settings.getString(DBWriterNodeModel.KEY_TABLE_NAME, ""));
    // append data flag
    m_append.setSelected(settings.getBoolean(DBWriterNodeModel.KEY_APPEND_DATA, true));
    m_insertNullForMissing.setSelected(settings.getBoolean(DBWriterNodeModel.KEY_INSERT_NULL_FOR_MISSING_COLS, false));
    m_insertNullForMissing.setEnabled(m_append.isSelected());
    // introduced in KNIME 3.3.1 default behavior was not failing e.g. false
    m_failOnError.setSelected(settings.getBoolean(DBWriterNodeModel.KEY_FAIL_ON_ERROR, false));
    // load SQL Types for each column
    try {
        NodeSettingsRO typeSett = settings.getNodeSettings(DBWriterNodeModel.CFG_SQL_TYPES);
        m_typePanel.loadSettingsFrom(typeSett, (DataTableSpec) specs[0]);
    } catch (InvalidSettingsException ise) {
        m_typePanel.loadSettingsFrom(null, (DataTableSpec) specs[0]);
    }
    // load batch size
    final int batchSize = settings.getInt(DBWriterNodeModel.KEY_BATCH_SIZE, DatabaseConnectionSettings.BATCH_WRITE_SIZE);
    m_batchSize.setText(Integer.toString(batchSize));
    if ((specs.length > 1) && (specs[1] instanceof DatabaseConnectionPortObjectSpec)) {
        m_loginPane.setVisible(false);
    } else {
        m_loginPane.setVisible(true);
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) DatabaseConnectionPortObjectSpec(org.knime.core.node.port.database.DatabaseConnectionPortObjectSpec)

Aggregations

NodeSettingsRO (org.knime.core.node.NodeSettingsRO)208 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)125 File (java.io.File)49 FileInputStream (java.io.FileInputStream)47 IOException (java.io.IOException)43 InputStream (java.io.InputStream)22 LinkedHashMap (java.util.LinkedHashMap)20 NodeSettings (org.knime.core.node.NodeSettings)20 BufferedInputStream (java.io.BufferedInputStream)19 ArrayList (java.util.ArrayList)16 GZIPInputStream (java.util.zip.GZIPInputStream)15 DataTableSpec (org.knime.core.data.DataTableSpec)14 Map (java.util.Map)11 ReferencedFile (org.knime.core.internal.ReferencedFile)11 BufferedDataTable (org.knime.core.node.BufferedDataTable)10 HashMap (java.util.HashMap)9 DataColumnSpec (org.knime.core.data.DataColumnSpec)9 RowKey (org.knime.core.data.RowKey)9 DataType (org.knime.core.data.DataType)8 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)8