Search in sources :

Example 1 with ExcelInputMeta

use of org.pentaho.di.trans.steps.excelinput.ExcelInputMeta in project pentaho-kettle by pentaho.

the class ExcelInputDialog method showFiles.

private void showFiles() {
    ExcelInputMeta eii = new ExcelInputMeta();
    getInfo(eii);
    String[] files = eii.getFilePaths(transMeta);
    if (files.length > 0) {
        EnterSelectionDialog esd = new EnterSelectionDialog(shell, files, BaseMessages.getString(PKG, "ExcelInputDialog.FilesRead.DialogTitle"), BaseMessages.getString(PKG, "ExcelInputDialog.FilesRead.DialogMessage"));
        esd.setViewOnly();
        esd.open();
    } else {
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
        mb.setMessage(BaseMessages.getString(PKG, "ExcelInputDialog.NoFilesFound.DialogMessage"));
        mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title"));
        mb.open();
    }
}
Also used : ExcelInputMeta(org.pentaho.di.trans.steps.excelinput.ExcelInputMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) EnterSelectionDialog(org.pentaho.di.ui.core.dialog.EnterSelectionDialog) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 2 with ExcelInputMeta

use of org.pentaho.di.trans.steps.excelinput.ExcelInputMeta in project pentaho-kettle by pentaho.

the class ExcelInputDialog method getFields.

/**
 * Get the list of fields in the Excel workbook and put the result in the fields table view.
 */
public void getFields() {
    RowMetaInterface fields = new RowMeta();
    ExcelInputMeta info = new ExcelInputMeta();
    getInfo(info);
    int clearFields = SWT.YES;
    if (wFields.nrNonEmpty() > 0) {
        MessageBox messageBox = new MessageBox(shell, SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_QUESTION);
        messageBox.setMessage(BaseMessages.getString(PKG, "ExcelInputDialog.ClearFieldList.DialogMessage"));
        messageBox.setText(BaseMessages.getString(PKG, "ExcelInputDialog.ClearFieldList.DialogTitle"));
        clearFields = messageBox.open();
        if (clearFields == SWT.CANCEL) {
            return;
        }
    }
    FileInputList fileList = info.getFileList(transMeta);
    for (FileObject file : fileList.getFiles()) {
        try {
            KWorkbook workbook = WorkbookFactory.getWorkbook(info.getSpreadSheetType(), KettleVFS.getFilename(file), info.getEncoding());
            processingWorkbook(fields, info, workbook);
            workbook.close();
        } catch (Exception e) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "System.Dialog.Error.Title"), BaseMessages.getString(PKG, "ExcelInputDialog.ErrorReadingFile2.DialogMessage", KettleVFS.getFilename(file), e.toString()), e);
        }
    }
    if (fields.size() > 0) {
        if (clearFields == SWT.YES) {
            wFields.clearAll(false);
        }
        for (int j = 0; j < fields.size(); j++) {
            ValueMetaInterface field = fields.getValueMeta(j);
            wFields.add(new String[] { field.getName(), field.getTypeDesc(), "", "", "none", "N" });
        }
        wFields.removeEmptyRows();
        wFields.setRowNums();
        wFields.optWidth(true);
    } else {
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_WARNING);
        mb.setMessage(BaseMessages.getString(PKG, "ExcelInputDialog.UnableToFindFields.DialogMessage"));
        mb.setText(BaseMessages.getString(PKG, "ExcelInputDialog.UnableToFindFields.DialogTitle"));
        mb.open();
    }
    checkAlerts();
}
Also used : ExcelInputMeta(org.pentaho.di.trans.steps.excelinput.ExcelInputMeta) RowMeta(org.pentaho.di.core.row.RowMeta) KWorkbook(org.pentaho.di.core.spreadsheet.KWorkbook) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) FileObject(org.apache.commons.vfs2.FileObject) FileInputList(org.pentaho.di.core.fileinput.FileInputList) KettleStepException(org.pentaho.di.core.exception.KettleStepException) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) MessageBox(org.eclipse.swt.widgets.MessageBox) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 3 with ExcelInputMeta

use of org.pentaho.di.trans.steps.excelinput.ExcelInputMeta in project pentaho-metaverse by pentaho.

the class ExcelInputExternalResourceConsumer method getResourcesFromRow.

@Override
public Collection<IExternalResourceInfo> getResourcesFromRow(ExcelInput excelInput, RowMetaInterface rowMeta, Object[] row) {
    Collection<IExternalResourceInfo> resources = new LinkedList<IExternalResourceInfo>();
    ExcelInputMeta meta = (ExcelInputMeta) excelInput.getStepMetaInterface();
    if (meta == null) {
        meta = (ExcelInputMeta) excelInput.getStepMeta().getStepMetaInterface();
    }
    try {
        String filename = rowMeta.getString(row, meta.getAcceptingField(), null);
        if (!Const.isEmpty(filename)) {
            FileObject fileObject = KettleVFS.getFileObject(filename);
            resources.add(ExternalResourceInfoFactory.createFileResource(fileObject, true));
        }
    } catch (KettleException kve) {
    // TODO throw exception or ignore?
    }
    return resources;
}
Also used : ExcelInputMeta(org.pentaho.di.trans.steps.excelinput.ExcelInputMeta) KettleException(org.pentaho.di.core.exception.KettleException) IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) FileObject(org.apache.commons.vfs2.FileObject) LinkedList(java.util.LinkedList)

