Search in sources :

Example 1 with SettingsModelFilterString

use of org.knime.core.node.defaultnodesettings.SettingsModelFilterString in project knime-core by knime.

the class CAIMDiscretizationNodeModel method validateSettings.

/**
 * This method validates the settings. That is:
 * <ul>
 * <li>The number of the class column must be an integer > 0</li>
 * <li>The positive value <code>DataCell</code> must not be null</li>
 * </ul>
 *
 * {@inheritDoc}
 */
@Override
protected void validateSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
    SettingsModelString tmp = m_classColumnName.createCloneWithValidatedValue(settings);
    String classifyColumn = tmp.getStringValue();
    if (classifyColumn == null || classifyColumn.equals("")) {
        throw new InvalidSettingsException("Discretization column not set");
    }
    SettingsModelFilterString tmpIncl = null;
    try {
        tmpIncl = m_includedColumnNames.createCloneWithValidatedValue(settings);
    } catch (InvalidSettingsException ise) {
    // new with 2.0
    }
    if (tmpIncl == null || tmpIncl.getIncludeList() == null || tmpIncl.getIncludeList().size() == 0) {
        setWarningMessage(WARNING_NO_COLS_SELECTED);
    }
    m_sortInMemory.validateSettings(settings);
}
Also used : SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 2 with SettingsModelFilterString

use of org.knime.core.node.defaultnodesettings.SettingsModelFilterString in project knime-core by knime.

the class GroupByNodeModel method validateSettings.

/**
 * {@inheritDoc}
 */
@Override
protected void validateSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
    m_groupByCols.validateSettings(settings);
    // FIX bug 5040: potential problem with clone settings method when in-/exclude list contain same elements
    final SettingsModelFilterString tmpSett = new SettingsModelFilterString(CFG_GROUP_BY_COLUMNS);
    tmpSett.loadSettingsFrom(settings);
    final List<String> groupByCols = tmpSett.getIncludeList();
    m_maxUniqueValues.validateSettings(settings);
    m_enableHilite.validateSettings(settings);
    // with Knime 2.0 as well as the naming policy
    try {
        final List<ColumnAggregator> aggregators = ColumnAggregator.loadColumnAggregators(settings);
        final List<DataTypeAggregator> typeAggregators = new LinkedList<>();
        final List<PatternAggregator> patternAggregators = new LinkedList<>();
        try {
            patternAggregators.addAll(PatternAggregator.loadAggregators(settings, CFG_PATTERN_AGGREGATORS));
            typeAggregators.addAll(DataTypeAggregator.loadAggregators(settings, CFG_DATA_TYPE_AGGREGATORS));
        } catch (InvalidSettingsException e) {
        // introduced in 2.11
        }
        if (groupByCols.isEmpty() && aggregators.isEmpty() && patternAggregators.isEmpty() && typeAggregators.isEmpty()) {
            throw new IllegalArgumentException("Please select at least one group column or aggregation option");
        }
        ColumnNamePolicy namePolicy;
        try {
            final String policyLabel = ((SettingsModelString) m_columnNamePolicy.createCloneWithValidatedValue(settings)).getStringValue();
            namePolicy = ColumnNamePolicy.getPolicy4Label(policyLabel);
        } catch (final InvalidSettingsException e) {
            namePolicy = compGetColumnNamePolicy(settings);
        }
        checkDuplicateAggregators(namePolicy, aggregators);
    } catch (final InvalidSettingsException e) {
    // these settings are prior Knime 2.0 and can't contain
    // a column several times
    } catch (final IllegalArgumentException e) {
        throw new InvalidSettingsException(e.getMessage());
    }
}
Also used : PatternAggregator(org.knime.base.data.aggregation.dialogutil.pattern.PatternAggregator) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) DataTypeAggregator(org.knime.base.data.aggregation.dialogutil.type.DataTypeAggregator) LinkedList(java.util.LinkedList) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) ColumnAggregator(org.knime.base.data.aggregation.ColumnAggregator) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Example 3 with SettingsModelFilterString

use of org.knime.core.node.defaultnodesettings.SettingsModelFilterString in project knime-core by knime.

