Search in sources :

Example 1 with ExcelInputField

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

the class ExcelInputDialog method getInfo.

private void getInfo(ExcelInputMeta meta) {
    // return value
    stepname = wStepname.getText();
    // copy info to Meta class (input)
    meta.setRowLimit(Const.toLong(wLimit.getText(), 0));
    meta.setEncoding(wEncoding.getText());
    meta.setSpreadSheetType(SpreadSheetType.values()[wSpreadSheetType.getSelectionIndex()]);
    meta.setFileField(wInclFilenameField.getText());
    meta.setSheetField(wInclSheetnameField.getText());
    meta.setSheetRowNumberField(wInclSheetRownumField.getText());
    meta.setRowNumberField(wInclRownumField.getText());
    meta.setAddResultFile(wAddResult.getSelection());
    meta.setStartsWithHeader(wHeader.getSelection());
    meta.setIgnoreEmptyRows(wNoempty.getSelection());
    meta.setStopOnEmpty(wStoponempty.getSelection());
    meta.setAcceptingFilenames(wAccFilenames.getSelection());
    meta.setAcceptingField(wAccField.getText());
    meta.setAcceptingStepName(wAccStep.getText());
    meta.searchInfoAndTargetSteps(transMeta.findPreviousSteps(transMeta.findStep(stepname)));
    int nrfiles = wFilenameList.nrNonEmpty();
    int nrsheets = wSheetnameList.nrNonEmpty();
    int nrfields = wFields.nrNonEmpty();
    meta.allocate(nrfiles, nrsheets, nrfields);
    meta.setFileName(wFilenameList.getItems(0));
    meta.setFileMask(wFilenameList.getItems(1));
    meta.setExcludeFileMask(wFilenameList.getItems(2));
    meta.setFileRequired(wFilenameList.getItems(3));
    meta.setIncludeSubFolders(wFilenameList.getItems(4));
    // CHECKSTYLE:Indentation:OFF
    for (int i = 0; i < nrsheets; i++) {
        TableItem item = wSheetnameList.getNonEmpty(i);
        meta.getSheetName()[i] = item.getText(1);
        meta.getStartRow()[i] = Const.toInt(item.getText(2), 0);
        meta.getStartColumn()[i] = Const.toInt(item.getText(3), 0);
    }
    // CHECKSTYLE:Indentation:OFF
    for (int i = 0; i < nrfields; i++) {
        TableItem item = wFields.getNonEmpty(i);
        meta.getField()[i] = new ExcelInputField();
        meta.getField()[i].setName(item.getText(1));
        meta.getField()[i].setType(ValueMetaFactory.getIdForValueMeta(item.getText(2)));
        String slength = item.getText(3);
        String sprec = item.getText(4);
        meta.getField()[i].setTrimType(ExcelInputMeta.getTrimTypeByDesc(item.getText(5)));
        meta.getField()[i].setRepeated(BaseMessages.getString(PKG, "System.Combo.Yes").equalsIgnoreCase(item.getText(6)));
        meta.getField()[i].setLength(Const.toInt(slength, -1));
        meta.getField()[i].setPrecision(Const.toInt(sprec, -1));
        meta.getField()[i].setFormat(item.getText(7));
        meta.getField()[i].setCurrencySymbol(item.getText(8));
        meta.getField()[i].setDecimalSymbol(item.getText(9));
        meta.getField()[i].setGroupSymbol(item.getText(10));
    }
    // Error handling fields...
    meta.setStrictTypes(wStrictTypes.getSelection());
    meta.setErrorIgnored(wErrorIgnored.getSelection());
    meta.setErrorLineSkipped(wSkipErrorLines.getSelection());
    meta.setWarningFilesDestinationDirectory(wWarningDestDir.getText());
    meta.setBadLineFilesExtension(wWarningExt.getText());
    meta.setErrorFilesDestinationDirectory(wErrorDestDir.getText());
    meta.setErrorFilesExtension(wErrorExt.getText());
    meta.setLineNumberFilesDestinationDirectory(wLineNrDestDir.getText());
    meta.setLineNumberFilesExtension(wLineNrExt.getText());
    meta.setShortFileNameField(wShortFileFieldName.getText());
    meta.setPathField(wPathFieldName.getText());
    meta.setIsHiddenField(wIsHiddenName.getText());
    meta.setLastModificationDateField(wLastModificationTimeName.getText());
    meta.setUriField(wUriName.getText());
    meta.setRootUriField(wRootUriName.getText());
    meta.setExtensionField(wExtensionFieldName.getText());
    meta.setSizeField(wSizeFieldName.getText());
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ExcelInputField(org.pentaho.di.trans.steps.excelinput.ExcelInputField)

Example 2 with ExcelInputField

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

the class ExcelWriterStepIntIT method testPDI11374.

@Test
public void testPDI11374() throws KettleException, IOException {
    String stepName = "Excel Writer";
    ExcelWriterStepMeta meta = new ExcelWriterStepMeta();
    meta.setDefault();
    File tempOutputFile = File.createTempFile("testPDI11374", ".xlsx");
    tempOutputFile.deleteOnExit();
    meta.setFileName(tempOutputFile.getAbsolutePath().replace(".xlsx", ""));
    meta.setExtension("xlsx");
    meta.setSheetname("Sheet10");
    meta.setOutputFields(new ExcelWriterStepField[] {});
    meta.setHeaderEnabled(true);
    TransMeta transMeta = TransTestFactory.generateTestTransformation(null, meta, stepName);
    List<RowMetaAndData> inputList = getPDI11374RowMetaAndData();
    TransTestFactory.executeTestTransformation(transMeta, TransTestFactory.INJECTOR_STEPNAME, stepName, TransTestFactory.DUMMY_STEPNAME, inputList);
    try {
        Thread.sleep(1000);
    } catch (InterruptedException ignore) {
    // Wait a second to ensure that the output file is properly closed
    }
    // Now, check the result
    String checkStepName = "Excel Input";
    ExcelInputMeta excelInput = new ExcelInputMeta();
    excelInput.setFileName(new String[] { tempOutputFile.getAbsolutePath() });
    excelInput.setFileMask(new String[] { "" });
    excelInput.setExcludeFileMask(new String[] { "" });
    excelInput.setFileRequired(new String[] { "N" });
    excelInput.setIncludeSubFolders(new String[] { "N" });
    excelInput.setSpreadSheetType(SpreadSheetType.POI);
    excelInput.setSheetName(new String[] { "Sheet10" });
    excelInput.setStartColumn(new int[] { 0 });
    excelInput.setStartRow(new int[] { 0 });
    // Ensures that we can check the header names
    excelInput.setStartsWithHeader(false);
    ExcelInputField[] fields = new ExcelInputField[5];
    for (int i = 0; i < 5; i++) {
        fields[i] = new ExcelInputField();
        fields[i].setName("field" + (i + 1));
    }
    excelInput.setField(fields);
    transMeta = TransTestFactory.generateTestTransformation(null, excelInput, checkStepName);
    // Remove the Injector hop, as it's not needed for this transformation
    TransHopMeta injectHop = transMeta.findTransHop(transMeta.findStep(TransTestFactory.INJECTOR_STEPNAME), transMeta.findStep(stepName));
    transMeta.removeTransHop(transMeta.indexOfTransHop(injectHop));
    inputList = new ArrayList<RowMetaAndData>();
    List<RowMetaAndData> result = TransTestFactory.executeTestTransformation(transMeta, TransTestFactory.INJECTOR_STEPNAME, stepName, TransTestFactory.DUMMY_STEPNAME, inputList);
    assertNotNull(result);
    assertEquals(2, result.size());
    assertEquals(5, result.get(0).getRowMeta().size());
    assertEquals(ValueMetaInterface.TYPE_STRING, result.get(0).getValueMeta(0).getType());
    assertEquals(ValueMetaInterface.TYPE_STRING, result.get(0).getValueMeta(1).getType());
    assertEquals(ValueMetaInterface.TYPE_STRING, result.get(0).getValueMeta(2).getType());
    assertEquals(ValueMetaInterface.TYPE_STRING, result.get(0).getValueMeta(3).getType());
    assertEquals(ValueMetaInterface.TYPE_STRING, result.get(0).getValueMeta(4).getType());
    assertEquals("col1", result.get(0).getString(0, "default-value"));
    assertEquals("col2", result.get(0).getString(1, "default-value"));
    assertEquals("col3", result.get(0).getString(2, "default-value"));
    assertEquals("col4", result.get(0).getString(3, "default-value"));
    assertEquals("col5", result.get(0).getString(4, "default-value"));
    assertEquals("data1", result.get(1).getString(0, "default-value"));
    assertEquals("data2", result.get(1).getString(1, "default-value"));
    assertEquals("data3", result.get(1).getString(2, "default-value"));
    assertEquals("data4", result.get(1).getString(3, "default-value"));
    assertEquals("data5", result.get(1).getString(4, "default-value"));
}
Also used : TransMeta(org.pentaho.di.trans.TransMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ExcelInputField(org.pentaho.di.trans.steps.excelinput.ExcelInputField) ExcelInputMeta(org.pentaho.di.trans.steps.excelinput.ExcelInputMeta) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) TransHopMeta(org.pentaho.di.trans.TransHopMeta) File(java.io.File) Test(org.junit.Test)

Aggregations

ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)2 ExcelInputField (org.pentaho.di.trans.steps.excelinput.ExcelInputField)2 File (java.io.File)1 TableItem (org.eclipse.swt.widgets.TableItem)1 Test (org.junit.Test)1 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)1 TransHopMeta (org.pentaho.di.trans.TransHopMeta)1 TransMeta (org.pentaho.di.trans.TransMeta)1 ExcelInputMeta (org.pentaho.di.trans.steps.excelinput.ExcelInputMeta)1