Example 4 with ExcelInputMeta

use of org.pentaho.di.trans.steps.excelinput.ExcelInputMeta in project pentaho-metaverse by pentaho.

the class MetaverseValidationIT method testExcelInputStep_filenameFromField.

@Test
public void testExcelInputStep_filenameFromField() throws Exception {
    // this is testing a specific TextFileInputStep instance
    ExcelInputStepNode excelInputStepNode = root.getExcelInputFileNameFromFieldStepNode();
    assertNotNull(excelInputStepNode);
    int countUses = getIterableSize(excelInputStepNode.getFileFieldNodesUses());
    int countInputs = getIterableSize(excelInputStepNode.getInputStreamFields());
    assertEquals(1, countUses);
    int fileFieldCount = 0;
    Iterable<StreamFieldNode> outFields = excelInputStepNode.getOutputStreamFields();
    int countOutputs = getIterableSize(outFields);
    for (StreamFieldNode outField : outFields) {
        assertNotNull(outField.getKettleType());
        if (!outField.getName().equals("filename")) {
            FieldNode fieldPopulatesMe = outField.getFieldPopulatesMe();
            assertNotNull(fieldPopulatesMe);
            assertEquals(DictionaryConst.NODE_TYPE_FILE_FIELD, fieldPopulatesMe.getType());
            assertEquals(excelInputStepNode, fieldPopulatesMe.getStepThatInputsMe());
            fileFieldCount++;
        }
    }
    // we should have one more input than file fields since we are reading it off of the input stream
    assertEquals(countInputs - 1, fileFieldCount);
    assertEquals(countOutputs - 1, fileFieldCount);
    String filenameField = null;
    TransMeta tm = new TransMeta(new FileInputStream(excelInputStepNode.getTransNode().getPath()), null, true, null, null);
    for (StepMeta stepMeta : tm.getSteps()) {
        if (stepMeta.getName().equals(excelInputStepNode.getName())) {
            ExcelInputMeta meta = (ExcelInputMeta) getBaseStepMetaFromStepMeta(stepMeta);
            assertTrue(meta.isAcceptingFilenames());
            filenameField = meta.getAcceptingField();
            assertNotNull(filenameField);
            assertEquals(filenameField, excelInputStepNode.getFileFieldNodesUses().iterator().next().getName());
            // this was the one we cared about...
            break;
        }
    }
}
Also used : ExcelInputMeta(org.pentaho.di.trans.steps.excelinput.ExcelInputMeta) FieldNode(org.pentaho.metaverse.frames.FieldNode) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) TransMeta(org.pentaho.di.trans.TransMeta) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) ExcelInputStepNode(org.pentaho.metaverse.frames.ExcelInputStepNode) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 5 with ExcelInputMeta

use of org.pentaho.di.trans.steps.excelinput.ExcelInputMeta in project pentaho-metaverse by pentaho.

the class ExcelInputStepAnalyzerTest method resourcesFromRowGotSuccessfullyWhenStepInputMetaInterfaceIsNull.

@Test
public void resourcesFromRowGotSuccessfullyWhenStepInputMetaInterfaceIsNull() throws Exception {
    StepMeta mockedStepMeta = mock(StepMeta.class);
    when(excelInput.getStepMetaInterface()).thenReturn(null);
    when(excelInput.getStepMeta()).thenReturn(mockedStepMeta);
    when(mockedStepMeta.getStepMetaInterface()).thenReturn(new ExcelInputMeta());
    when(rmi.getString(Mockito.any(Object[].class), Mockito.anyString(), Mockito.anyString())).thenReturn("/path/to/row/file");
    Collection<IExternalResourceInfo> resources = consumer.getResourcesFromRow(excelInput, rmi, ROW);
    assertEquals(1, resources.size());
}
Also used : ExcelInputMeta(org.pentaho.di.trans.steps.excelinput.ExcelInputMeta) IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Test(org.junit.Test)

Aggregations

ExcelInputMeta (org.pentaho.di.trans.steps.excelinput.ExcelInputMeta)9 Test (org.junit.Test)4 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)4 FileObject (org.apache.commons.vfs2.FileObject)3 MessageBox (org.eclipse.swt.widgets.MessageBox)3 KWorkbook (org.pentaho.di.core.spreadsheet.KWorkbook)3 TransMeta (org.pentaho.di.trans.TransMeta)3 KettlePluginException (org.pentaho.di.core.exception.KettlePluginException)2 KettleStepException (org.pentaho.di.core.exception.KettleStepException)2 FileInputList (org.pentaho.di.core.fileinput.FileInputList)2 RowMeta (org.pentaho.di.core.row.RowMeta)2 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)2 KSheet (org.pentaho.di.core.spreadsheet.KSheet)2 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)2 StepMeta (org.pentaho.di.trans.step.StepMeta)2 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)2 IExternalResourceInfo (org.pentaho.metaverse.api.model.IExternalResourceInfo)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 Method (java.lang.reflect.Method)1