Search in sources :

Example 86 with InvalidSettingsException

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

the class VariableFileReaderNodeSettings method createSettingsFrom.

/**
 * Creates a clone from this object replacing the dataURL location by the
 * value from stack.
 *
 * @param stack the map containing all currently available variables and
 *            their values
 * @return a copy of this settings object with the file location replaced by
 *         the value of the variable
 * @throws InvalidSettingsException if the variable is not on the stack
 * @throws MalformedURLException if the value of the variable is not a valid
 *             URL
 */
VariableFileReaderNodeSettings createSettingsFrom(final Map<String, FlowVariable> stack) throws MalformedURLException, InvalidSettingsException {
    VariableFileReaderNodeSettings result = new VariableFileReaderNodeSettings(this);
    FlowVariable var = stack.get(m_variableName);
    if (var == null) {
        throw new InvalidSettingsException("File location variable (" + m_variableName + ") is not on the stack.");
    }
    if (!var.getType().equals(FlowVariable.Type.STRING)) {
        throw new InvalidSettingsException("Selected file location variable (" + m_variableName + ") is not of type string.");
    }
    if (var.getStringValue() == null || var.getStringValue().isEmpty()) {
        throw new InvalidSettingsException("File location variable (" + m_variableName + ") is not set. Execute predecessor.");
    }
    URL loc = FileReaderNodeDialog.textToURL(var.getStringValue());
    result.setDataFileLocationAndUpdateTableName(loc);
    return result;
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) URL(java.net.URL) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 87 with InvalidSettingsException

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

the class DBGroupByAggregationPanel method loadSettingsFrom.

/**
 * @param settings The settings to load from
 * @param dbspec {@link DatabasePortObjectSpec} with the database information e.g. the supported
 * {@link DBAggregationFunction}s
 * @param spec The spec containing the available columns
 * @throws NotConfigurableException if the connection settings cannot retrieved from the
 * {@link DatabasePortObjectSpec}.
 */
void loadSettingsFrom(final NodeSettingsRO settings, final DatabasePortObjectSpec dbspec, final DataTableSpec spec) throws NotConfigurableException {
    m_dbspec = dbspec;
    try {
        final DatabaseUtility utility = m_dbspec.getConnectionSettings(null).getUtility();
        final Collection<DBAggregationFunction> aggregationFunctions = utility.getAggregationFunctions();
        setSupportedAggregationFunctions(aggregationFunctions);
    } catch (final InvalidSettingsException e) {
        throw new NotConfigurableException(e.getMessage());
    }
    m_spec = spec;
    m_aggregatedColumnsModel.setRowCount(0);
    String[] columns = settings.getStringArray(DBGroupByNodeModel.CFG_AGGREGATED_COLUMNS, new String[0]);
    String[] methods = settings.getStringArray(DBGroupByNodeModel.CFG_AGGREGATION_METHODS, new String[0]);
    for (int i = 0; i < columns.length; i++) {
        m_aggregatedColumnsModel.addRow(new Object[] { columns[i], methods[i] });
    }
    refreshAvailableColumns();
}
Also used : NotConfigurableException(org.knime.core.node.NotConfigurableException) DatabaseUtility(org.knime.core.node.port.database.DatabaseUtility) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DBAggregationFunction(org.knime.core.node.port.database.aggregation.DBAggregationFunction)

Example 88 with InvalidSettingsException

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

the class VariableFileReaderNodeDialog method takeOverNewFileLocation.

/*
     * Reads the entered variable name from the edit field and stores the new
     * value in the settings object. Throws an exception if the entered URL is
     * invalid (and clears the URL in the settings object before). Returns true
     * if the entered location (string) is different from the one previously
     * set.
     */
