Search in sources :

Example 1 with SettingsStatus

use of org.knime.core.util.tokenizer.SettingsStatus 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)

Example 2 with SettingsStatus

use of org.knime.core.util.tokenizer.SettingsStatus in project knime-core by knime.

the class FileReaderNodeSettings method createDataTableSpec.

/**
 * @since 2.12
 */
public DataTableSpec createDataTableSpec(final boolean checkFile) {
    // first check if the settings are in a state we can create a valid
    // table spec for.
    // SettingsStatus status = new SettingsStatus();
    // addThisStatus(status);
    SettingsStatus status = getStatusOfSettings(true, null);
    if (status.getNumOfErrors() > 0) {
        return null;
    }
    // collect the ColumnSpecs for each column
    Vector<DataColumnSpec> cSpec = new Vector<DataColumnSpec>();
    for (int c = 0; c < getNumberOfColumns(); c++) {
        ColProperty cProp = m_columnProperties.get(c);
        if (!cProp.getSkipThisColumn()) {
            cSpec.add(cProp.getColumnSpec());
        }
    }
    return new DataTableSpec(getTableName(), cSpec.toArray(new DataColumnSpec[cSpec.size()]));
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) SettingsStatus(org.knime.core.util.tokenizer.SettingsStatus) Vector(java.util.Vector)

Example 3 with SettingsStatus

use of org.knime.core.util.tokenizer.SettingsStatus in project knime-core by knime.

the class FileReaderSettings method getStatusOfSettings.

/**
 * Method to check consistency and completeness of the current settings. It
 * will return a {@link SettingsStatus} object which contains info, warning
 * and error messages. Or if the settings are alright it will return null.
 *
 * @param openDataFile tells whether or not this method should try to access
 *            the data file. This will - if set <code>true</code> - verify
 *            the accessibility of the data.
 * @param tableSpec the spec of the DataTable these settings are for. If set
 *            <code>null</code> only a few checks will be performed - the
 *            ones that are possible without the knowledge of the structure
 *            of the table
 * @return a SettingsStatus object containing info, warning and error
 *         messages, or <code>null</code> if no messages were generated
 *         (i.e. all settings are just fine).
 */
public SettingsStatus getStatusOfSettings(final boolean openDataFile, final DataTableSpec tableSpec) {
    SettingsStatus status = new SettingsStatus();
    addStatusOfSettings(status, openDataFile, tableSpec);
    return status;
}
Also used : SettingsStatus(org.knime.core.util.tokenizer.SettingsStatus)

Example 4 with SettingsStatus

use of org.knime.core.util.tokenizer.SettingsStatus in project knime-core by knime.

the class FileTable method getStatusOfSettings.

/**
 * Method to check consistency and completeness of the current settings. It
 * will return a {@link SettingsStatus} object which contains info, warning
 * and error messages. Or if the settings are alright it will return null.
 *
 * @param openDataFile tells whether or not this method should try to access
 *            the data file. This will - if set <code>true</code> - verify
 *            the accessibility of the data.
 * @return a SettingsStatus object containing info, warning and error
 *         messages, or <code>null</code> if no messages were generated
 *         (i.e. all settings are just fine)
 */
public SettingsStatus getStatusOfSettings(final boolean openDataFile) {
    SettingsStatus status = new SettingsStatus();
    addStatusOfSettings(status, openDataFile);
    return status;
}
Also used : SettingsStatus(org.knime.core.util.tokenizer.SettingsStatus)

Example 5 with SettingsStatus

use of org.knime.core.util.tokenizer.SettingsStatus in project knime-core by knime.

the class VariableFileReaderNodeDialog method updatePreview.

/*
     * from the current settings it creates a data table and displays it in the
     * preview pane. Will not analyze the file. Will not change things.
     */
private void updatePreview() {
    // the settings changed - clear error message first
    setErrorLabelText("");
    // update preview
    if ((m_frSettings.getVariableName() == null) || (m_frSettings.getVariableName().isEmpty())) {
        // if there is no data file specified display empty table
        setPreviewTable(null);
        showPreviewTable();
        return;
    }
    VariableFileReaderNodeSettings sWithLoc;
    try {
        sWithLoc = m_frSettings.createSettingsFrom(getAvailableFlowVariables());
    } catch (Exception e) {
        setPreviewTable(null);
        showPreviewTable();
        return;
    }
    FileReaderNodeSettings previewSettings = createPreviewSettings(sWithLoc);
    SettingsStatus status = previewSettings.getStatusOfSettings(true, null);
    if (status.getNumOfErrors() > 0) {
        setErrorLabelText(status.getErrorMessage(0));
        setPreviewTable(null);
        showPreviewTable();
        return;
    }
    DataTableSpec tSpec = previewSettings.createDataTableSpec();
    FileReaderPreviewTable newTable = new FileReaderPreviewTable(tSpec, previewSettings, null);
    setPreviewTable(newTable);
    showPreviewTable();
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) SettingsStatus(org.knime.core.util.tokenizer.SettingsStatus) 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)

Aggregations

SettingsStatus (org.knime.core.util.tokenizer.SettingsStatus)11 DataTableSpec (org.knime.core.data.DataTableSpec)6 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)5 DataRow (org.knime.core.data.DataRow)2 ExecutionContext (org.knime.core.node.ExecutionContext)2 DuplicateKeyException (org.knime.core.util.DuplicateKeyException)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Vector (java.util.Vector)1 FileReaderExecutionMonitor (org.knime.base.node.io.filereader.FileReaderExecutionMonitor)1 FileReaderNodeSettings (org.knime.base.node.io.filereader.FileReaderNodeSettings)1 FileTable (org.knime.base.node.io.filereader.FileTable)1 DataColumnSpec (org.knime.core.data.DataColumnSpec)1 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)1 BufferedDataTable (org.knime.core.node.BufferedDataTable)1 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)1 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)1 NotConfigurableException (org.knime.core.node.NotConfigurableException)1 BufferedDataTableRowOutput (org.knime.core.node.streamable.BufferedDataTableRowOutput)1