Search in sources :

Example 1 with FileReaderNodeSettings

use of org.knime.base.node.io.filereader.FileReaderNodeSettings in project knime-core by knime.

the class CSVWriterNodeDialog method saveSettingsTo.

/**
 * {@inheritDoc}
 */
@Override
protected void saveSettingsTo(final NodeSettingsWO settings) throws InvalidSettingsException {
    FileWriterNodeSettings values = new FileWriterNodeSettings();
    values.setFileName(m_filePanel.getSelectedFile().trim());
    values.setWriteColumnHeader(m_colHeaderChecker.isSelected());
    values.setSkipColHeaderIfFileExists(m_colHeaderWriteSkipOnAppend.isSelected());
    values.setWriteRowID(m_rowHeaderChecker.isSelected());
    FileOverwritePolicy overwritePolicy;
    if (m_overwritePolicyAppendButton.isSelected()) {
        overwritePolicy = FileOverwritePolicy.Append;
    } else if (m_overwritePolicyOverwriteButton.isSelected()) {
        overwritePolicy = FileOverwritePolicy.Overwrite;
    } else {
        overwritePolicy = FileOverwritePolicy.Abort;
    }
    values.setFileOverwritePolicy(overwritePolicy);
    values.setGzipOutput(m_useGzipChecker.isSelected());
    m_quotePanel.saveValuesFromPanelInto(values);
    m_advancedPanel.saveValuesFromPanelInto(values);
    m_commentPanel.saveValuesFromPanelInto(values);
    m_decSeparatorPanel.saveValuesFromPanelInto(values);
    String errMsg = m_encodingPanel.checkSettings();
    if (errMsg != null) {
        throw new InvalidSettingsException(errMsg);
    }
    FileReaderNodeSettings s = new FileReaderNodeSettings();
    m_encodingPanel.overrideSettings(s);
    values.setCharacterEncoding(s.getCharsetName());
    values.saveSettingsTo(settings);
    m_filePanel.addToHistory();
}
Also used : FileReaderNodeSettings(org.knime.base.node.io.filereader.FileReaderNodeSettings) FileOverwritePolicy(org.knime.base.node.io.csvwriter.FileWriterNodeSettings.FileOverwritePolicy) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Example 2 with FileReaderNodeSettings

use of org.knime.base.node.io.filereader.FileReaderNodeSettings in project knime-core by knime.

the class CSVReaderNodeDialog method saveSettingsTo.

/**
 * {@inheritDoc}
 */
@Override
protected void saveSettingsTo(final NodeSettingsWO settings) throws InvalidSettingsException {
    CSVReaderConfig config = new CSVReaderConfig();
    String fileS = m_filePanel.getSelectedFile().trim();
    config.setLocation(fileS);
    config.setColDelimiter(unescape(m_colDelimiterField.getText()));
    config.setRowDelimiter(unescape(m_rowDelimiterField.getText()));
    config.setQuoteString(m_quoteStringField.getText());
    config.setCommentStart(m_commentStartField.getText());
    config.setHasRowHeader(m_hasRowHeaderChecker.isSelected());
    config.setHasColHeader(m_hasColHeaderChecker.isSelected());
    config.setSupportShortLines(m_supportShortLinesChecker.isSelected());
    int skiptFirstLines = (Integer) (m_skipFirstLinesChecker.isSelected() ? m_skipFirstLinesSpinner.getValue() : -1);
    config.setSkipFirstLinesCount(skiptFirstLines);
    int limitRows = (Integer) (m_limitRowsChecker.isSelected() ? m_limitRowsSpinner.getValue() : -1);
    config.setLimitRowsCount(limitRows);
    int limitAnalysis = (Integer) (m_limitAnalysisChecker.isSelected() ? m_limitAnalysisSpinner.getValue() : -1);
    config.setLimitAnalysisCount(limitAnalysis);
    FileReaderNodeSettings s = new FileReaderNodeSettings();
    m_encodingPanel.overrideSettings(s);
    config.setCharSetName(s.getCharsetName());
    config.setConnectTimeout(m_filePanel.getConnectTimeout().orElse(null));
    config.saveSettingsTo(settings);
    m_filePanel.addToHistory();
}
Also used : FileReaderNodeSettings(org.knime.base.node.io.filereader.FileReaderNodeSettings)

Example 3 with FileReaderNodeSettings

use of org.knime.base.node.io.filereader.FileReaderNodeSettings in project knime-core by knime.

the class CSVReaderNodeModel method createFileTable.