private boolean takeOverNewFileLocation() throws InvalidSettingsException {
    FlowVariable sel = (FlowVariable) m_urlCombo.getSelectedItem();
    String varName = null;
    if (sel != null) {
        varName = sel.getName();
    }
    if (getAvailableFlowVariables().get(varName) == null) {
        // oops.
        throw new InvalidSettingsException("Selected variable not available anymore. " + "Select a different one.");
    }
    m_frSettings.setVariableName(varName);
    URL oldUrl = m_frSettings.getDataFileLocation();
    try {
        m_frSettings = m_frSettings.createSettingsFrom(getAvailableFlowVariables());
    } catch (Exception e) {
        m_frSettings.setDataFileLocationAndUpdateTableName(null);
        throw new InvalidSettingsException(e.getMessage());
    }
    String oldString = "";
    if (oldUrl != null) {
        oldString = oldUrl.toString();
    }
    return !oldString.equals(m_frSettings.getDataFileLocation().toString());
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) URL(java.net.URL) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NotConfigurableException(org.knime.core.node.NotConfigurableException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) TokenizerException(org.knime.core.util.tokenizer.TokenizerException) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 89 with InvalidSettingsException

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

the class VariableFileReaderNodeDialog method loadSettingsFromInternal.

/**
 * We do the entire load settings in the Event/GUI thread as it accesses a
 * lot of GUI components.
 */
private void loadSettingsFromInternal(final NodeSettingsRO settings, final PortObjectSpec[] specs) {
    assert (settings != null && specs != null);
    // loading of the variable names would trigger an item changed event.
    m_urlCombo.removeItemListener(this);
    m_urlCombo.removeAllItems();
    Map<String, FlowVariable> stack = getAvailableFlowVariables();
    for (FlowVariable fv : stack.values()) {
        m_urlCombo.addItem(fv);
    }
    m_urlCombo.addItemListener(this);
    try {
        // this will fail if the settings are invalid (which will be the
        // case when they come from an uninitialized model). We create
        // an empty settings object in the catch block.
        m_frSettings = new VariableFileReaderNodeSettings(settings);
    } catch (InvalidSettingsException ice) {
        m_frSettings = new VariableFileReaderNodeSettings();
    }
    String loadedLocation = null;
    if (m_frSettings.getDataFileLocation() != null) {
        loadedLocation = m_frSettings.getDataFileLocation().toString();
    }
    // check the specified variable
    if (stack.get(m_frSettings.getVariableName()) == null) {
        // the variable is not on the stack anymore
        m_frSettings.setVariableName("");
        m_frSettings.setDataFileLocationAndUpdateTableName(null);
    } else {
        String varVal = stack.get(m_frSettings.getVariableName()).getStringValue();
        try {
            URL varURL = textToURL(varVal);
            if (!varURL.toString().equals(m_frSettings.getDataFileLocation().toString())) {
                // variable points to a different location
                m_frSettings.setDataFileLocationAndUpdateTableName(null);
            }
        } catch (Exception e) {
            // the variable is still there - but has a invalid location
            m_frSettings.setDataFileLocationAndUpdateTableName(null);
        }
    }
    // set the URL, if available, or clear an invalid variable name
    try {
        m_frSettings = m_frSettings.createSettingsFrom(stack);
    } catch (Exception e) {
        m_frSettings.setVariableName("");
        m_frSettings.setDataFileLocationAndUpdateTableName(null);
    }
    FlowVariable fv = getAvailableFlowVariables().get(m_frSettings.getVariableName());
    m_urlCombo.setSelectedItem(fv);
    // transfer settings from the structure in the dialog's components
    if ((m_frSettings.getDataFileLocation() != null) && m_frSettings.getDataFileLocation().toString().equals(loadedLocation) && (m_frSettings.getColumnProperties() != null) && (m_frSettings.getColumnProperties().size() > 0)) {
        // do not analyze file if we got settings to use
        loadSettings(false);
    } else {
        // load settings and analyze file
        loadSettings(true);
    }
    // after loading settings we can clear the analyze warning
    setAnalWarningText("");
    // Reset flag when dialog opens
    m_preserveSettings.setSelected(false);
    updatePreview();
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) URL(java.net.URL) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NotConfigurableException(org.knime.core.node.NotConfigurableException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) TokenizerException(org.knime.core.util.tokenizer.TokenizerException) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 90 with InvalidSettingsException

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

