use of org.pentaho.di.trans.steps.fileinput.text.TextFileInputMeta in project pentaho-kettle by pentaho.
the class TextFileInputDialogTest method testMinimalWidth_PDI_14253.
@Test
public void testMinimalWidth_PDI_14253() throws Exception {
final String virtualFile = "ram://pdi-14253.txt";
KettleVFS.getFileObject(virtualFile).createFile();
final String content = "r1c1, r1c2\nr2c1 , r2c2 ";
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bos.write(content.getBytes());
OutputStream os = KettleVFS.getFileObject(virtualFile).getContent().getOutputStream();
IOUtils.copy(new ByteArrayInputStream(bos.toByteArray()), os);
os.close();
TextFileInputMeta meta = new TextFileInputMeta();
meta.content.lineWrapped = false;
meta.inputFields = new BaseFileField[] { new BaseFileField("col1", -1, -1), new BaseFileField("col2", -1, -1) };
meta.content.fileCompression = "None";
meta.content.fileType = "CSV";
meta.content.header = false;
meta.content.nrHeaderLines = -1;
meta.content.footer = false;
meta.content.nrFooterLines = -1;
TextFileInputData data = new TextFileInputData();
data.files = new FileInputList();
data.files.addFile(KettleVFS.getFileObject(virtualFile));
data.outputRowMeta = new RowMeta();
data.outputRowMeta.addValueMeta(new ValueMetaString("col1"));
data.outputRowMeta.addValueMeta(new ValueMetaString("col2"));
data.dataErrorLineHandler = mock(FileErrorHandler.class);
data.fileFormatType = TextFileInputMeta.FILE_FORMAT_UNIX;
data.separator = ",";
data.filterProcessor = new TextFileFilterProcessor(new TextFileFilter[0], new Variables() {
});
data.filePlayList = new FilePlayListAll();
TextFileInputDialog dialog = new TextFileInputDialog(mock(Shell.class), meta, mock(TransMeta.class), "TFIMinimalWidthTest");
TableView tv = mock(TableView.class);
when(tv.nrNonEmpty()).thenReturn(0);
// click the Minimal width button
dialog.setMinimalWidth(tv);
RowSet output = new BlockingRowSet(5);
TextFileInput input = StepMockUtil.getStep(TextFileInput.class, TextFileInputMeta.class, "test");
input.setOutputRowSets(Collections.singletonList(output));
while (input.processRow(meta, data)) {
// wait until the step completes executing
}
Object[] row1 = output.getRowImmediate();
assertRow(row1, "r1c1", "r1c2");
Object[] row2 = output.getRowImmediate();
assertRow(row2, "r2c1", "r2c2");
KettleVFS.getFileObject(virtualFile).delete();
}
use of org.pentaho.di.trans.steps.fileinput.text.TextFileInputMeta in project pentaho-kettle by pentaho.
the class TextFileInputDialog method showFiles.
private void showFiles() {
TextFileInputMeta tfii = new TextFileInputMeta();
getInfo(tfii, true);
String[] files = FileInputList.createFilePathList(transMeta, tfii.inputFiles.fileName, tfii.inputFiles.fileMask, tfii.inputFiles.excludeFileMask, tfii.inputFiles.fileRequired, tfii.inputFiles.includeSubFolderBoolean());
if (files != null && files.length > 0) {
EnterSelectionDialog esd = new EnterSelectionDialog(shell, files, "Files read", "Files read:");
esd.setViewOnly();
esd.open();
} else {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setMessage(BaseMessages.getString(PKG, "TextFileInputDialog.NoFilesFound.DialogMessage"));
mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title"));
mb.open();
}
}
use of org.pentaho.di.trans.steps.fileinput.text.TextFileInputMeta in project pentaho-kettle by pentaho.
the class TextFileInputDialog method first.
// Get the first x lines
private void first(boolean skipHeaders) {
TextFileInputMeta info = new TextFileInputMeta();
getInfo(info, true);
try {
if (info.getFileInputList(transMeta).nrOfFiles() > 0) {
String shellText = BaseMessages.getString(PKG, "TextFileInputDialog.LinesToView.DialogTitle");
String lineText = BaseMessages.getString(PKG, "TextFileInputDialog.LinesToView.DialogMessage");
EnterNumberDialog end = new EnterNumberDialog(shell, 100, shellText, lineText);
int nrLines = end.open();
if (nrLines >= 0) {
List<String> linesList = getFirst(nrLines, skipHeaders);
if (linesList != null && linesList.size() > 0) {
String firstlines = "";
for (String aLinesList : linesList) {
firstlines += aLinesList + Const.CR;
}
EnterTextDialog etd = new EnterTextDialog(shell, BaseMessages.getString(PKG, "TextFileInputDialog.ContentOfFirstFile.DialogTitle"), (nrLines == 0 ? BaseMessages.getString(PKG, "TextFileInputDialog.ContentOfFirstFile.AllLines.DialogMessage") : BaseMessages.getString(PKG, "TextFileInputDialog.ContentOfFirstFile.NLines.DialogMessage", "" + nrLines)), firstlines, true);
etd.setReadOnly();
etd.open();
} else {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setMessage(BaseMessages.getString(PKG, "TextFileInputDialog.UnableToReadLines.DialogMessage"));
mb.setText(BaseMessages.getString(PKG, "TextFileInputDialog.UnableToReadLines.DialogTitle"));
mb.open();
}
}
} else {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setMessage(BaseMessages.getString(PKG, "TextFileInputDialog.NoValidFile.DialogMessage"));
mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title"));
mb.open();
}
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "System.Dialog.Error.Title"), BaseMessages.getString(PKG, "TextFileInputDialog.ErrorGettingData.DialogMessage"), e);
}
}
use of org.pentaho.di.trans.steps.fileinput.text.TextFileInputMeta in project pentaho-kettle by pentaho.
the class TextFileInputDialog method getFixed.
private void getFixed() {
TextFileInputMeta info = new TextFileInputMeta();
getInfo(info, true);
Shell sh = new Shell(shell, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN);
try {
List<String> rows = getFirst(50, false);
fields = getFields(info, rows);
final TextFileImportWizardPage1 page1 = new TextFileImportWizardPage1("1", props, rows, fields);
page1.createControl(sh);
final TextFileImportWizardPage2 page2 = new TextFileImportWizardPage2("2", props, rows, fields);
page2.createControl(sh);
Wizard wizard = new Wizard() {
public boolean performFinish() {
wFields.clearAll(false);
for (TextFileInputFieldInterface field1 : fields) {
BaseFileField field = (BaseFileField) field1;
if (!field.isIgnored() && field.getLength() > 0) {
TableItem item = new TableItem(wFields.table, SWT.NONE);
item.setText(1, field.getName());
item.setText(2, "" + field.getTypeDesc());
item.setText(3, "" + field.getFormat());
item.setText(4, "" + field.getPosition());
item.setText(5, field.getLength() < 0 ? "" : "" + field.getLength());
item.setText(6, field.getPrecision() < 0 ? "" : "" + field.getPrecision());
item.setText(7, "" + field.getCurrencySymbol());
item.setText(8, "" + field.getDecimalSymbol());
item.setText(9, "" + field.getGroupSymbol());
item.setText(10, "" + field.getNullString());
item.setText(11, "" + field.getIfNullValue());
item.setText(12, "" + field.getTrimTypeDesc());
item.setText(13, field.isRepeated() ? BaseMessages.getString(PKG, "System.Combo.Yes") : BaseMessages.getString(PKG, "System.Combo.No"));
}
}
int size = wFields.table.getItemCount();
if (size == 0) {
new TableItem(wFields.table, SWT.NONE);
}
wFields.removeEmptyRows();
wFields.setRowNums();
wFields.optWidth(true);
input.setChanged();
return true;
}
};
wizard.addPage(page1);
wizard.addPage(page2);
WizardDialog wd = new WizardDialog(shell, wizard);
WizardDialog.setDefaultImage(GUIResource.getInstance().getImageWizard());
wd.setMinimumPageSize(700, 375);
wd.updateSize();
wd.open();
} catch (Exception e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "TextFileInputDialog.ErrorShowingFixedWizard.DialogTitle"), BaseMessages.getString(PKG, "TextFileInputDialog.ErrorShowingFixedWizard.DialogMessage"), e);
}
}
Aggregations