Search in sources :

Example 6 with TextFileInputMeta

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();
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) TextFileFilterProcessor(org.pentaho.di.trans.steps.fileinput.text.TextFileFilterProcessor) RowMeta(org.pentaho.di.core.row.RowMeta) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) TextFileFilter(org.pentaho.di.trans.steps.fileinput.text.TextFileFilter) FilePlayListAll(org.pentaho.di.core.playlist.FilePlayListAll) BaseFileField(org.pentaho.di.trans.steps.file.BaseFileField) TransMeta(org.pentaho.di.trans.TransMeta) RowSet(org.pentaho.di.core.RowSet) BlockingRowSet(org.pentaho.di.core.BlockingRowSet) BlockingRowSet(org.pentaho.di.core.BlockingRowSet) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Variables(org.pentaho.di.core.variables.Variables) Shell(org.eclipse.swt.widgets.Shell) TextFileInputMeta(org.pentaho.di.trans.steps.fileinput.text.TextFileInputMeta) ByteArrayInputStream(java.io.ByteArrayInputStream) TextFileInput(org.pentaho.di.trans.steps.fileinput.text.TextFileInput) FileErrorHandler(org.pentaho.di.trans.step.errorhandling.FileErrorHandler) TextFileInputData(org.pentaho.di.trans.steps.fileinput.text.TextFileInputData) FileInputList(org.pentaho.di.core.fileinput.FileInputList) TableView(org.pentaho.di.ui.core.widget.TableView) Test(org.junit.Test)

Example 7 with TextFileInputMeta

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();
    }
}
Also used : TextFileInputMeta(org.pentaho.di.trans.steps.fileinput.text.TextFileInputMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) EnterSelectionDialog(org.pentaho.di.ui.core.dialog.EnterSelectionDialog) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 8 with TextFileInputMeta

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);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) TextFileInputMeta(org.pentaho.di.trans.steps.fileinput.text.TextFileInputMeta) EnterTextDialog(org.pentaho.di.ui.core.dialog.EnterTextDialog) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) EnterNumberDialog(org.pentaho.di.ui.core.dialog.EnterNumberDialog) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 9 with TextFileInputMeta

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);
    }
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) BaseFileField(org.pentaho.di.trans.steps.file.BaseFileField) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException) Shell(org.eclipse.swt.widgets.Shell) TextFileInputMeta(org.pentaho.di.trans.steps.fileinput.text.TextFileInputMeta) TextFileInputFieldInterface(org.pentaho.di.core.gui.TextFileInputFieldInterface) Wizard(org.eclipse.jface.wizard.Wizard) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Aggregations

TextFileInputMeta (org.pentaho.di.trans.steps.fileinput.text.TextFileInputMeta)9 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)7 KettleException (org.pentaho.di.core.exception.KettleException)6 MessageBox (org.eclipse.swt.widgets.MessageBox)4 IOException (java.io.IOException)3 FileObject (org.apache.commons.vfs2.FileObject)3 FileInputList (org.pentaho.di.core.fileinput.FileInputList)3 BaseFileField (org.pentaho.di.trans.steps.file.BaseFileField)3 EnterNumberDialog (org.pentaho.di.ui.core.dialog.EnterNumberDialog)3 EnterTextDialog (org.pentaho.di.ui.core.dialog.EnterTextDialog)3 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)3 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 ArrayList (java.util.ArrayList)2 Shell (org.eclipse.swt.widgets.Shell)2 TableItem (org.eclipse.swt.widgets.TableItem)2 CompressionInputStream (org.pentaho.di.core.compress.CompressionInputStream)2 CompressionProvider (org.pentaho.di.core.compress.CompressionProvider)2 RowMeta (org.pentaho.di.core.row.RowMeta)2 TransMeta (org.pentaho.di.trans.TransMeta)2