the class VariableFileReaderNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    Map<String, FlowVariable> stack = createStack(m_frSettings.getVariableName());
    VariableFileReaderNodeSettings settings = m_frSettings.createSettingsFrom(stack);
    LOGGER.info("Preparing to read from '" + m_frSettings.getDataFileLocation().toString() + "'.");
    // check again the settings - especially file existence (under Linux
    // files could be deleted/renamed since last config-call...
    SettingsStatus status = settings.getStatusOfSettings(true, null);
    if (status.getNumOfErrors() > 0) {
        throw new InvalidSettingsException(status.getAllErrorMessages(10));
    }
    DataTableSpec tSpec = settings.createDataTableSpec();
    FileTable fTable = new FileTable(tSpec, settings, settings.getSkippedColumns(), exec);
    // create a DataContainer and fill it with the rows read. It is faster
    // then reading the file every time (for each row iterator), and it
    // collects the domain for each column for us. Also, if things fail,
    // the error message is printed during file reader execution (were it
    // belongs to) and not some time later when a node uses the row
    // iterator from the file table.
    BufferedDataContainer c = exec.createDataContainer(fTable.getDataTableSpec(), /* initDomain= */
    true);
    int row = 0;
    FileRowIterator it = fTable.iterator();
    try {
        if (it.getZipEntryName() != null) {
            // seems we are reading a ZIP archive.
            LOGGER.info("Reading entry '" + it.getZipEntryName() + "' from the specified ZIP archive.");
        }
        while (it.hasNext()) {
            row++;
            DataRow next = it.next();
            String message = "Caching row #" + row + " (\"" + next.getKey() + "\")";
            exec.setMessage(message);
            exec.checkCanceled();
            c.addRowToTable(next);
        }
        if (it.zippedSourceHasMoreEntries()) {
            // after reading til the end of the file this returns a valid
            // result
            setWarningMessage("Source is a ZIP archive with multiple " + "entries. Only reading first entry!");
        }
    } catch (DuplicateKeyException dke) {
        String msg = dke.getMessage();
        if (msg == null) {
            msg = "Duplicate row IDs";
        }
        msg += ". Consider making IDs unique in the advanced settings.";
        DuplicateKeyException newDKE = new DuplicateKeyException(msg);
        newDKE.initCause(dke);
        throw newDKE;
    } finally {
        c.close();
    }
    // user settings allow for truncating the table
    if (it.iteratorEndedEarly()) {
        setWarningMessage("Data was truncated due to user settings.");
    }
    BufferedDataTable out = c.getTable();
    // closes all sources.
    fTable.dispose();
    return new BufferedDataTable[] { out };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) SettingsStatus(org.knime.core.util.tokenizer.SettingsStatus) DataRow(org.knime.core.data.DataRow) DuplicateKeyException(org.knime.core.util.DuplicateKeyException) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) BufferedDataTable(org.knime.core.node.BufferedDataTable) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Aggregations

InvalidSettingsException (org.knime.core.node.InvalidSettingsException)818 DataTableSpec (org.knime.core.data.DataTableSpec)278 DataColumnSpec (org.knime.core.data.DataColumnSpec)211 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)153 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)121 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)113 IOException (java.io.IOException)109 DataCell (org.knime.core.data.DataCell)99 ArrayList (java.util.ArrayList)96 DataType (org.knime.core.data.DataType)89 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)82 File (java.io.File)72 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)69 DataRow (org.knime.core.data.DataRow)66 DoubleValue (org.knime.core.data.DoubleValue)58 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)48 SettingsModelFilterString (org.knime.core.node.defaultnodesettings.SettingsModelFilterString)47 FileInputStream (java.io.FileInputStream)43 LinkedHashMap (java.util.LinkedHashMap)42 NotConfigurableException (org.knime.core.node.NotConfigurableException)41