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 };
}
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()]));
}
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;
}
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;
}
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();
}
Aggregations