the class Pivot2NodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected DataTableSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    // we have to explicitly set all not pivot columns in the exclude list of the SettingsModelFilterString. The
    // DialogComponentColumnFilter component always uses the exclude/ list to update the component if we don't set
    // the exclude list all columns are added as group by columns.
    final DataTableSpec origSpec = (DataTableSpec) inSpecs[0];
    final Collection<String> exclList = getExcludeList(origSpec, m_pivotCols.getIncludeList());
    m_pivotCols.setExcludeList(exclList);
    final List<String> pivotCols = m_pivotCols.getIncludeList();
    if (pivotCols.isEmpty()) {
        throw new InvalidSettingsException("No pivot columns selected.");
    }
    // call super configure do have everything applied as in the super class
    super.configure(inSpecs);
    final List<String> groupCols = getGroupByColumns();
    for (final String piv : pivotCols) {
        if (groupCols.contains(piv)) {
            throw new InvalidSettingsException("Ambigious group/pivot column selection.");
        }
    }
    final List<String> groupAndPivotCols = createAllColumns();
    final DataTableSpec groupSpec = createGroupBySpec(origSpec, groupAndPivotCols);
    if (groupSpec.getNumColumns() == groupAndPivotCols.size()) {
        throw new InvalidSettingsException("No aggregation columns selected.");
    }
    final DataTableSpec groupRowsSpec = createGroupBySpec(origSpec, groupCols);
    if (m_ignoreMissValues.getBooleanValue()) {
        final Set<String>[] combPivots = createCombinedPivots(groupSpec, pivotCols);
        for (final Set<String> combPivot : combPivots) {
            if (combPivot == null) {
                return new DataTableSpec[] { null, groupRowsSpec, null };
            }
        }
        final DataTableSpec outSpec = createOutSpec(groupSpec, combPivots, /* ignored */
        new HashMap<String, Integer>(), null);
        if (m_totalAggregation.getBooleanValue()) {
            @SuppressWarnings("unchecked") final DataTableSpec totalGroupSpec = createGroupBySpec(origSpec, Collections.EMPTY_LIST);
            final DataColumnSpec[] pivotRowsSpec = new DataColumnSpec[outSpec.getNumColumns() + totalGroupSpec.getNumColumns()];
            for (int i = 0; i < outSpec.getNumColumns(); i++) {
                pivotRowsSpec[i] = outSpec.getColumnSpec(i);
            }
            final int totalOffset = outSpec.getNumColumns();
            for (int i = 0; i < totalGroupSpec.getNumColumns(); i++) {
                pivotRowsSpec[i + totalOffset] = totalGroupSpec.getColumnSpec(i);
            }
            return new DataTableSpec[] { outSpec, groupRowsSpec, new DataTableSpec(pivotRowsSpec) };
        } else {
            return new DataTableSpec[] { outSpec, groupRowsSpec, outSpec };
        }
    } else {
        return new DataTableSpec[] { null, groupRowsSpec, null };
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) DataColumnSpec(org.knime.core.data.DataColumnSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Example 4 with SettingsModelFilterString

use of org.knime.core.node.defaultnodesettings.SettingsModelFilterString in project knime-core by knime.

the class DBColumnFilterNodeModel method validateSettings.

/**
 * {@inheritDoc}
 */
@Override
protected void validateSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
    super.validateSettings(settings);
    // FIX bug 5040: potential problem with clone settings method when in-/exclude list contain same elements
    SettingsModelFilterString filter = DBColumnFilterNodeDialogPane.createColumnFilterModel();
    filter.loadSettingsFrom(settings);
    if (filter.getIncludeList().isEmpty() && !filter.getExcludeList().isEmpty()) {
        throw new InvalidSettingsException("No columns included in output table.");
    }
}
Also used : SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Example 5 with SettingsModelFilterString

use of org.knime.core.node.defaultnodesettings.SettingsModelFilterString in project knime-core by knime.

the class BitVectorGeneratorNodeModel method validateSettings.

/**
 * {@inheritDoc}
 */
@Override
protected void validateSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
    settings.getDouble(CFG_THRESHOLD);
    settings.getBoolean(CFG_USE_MEAN);
    settings.getInt(CFG_MEAN_THRESHOLD);
    boolean fromString = settings.getBoolean(CFG_FROM_STRING);
    SettingsModelString tmp = m_stringColumn.createCloneWithValidatedValue(settings);
    String stringCol = tmp.getStringValue();
    if (fromString && stringCol == null) {
        throw new InvalidSettingsException("A String column must be specified!");
    }
    settings.getString(CFG_STRING_TYPE);
    settings.getBoolean(CFG_REPLACE, false);
    // try to load them
    SettingsModelFilterString clone = null;
    try {
        clone = m_includedColumns.createCloneWithValidatedValue(settings);
    } catch (InvalidSettingsException ise) {
    // added with 2.0 -> no validation for backward compatibility
    }
    if (clone != null) {
        if (clone.isEnabled() && clone.getIncludeList().isEmpty()) {
            throw new InvalidSettingsException("No numeric input columns selected.");
        }
    }
}
Also used : SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Aggregations

InvalidSettingsException (org.knime.core.node.InvalidSettingsException)7 SettingsModelFilterString (org.knime.core.node.defaultnodesettings.SettingsModelFilterString)7 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)4 DataColumnSpec (org.knime.core.data.DataColumnSpec)2 DataTableSpec (org.knime.core.data.DataTableSpec)2 LinkedHashSet (java.util.LinkedHashSet)1 LinkedList (java.util.LinkedList)1 Set (java.util.Set)1 ColumnAggregator (org.knime.base.data.aggregation.ColumnAggregator)1 PatternAggregator (org.knime.base.data.aggregation.dialogutil.pattern.PatternAggregator)1 DataTypeAggregator (org.knime.base.data.aggregation.dialogutil.type.DataTypeAggregator)1