protected FileTable createFileTable(final ExecutionContext exec) throws Exception {
    // prepare the settings for the file analyzer
    FileReaderNodeSettings settings = new FileReaderNodeSettings();
    CheckUtils.checkSourceFile(m_config.getLocation());
    URL url = FileUtil.toURL(m_config.getLocation());
    settings.setDataFileLocationAndUpdateTableName(url);
    String colDel = m_config.getColDelimiter();
    if (colDel != null && !colDel.isEmpty()) {
        settings.addDelimiterPattern(colDel, false, false, false);
    }
    settings.setDelimiterUserSet(true);
    String rowDel = m_config.getRowDelimiter();
    if (rowDel != null && !rowDel.isEmpty()) {
        settings.addRowDelimiter(rowDel, true);
    }
    String quote = m_config.getQuoteString();
    if (quote != null && !quote.isEmpty()) {
        settings.addQuotePattern(quote, quote);
    }
    settings.setQuoteUserSet(true);
    String commentStart = m_config.getCommentStart();
    if (commentStart != null && !commentStart.isEmpty()) {
        settings.addSingleLineCommentPattern(commentStart, false, false);
    }
    settings.setCommentUserSet(true);
    boolean hasColHeader = m_config.hasColHeader();
    settings.setFileHasColumnHeaders(hasColHeader);
    settings.setFileHasColumnHeadersUserSet(true);
    boolean hasRowHeader = m_config.hasRowHeader();
    settings.setFileHasRowHeaders(hasRowHeader);
    settings.setFileHasRowHeadersUserSet(true);
    settings.setWhiteSpaceUserSet(true);
    boolean supportShortLines = m_config.isSupportShortLines();
    settings.setSupportShortLines(supportShortLines);
    int skipFirstLinesCount = m_config.getSkipFirstLinesCount();
    settings.setSkipFirstLines(skipFirstLinesCount);
    final long limitRowsCount = m_config.getLimitRowsCount();
    settings.setMaximumNumberOfRowsToRead(limitRowsCount);
    settings.setCharsetName(m_config.getCharSetName());
    settings.setCharsetUserSet(true);
    settings.setConnectTimeout(m_config.getConnectTimeout());
    final int limitAnalysisCount = m_config.getLimitAnalysisCount();
    final ExecutionMonitor analyseExec = exec.createSubProgress(0.5);
    final ExecutionContext readExec = exec.createSubExecutionContext(0.5);
    exec.setMessage("Analyzing file");
    if (limitAnalysisCount >= 0) {
        final FileReaderExecutionMonitor fileReaderExec = new FileReaderExecutionMonitor();
        fileReaderExec.getProgressMonitor().addProgressListener(new NodeProgressListener() {

            @Override
            public void progressChanged(final NodeProgressEvent pe) {
                try {
                    // if the node was canceled, cancel (interrupt) the analysis
                    analyseExec.checkCanceled();
                    // otherwise update the node progress
                    NodeProgress nodeProgress = pe.getNodeProgress();
                    analyseExec.setProgress(nodeProgress.getProgress(), nodeProgress.getMessage());
                } catch (CanceledExecutionException e) {
                    fileReaderExec.setExecuteInterrupted();
                }
            }
        });
        fileReaderExec.setShortCutLines(limitAnalysisCount);
        fileReaderExec.setExecuteCanceled();
        settings = FileAnalyzer.analyze(settings, fileReaderExec);
    } else {
        settings = FileAnalyzer.analyze(settings, analyseExec);
    }
    SettingsStatus status = settings.getStatusOfSettings();
    if (status.getNumOfErrors() > 0) {
        throw new IllegalStateException(status.getErrorMessage(0));
    }
    final DataTableSpec tableSpec = settings.createDataTableSpec();
    if (tableSpec == null) {
        final SettingsStatus status2 = settings.getStatusOfSettings(true, null);
        if (status2.getNumOfErrors() > 0) {
            throw new IllegalStateException(status2.getErrorMessage(0));
        } else {
            throw new IllegalStateException("Unknown error during file analysis.");
        }
    }
    exec.setMessage("Buffering file");
    return new FileTable(tableSpec, settings, readExec);
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) NodeProgressListener(org.knime.core.node.workflow.NodeProgressListener) NodeProgress(org.knime.core.node.workflow.NodeProgress) FileTable(org.knime.base.node.io.filereader.FileTable) SettingsStatus(org.knime.core.util.tokenizer.SettingsStatus) URL(java.net.URL) FileReaderNodeSettings(org.knime.base.node.io.filereader.FileReaderNodeSettings) ExecutionContext(org.knime.core.node.ExecutionContext) NodeProgressEvent(org.knime.core.node.workflow.NodeProgressEvent) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) FileReaderExecutionMonitor(org.knime.base.node.io.filereader.FileReaderExecutionMonitor) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) FileReaderExecutionMonitor(org.knime.base.node.io.filereader.FileReaderExecutionMonitor)

Aggregations

FileReaderNodeSettings (org.knime.base.node.io.filereader.FileReaderNodeSettings)3 URL (java.net.URL)1 FileOverwritePolicy (org.knime.base.node.io.csvwriter.FileWriterNodeSettings.FileOverwritePolicy)1 FileReaderExecutionMonitor (org.knime.base.node.io.filereader.FileReaderExecutionMonitor)1 FileTable (org.knime.base.node.io.filereader.FileTable)1 DataTableSpec (org.knime.core.data.DataTableSpec)1 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)1 ExecutionContext (org.knime.core.node.ExecutionContext)1 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)1 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1 NodeProgress (org.knime.core.node.workflow.NodeProgress)1 NodeProgressEvent (org.knime.core.node.workflow.NodeProgressEvent)1 NodeProgressListener (org.knime.core.node.workflow.NodeProgressListener)1 SettingsStatus (org.knime.core.util.tokenizer.SettingsStatus)1