Search in sources :

Example 46 with RowMeta

use of org.pentaho.di.core.row.RowMeta in project pentaho-kettle by pentaho.

the class SalesforceInsertTest method testWriteToSalesForceForNotNullExtIdField_WithExtIdYES.

@Test
public void testWriteToSalesForceForNotNullExtIdField_WithExtIdYES() throws Exception {
    SalesforceInsert sfInputStep = new SalesforceInsert(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
    SalesforceInsertMeta meta = generateSalesforceInsertMeta(new String[] { ACCOUNT_EXT_ID_ACCOUNT_ID_C_ACCOUNT }, new Boolean[] { true });
    SalesforceInsertData data = generateSalesforceInsertData();
    sfInputStep.init(meta, data);
    RowMeta rowMeta = new RowMeta();
    ValueMetaBase valueMeta = new ValueMetaString("AccExtId");
    rowMeta.addValueMeta(valueMeta);
    smh.initStepDataInterface.inputRowMeta = rowMeta;
    sfInputStep.writeToSalesForce(new Object[] { "tkas88" });
    assertEquals(0, data.sfBuffer[0].getFieldsToNull().length);
    assertEquals(1, SalesforceConnection.getChildren(data.sfBuffer[0]).length);
    assertEquals(Constants.PARTNER_SOBJECT_NS, SalesforceConnection.getChildren(data.sfBuffer[0])[0].getName().getNamespaceURI());
    assertEquals("Account", SalesforceConnection.getChildren(data.sfBuffer[0])[0].getName().getLocalPart());
    assertNull(SalesforceConnection.getChildren(data.sfBuffer[0])[0].getValue());
    assertFalse(SalesforceConnection.getChildren(data.sfBuffer[0])[0].hasChildren());
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaBase(org.pentaho.di.core.row.value.ValueMetaBase) Test(org.junit.Test)

Example 47 with RowMeta

use of org.pentaho.di.core.row.RowMeta in project pentaho-kettle by pentaho.

the class SalesforceInsertTest method testLogMessageInDetailedModeFotWriteToSalesForce.

@Test
public void testLogMessageInDetailedModeFotWriteToSalesForce() throws KettleException {
    SalesforceInsert sfInputStep = new SalesforceInsert(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
    SalesforceInsertMeta meta = generateSalesforceInsertMeta(new String[] { ACCOUNT_ID }, new Boolean[] { false });
    SalesforceInsertData data = generateSalesforceInsertData();
    sfInputStep.init(meta, data);
    when(sfInputStep.getLogChannel().isDetailed()).thenReturn(true);
    RowMeta rowMeta = new RowMeta();
    ValueMetaBase valueMeta = new ValueMetaString("AccNoExtId");
    rowMeta.addValueMeta(valueMeta);
    smh.initStepDataInterface.inputRowMeta = rowMeta;
    verify(sfInputStep.getLogChannel(), never()).logDetailed(anyString());
    sfInputStep.writeToSalesForce(new Object[] { "001i000001c5Nv9AAE" });
    verify(sfInputStep.getLogChannel()).logDetailed("Called writeToSalesForce with 0 out of 2");
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaBase(org.pentaho.di.core.row.value.ValueMetaBase) Test(org.junit.Test)

Example 48 with RowMeta

use of org.pentaho.di.core.row.RowMeta in project pentaho-kettle by pentaho.

the class SalesforceInsertTest method testWriteToSalesForceForNullExtIdField_WithExtIdYES.

@Test
public void testWriteToSalesForceForNullExtIdField_WithExtIdYES() throws Exception {
    SalesforceInsert sfInputStep = new SalesforceInsert(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
    SalesforceInsertMeta meta = generateSalesforceInsertMeta(new String[] { ACCOUNT_EXT_ID_ACCOUNT_ID_C_ACCOUNT }, new Boolean[] { true });
    SalesforceInsertData data = generateSalesforceInsertData();
    sfInputStep.init(meta, data);
    RowMeta rowMeta = new RowMeta();
    ValueMetaBase valueMeta = new ValueMetaString("AccExtId");
    rowMeta.addValueMeta(valueMeta);
    smh.initStepDataInterface.inputRowMeta = rowMeta;
    sfInputStep.writeToSalesForce(new Object[] { null });
    assertEquals(1, data.sfBuffer[0].getFieldsToNull().length);
    assertEquals(ACCOUNT_ID, data.sfBuffer[0].getFieldsToNull()[0]);
    assertNull(SalesforceConnection.getChildren(data.sfBuffer[0]));
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaBase(org.pentaho.di.core.row.value.ValueMetaBase) Test(org.junit.Test)

Example 49 with RowMeta

use of org.pentaho.di.core.row.RowMeta in project pentaho-kettle by pentaho.

the class S3CsvInput method processRow.

@Override
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
    meta = (S3CsvInputMeta) smi;
    data = (S3CsvInputData) sdi;
    if (first) {
        first = false;
        data.outputRowMeta = new RowMeta();
        meta.getFields(data.outputRowMeta, getStepname(), null, null, this);
        if (data.filenames == null) {
            // We're expecting the list of filenames from the previous step(s)...
            // 
            getFilenamesFromPreviousSteps();
        }
        // We only run in parallel if we have at least one file to process
        // AND if we have more than one step copy running...
        // 
        data.parallel = meta.isRunningInParallel() && data.totalNumberOfSteps > 1;
        // The conversion logic for when the lazy conversion is turned of is simple:
        // Pretend it's a lazy conversion object anyway and get the native type during conversion.
        // 
        data.convertRowMeta = data.outputRowMeta.clone();
        for (ValueMetaInterface valueMeta : data.convertRowMeta.getValueMetaList()) {
            valueMeta.setStorageType(ValueMetaInterface.STORAGE_TYPE_BINARY_STRING);
        }
        // 
        if (data.parallel) {
            prepareToRunInParallel();
        }
        // 
        if (!openNextFile()) {
            setOutputDone();
            // nothing to see here, move along...
            return false;
        }
    }
    // 
    if (data.parallel) {
        if (data.totalBytesRead > data.blockToRead) {
            // stop reading
            setOutputDone();
            return false;
        }
    }
    // get row, set busy!
    Object[] outputRowData = readOneRow(true);
    if (outputRowData == null) {
        // no more input to be expected...
        if (openNextFile()) {
            // try again on the next loop...
            return true;
        } else {
            // last file, end here
            setOutputDone();
            return false;
        }
    } else {
        // copy row to possible alternate rowset(s).
        putRow(data.outputRowMeta, outputRowData);
        if (checkFeedback(getLinesInput())) {
            if (log.isBasic()) {
                // $NON-NLS-1$
                logBasic(Messages.getString("S3CsvInput.Log.LineNumber", Long.toString(getLinesInput())));
            }
        }
    }
    return true;
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 50 with RowMeta

use of org.pentaho.di.core.row.RowMeta in project pentaho-kettle by pentaho.

the class S3CsvInputDialog method open.

@Override
public String open() {
    Shell parent = getParent();
    Display display = parent.getDisplay();
    shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MIN | SWT.MAX);
    props.setLook(shell);
    setShellImage(shell, inputMeta);
    ModifyListener lsMod = new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            inputMeta.setChanged();
        }
    };
    changed = inputMeta.hasChanged();
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = Const.FORM_MARGIN;
    formLayout.marginHeight = Const.FORM_MARGIN;
    shell.setLayout(formLayout);
    // $NON-NLS-1$
    shell.setText(Messages.getString("S3CsvInputDialog.Shell.Title"));
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    // Step name line
    // 
    wlStepname = new Label(shell, SWT.RIGHT);
    // $NON-NLS-1$
    wlStepname.setText(Messages.getString("S3CsvInputDialog.Stepname.Label"));
    props.setLook(wlStepname);
    fdlStepname = new FormData();
    fdlStepname.left = new FormAttachment(0, 0);
    fdlStepname.right = new FormAttachment(middle, -margin);
    fdlStepname.top = new FormAttachment(0, margin);
    wlStepname.setLayoutData(fdlStepname);
    wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wStepname);
    wStepname.addModifyListener(lsMod);
    fdStepname = new FormData();
    fdStepname.left = new FormAttachment(middle, 0);
    fdStepname.top = new FormAttachment(0, margin);
    fdStepname.right = new FormAttachment(100, 0);
    wStepname.setLayoutData(fdStepname);
    Control lastControl = wStepname;
    // Access key
    Label wlAccessKey = new Label(shell, SWT.RIGHT);
    // $NON-NLS-1$
    wlAccessKey.setText(Messages.getString("S3CsvInputDialog.AccessKey.Label"));
    props.setLook(wlAccessKey);
    FormData fdlAccessKey = new FormData();
    fdlAccessKey.top = new FormAttachment(lastControl, margin);
    fdlAccessKey.left = new FormAttachment(0, 0);
    fdlAccessKey.right = new FormAttachment(middle, -margin);
    wlAccessKey.setLayoutData(fdlAccessKey);
    wAccessKey = new PasswordTextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wAccessKey);
    wAccessKey.addModifyListener(lsMod);
    FormData fdAccessKey = new FormData();
    fdAccessKey.top = new FormAttachment(lastControl, margin);
    fdAccessKey.left = new FormAttachment(middle, 0);
    fdAccessKey.right = new FormAttachment(100, 0);
    wAccessKey.setLayoutData(fdAccessKey);
    lastControl = wAccessKey;
    // Secret key
    Label wlSecretKey = new Label(shell, SWT.RIGHT);
    // $NON-NLS-1$
    wlSecretKey.setText(Messages.getString("S3CsvInputDialog.SecretKey.Label"));
    props.setLook(wlSecretKey);
    FormData fdlSecretKey = new FormData();
    fdlSecretKey.top = new FormAttachment(lastControl, margin);
    fdlSecretKey.left = new FormAttachment(0, 0);
    fdlSecretKey.right = new FormAttachment(middle, -margin);
    wlSecretKey.setLayoutData(fdlSecretKey);
    wSecretKey = new PasswordTextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wSecretKey);
    wSecretKey.addModifyListener(lsMod);
    FormData fdSecretKey = new FormData();
    fdSecretKey.top = new FormAttachment(lastControl, margin);
    fdSecretKey.left = new FormAttachment(middle, 0);
    fdSecretKey.right = new FormAttachment(100, 0);
    wSecretKey.setLayoutData(fdSecretKey);
    lastControl = wSecretKey;
    // Bucket name
    Label wlBucket = new Label(shell, SWT.RIGHT);
    // $NON-NLS-1$
    wlBucket.setText(Messages.getString("S3CsvInputDialog.Bucket.Label"));
    props.setLook(wlBucket);
    FormData fdlBucket = new FormData();
    fdlBucket.top = new FormAttachment(lastControl, margin);
    fdlBucket.left = new FormAttachment(0, 0);
    fdlBucket.right = new FormAttachment(middle, -margin);
    wlBucket.setLayoutData(fdlBucket);
    wbBucket = new Button(shell, SWT.PUSH | SWT.CENTER);
    props.setLook(wbBucket);
    wbBucket.setText(Messages.getString("S3CsvInputDialog.Bucket.Button"));
    FormData fdbBucket = new FormData();
    fdbBucket.top = new FormAttachment(lastControl, margin);
    fdbBucket.right = new FormAttachment(100, 0);
    wbBucket.setLayoutData(fdbBucket);
    wBucket = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wBucket);
    wBucket.addModifyListener(lsMod);
    FormData fdBucket = new FormData();
    fdBucket.top = new FormAttachment(lastControl, margin);
    fdBucket.left = new FormAttachment(middle, 0);
    fdBucket.right = new FormAttachment(wbBucket, -margin);
    wBucket.setLayoutData(fdBucket);
    lastControl = wBucket;
    // See if the step receives input.  If so, we don't ask for the filename, but for the filename field.
    // 
    isReceivingInput = transMeta.findNrPrevSteps(stepMeta) > 0;
    if (isReceivingInput) {
        RowMetaInterface previousFields;
        try {
            previousFields = transMeta.getPrevStepFields(stepMeta);
        } catch (KettleStepException e) {
            new ErrorDialog(shell, Messages.getString("S3CsvInputDialog.ErrorDialog.UnableToGetInputFields.Title"), Messages.getString("S3CsvInputDialog.ErrorDialog.UnableToGetInputFields.Message"), e);
            previousFields = new RowMeta();
        }
        // The filename field ...
        // 
        Label wlFilename = new Label(shell, SWT.RIGHT);
        // $NON-NLS-1$
        wlFilename.setText(Messages.getString("S3CsvInputDialog.FilenameField.Label"));
        props.setLook(wlFilename);
        FormData fdlFilename = new FormData();
        fdlFilename.top = new FormAttachment(lastControl, margin);
        fdlFilename.left = new FormAttachment(0, 0);
        fdlFilename.right = new FormAttachment(middle, -margin);
        wlFilename.setLayoutData(fdlFilename);
        wFilenameField = new CCombo(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
        wFilenameField.setItems(previousFields.getFieldNames());
        props.setLook(wFilenameField);
        wFilenameField.addModifyListener(lsMod);
        FormData fdFilename = new FormData();
        fdFilename.top = new FormAttachment(lastControl, margin);
        fdFilename.left = new FormAttachment(middle, 0);
        fdFilename.right = new FormAttachment(100, 0);
        wFilenameField.setLayoutData(fdFilename);
        lastControl = wFilenameField;
        // Checkbox to include the filename in the output...
        // 
        Label wlIncludeFilename = new Label(shell, SWT.RIGHT);
        // $NON-NLS-1$
        wlIncludeFilename.setText(Messages.getString("S3CsvInputDialog.IncludeFilenameField.Label"));
        props.setLook(wlIncludeFilename);
        FormData fdlIncludeFilename = new FormData();
        fdlIncludeFilename.top = new FormAttachment(lastControl, margin);
        fdlIncludeFilename.left = new FormAttachment(0, 0);
        fdlIncludeFilename.right = new FormAttachment(middle, -margin);
        wlIncludeFilename.setLayoutData(fdlIncludeFilename);
        wIncludeFilename = new Button(shell, SWT.CHECK);
        props.setLook(wIncludeFilename);
        wFilenameField.addModifyListener(lsMod);
        FormData fdIncludeFilename = new FormData();
        fdIncludeFilename.top = new FormAttachment(lastControl, margin);
        fdIncludeFilename.left = new FormAttachment(middle, 0);
        fdIncludeFilename.right = new FormAttachment(100, 0);
        wIncludeFilename.setLayoutData(fdIncludeFilename);
        lastControl = wIncludeFilename;
    } else {
        // Filename...
        // 
        // The filename browse button
        // 
        wbbFilename = new Button(shell, SWT.PUSH | SWT.CENTER);
        props.setLook(wbbFilename);
        wbbFilename.setText(Messages.getString("System.Button.Browse"));
        wbbFilename.setToolTipText(Messages.getString("System.Tooltip.BrowseForFileOrDirAndAdd"));
        FormData fdbFilename = new FormData();
        fdbFilename.top = new FormAttachment(lastControl, margin);
        fdbFilename.right = new FormAttachment(100, 0);
        wbbFilename.setLayoutData(fdbFilename);
        // The field itself...
        // 
        Label wlFilename = new Label(shell, SWT.RIGHT);
        // $NON-NLS-1$
        wlFilename.setText(Messages.getString("S3CsvInputDialog.Filename.Label"));
        props.setLook(wlFilename);
        FormData fdlFilename = new FormData();
        fdlFilename.top = new FormAttachment(lastControl, margin);
        fdlFilename.left = new FormAttachment(0, 0);
        fdlFilename.right = new FormAttachment(middle, -margin);
        wlFilename.setLayoutData(fdlFilename);
        wFilename = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
        props.setLook(wFilename);
        wFilename.addModifyListener(lsMod);
        FormData fdFilename = new FormData();
        fdFilename.top = new FormAttachment(lastControl, margin);
        fdFilename.left = new FormAttachment(middle, 0);
        fdFilename.right = new FormAttachment(wbbFilename, -margin);
        wFilename.setLayoutData(fdFilename);
        lastControl = wFilename;
    }
    // delimiter
    Label wlDelimiter = new Label(shell, SWT.RIGHT);
    // $NON-NLS-1$
    wlDelimiter.setText(Messages.getString("S3CsvInputDialog.Delimiter.Label"));
    props.setLook(wlDelimiter);
    FormData fdlDelimiter = new FormData();
    fdlDelimiter.top = new FormAttachment(lastControl, margin);
    fdlDelimiter.left = new FormAttachment(0, 0);
    fdlDelimiter.right = new FormAttachment(middle, -margin);
    wlDelimiter.setLayoutData(fdlDelimiter);
    wbDelimiter = new Button(shell, SWT.PUSH | SWT.CENTER);
    props.setLook(wbDelimiter);
    wbDelimiter.setText(Messages.getString("S3CsvInputDialog.Delimiter.Button"));
    FormData fdbDelimiter = new FormData();
    fdbDelimiter.top = new FormAttachment(lastControl, margin);
    fdbDelimiter.right = new FormAttachment(100, 0);
    wbDelimiter.setLayoutData(fdbDelimiter);
    wDelimiter = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wDelimiter);
    wDelimiter.addModifyListener(lsMod);
    FormData fdDelimiter = new FormData();
    fdDelimiter.top = new FormAttachment(lastControl, margin);
    fdDelimiter.left = new FormAttachment(middle, 0);
    fdDelimiter.right = new FormAttachment(wbDelimiter, -margin);
    wDelimiter.setLayoutData(fdDelimiter);
    lastControl = wDelimiter;
    // enclosure
    Label wlEnclosure = new Label(shell, SWT.RIGHT);
    // $NON-NLS-1$
    wlEnclosure.setText(Messages.getString("S3CsvInputDialog.Enclosure.Label"));
    props.setLook(wlEnclosure);
    FormData fdlEnclosure = new FormData();
    fdlEnclosure.top = new FormAttachment(lastControl, margin);
    fdlEnclosure.left = new FormAttachment(0, 0);
    fdlEnclosure.right = new FormAttachment(middle, -margin);
    wlEnclosure.setLayoutData(fdlEnclosure);
    wEnclosure = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wEnclosure);
    wEnclosure.addModifyListener(lsMod);
    FormData fdEnclosure = new FormData();
    fdEnclosure.top = new FormAttachment(lastControl, margin);
    fdEnclosure.left = new FormAttachment(middle, 0);
    fdEnclosure.right = new FormAttachment(100, 0);
    wEnclosure.setLayoutData(fdEnclosure);
    lastControl = wEnclosure;
    // Max line size
    // 
    Label wlMaxLineSize = new Label(shell, SWT.RIGHT);
    // $NON-NLS-1$
    wlMaxLineSize.setText(Messages.getString("S3CsvInputDialog.MaxLineSize.Label"));
    props.setLook(wlMaxLineSize);
    FormData fdlMaxLineSize = new FormData();
    fdlMaxLineSize.top = new FormAttachment(lastControl, margin);
    fdlMaxLineSize.left = new FormAttachment(0, 0);
    fdlMaxLineSize.right = new FormAttachment(middle, -margin);
    wlMaxLineSize.setLayoutData(fdlMaxLineSize);
    wMaxLineSize = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wMaxLineSize);
    wMaxLineSize.addModifyListener(lsMod);
    FormData fdMaxLineSize = new FormData();
    fdMaxLineSize.top = new FormAttachment(lastControl, margin);
    fdMaxLineSize.left = new FormAttachment(middle, 0);
    fdMaxLineSize.right = new FormAttachment(100, 0);
    wMaxLineSize.setLayoutData(fdMaxLineSize);
    lastControl = wMaxLineSize;
    // performingLazyConversion?
    // 
    Label wlLazyConversion = new Label(shell, SWT.RIGHT);
    // $NON-NLS-1$
    wlLazyConversion.setText(Messages.getString("S3CsvInputDialog.LazyConversion.Label"));
    props.setLook(wlLazyConversion);
    FormData fdlLazyConversion = new FormData();
    fdlLazyConversion.top = new FormAttachment(lastControl, margin);
    fdlLazyConversion.left = new FormAttachment(0, 0);
    fdlLazyConversion.right = new FormAttachment(middle, -margin);
    wlLazyConversion.setLayoutData(fdlLazyConversion);
    wLazyConversion = new Button(shell, SWT.CHECK);
    props.setLook(wLazyConversion);
    FormData fdLazyConversion = new FormData();
    fdLazyConversion.top = new FormAttachment(lastControl, margin);
    fdLazyConversion.left = new FormAttachment(middle, 0);
    fdLazyConversion.right = new FormAttachment(100, 0);
    wLazyConversion.setLayoutData(fdLazyConversion);
    lastControl = wLazyConversion;
    // header row?
    // 
    Label wlHeaderPresent = new Label(shell, SWT.RIGHT);
    // $NON-NLS-1$
    wlHeaderPresent.setText(Messages.getString("S3CsvInputDialog.HeaderPresent.Label"));
    props.setLook(wlHeaderPresent);
    FormData fdlHeaderPresent = new FormData();
    fdlHeaderPresent.top = new FormAttachment(lastControl, margin);
    fdlHeaderPresent.left = new FormAttachment(0, 0);
    fdlHeaderPresent.right = new FormAttachment(middle, -margin);
    wlHeaderPresent.setLayoutData(fdlHeaderPresent);
    wHeaderPresent = new Button(shell, SWT.CHECK);
    props.setLook(wHeaderPresent);
    FormData fdHeaderPresent = new FormData();
    fdHeaderPresent.top = new FormAttachment(lastControl, margin);
    fdHeaderPresent.left = new FormAttachment(middle, 0);
    fdHeaderPresent.right = new FormAttachment(100, 0);
    wHeaderPresent.setLayoutData(fdHeaderPresent);
    lastControl = wHeaderPresent;
    // The field itself...
    // 
    Label wlRowNumField = new Label(shell, SWT.RIGHT);
    // $NON-NLS-1$
    wlRowNumField.setText(Messages.getString("S3CsvInputDialog.RowNumField.Label"));
    props.setLook(wlRowNumField);
    FormData fdlRowNumField = new FormData();
    fdlRowNumField.top = new FormAttachment(lastControl, margin);
    fdlRowNumField.left = new FormAttachment(0, 0);
    fdlRowNumField.right = new FormAttachment(middle, -margin);
    wlRowNumField.setLayoutData(fdlRowNumField);
    wRowNumField = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wRowNumField);
    wRowNumField.addModifyListener(lsMod);
    FormData fdRowNumField = new FormData();
    fdRowNumField.top = new FormAttachment(lastControl, margin);
    fdRowNumField.left = new FormAttachment(middle, 0);
    fdRowNumField.right = new FormAttachment(100, 0);
    wRowNumField.setLayoutData(fdRowNumField);
    lastControl = wRowNumField;
    // running in parallel?
    // 
    Label wlRunningInParallel = new Label(shell, SWT.RIGHT);
    // $NON-NLS-1$
    wlRunningInParallel.setText(Messages.getString("S3CsvInputDialog.RunningInParallel.Label"));
    props.setLook(wlRunningInParallel);
    FormData fdlRunningInParallel = new FormData();
    fdlRunningInParallel.top = new FormAttachment(lastControl, margin);
    fdlRunningInParallel.left = new FormAttachment(0, 0);
    fdlRunningInParallel.right = new FormAttachment(middle, -margin);
    wlRunningInParallel.setLayoutData(fdlRunningInParallel);
    wRunningInParallel = new Button(shell, SWT.CHECK);
    props.setLook(wRunningInParallel);
    FormData fdRunningInParallel = new FormData();
    fdRunningInParallel.top = new FormAttachment(lastControl, margin);
    fdRunningInParallel.left = new FormAttachment(middle, 0);
    wRunningInParallel.setLayoutData(fdRunningInParallel);
    lastControl = wRunningInParallel;
    // Some buttons first, so that the dialog scales nicely...
    // 
    wOK = new Button(shell, SWT.PUSH);
    // $NON-NLS-1$
    wOK.setText(Messages.getString("System.Button.OK"));
    wCancel = new Button(shell, SWT.PUSH);
    // $NON-NLS-1$
    wCancel.setText(Messages.getString("System.Button.Cancel"));
    wPreview = new Button(shell, SWT.PUSH);
    // $NON-NLS-1$
    wPreview.setText(Messages.getString("System.Button.Preview"));
    wPreview.setEnabled(!isReceivingInput);
    wGet = new Button(shell, SWT.PUSH);
    // $NON-NLS-1$
    wGet.setText(Messages.getString("System.Button.GetFields"));
    wGet.setEnabled(!isReceivingInput);
    setButtonPositions(new Button[] { wOK, wCancel, wPreview, wGet }, margin, null);
    // Fields
    ColumnInfo[] colinf = new ColumnInfo[] { new ColumnInfo(Messages.getString("S3CsvInputDialog.NameColumn.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(Messages.getString("S3CsvInputDialog.TypeColumn.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, ValueMeta.getTypes(), true), new ColumnInfo(Messages.getString("S3CsvInputDialog.FormatColumn.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, Const.getConversionFormats()), new ColumnInfo(Messages.getString("S3CsvInputDialog.LengthColumn.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(Messages.getString("S3CsvInputDialog.PrecisionColumn.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(Messages.getString("S3CsvInputDialog.CurrencyColumn.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(Messages.getString("S3CsvInputDialog.DecimalColumn.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(Messages.getString("S3CsvInputDialog.GroupColumn.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(Messages.getString("S3CsvInputDialog.TrimTypeColumn.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, ValueMeta.trimTypeDesc) };
    colinf[2].setComboValuesSelectionListener(new ComboValuesSelectionListener() {

        @Override
        public String[] getComboValues(TableItem tableItem, int rowNr, int colNr) {
            String[] comboValues = new String[] {};
            int type = ValueMeta.getType(tableItem.getText(colNr - 1));
            switch(type) {
                case ValueMetaInterface.TYPE_DATE:
                    comboValues = Const.getDateFormats();
                    break;
                case ValueMetaInterface.TYPE_INTEGER:
                case ValueMetaInterface.TYPE_BIGNUMBER:
                case ValueMetaInterface.TYPE_NUMBER:
                    comboValues = Const.getNumberFormats();
                    break;
                default:
                    break;
            }
            return comboValues;
        }
    });
    wFields = new TableView(transMeta, shell, SWT.FULL_SELECTION | SWT.MULTI, colinf, 1, lsMod, props);
    FormData fdFields = new FormData();
    fdFields.top = new FormAttachment(lastControl, margin * 2);
    fdFields.bottom = new FormAttachment(wOK, -margin * 2);
    fdFields.left = new FormAttachment(0, 0);
    fdFields.right = new FormAttachment(100, 0);
    wFields.setLayoutData(fdFields);
    // Add listeners
    lsCancel = new Listener() {

        @Override
        public void handleEvent(Event e) {
            cancel();
        }
    };
    lsOK = new Listener() {

        @Override
        public void handleEvent(Event e) {
            ok();
        }
    };
    lsPreview = new Listener() {

        @Override
        public void handleEvent(Event e) {
            preview();
        }
    };
    lsGet = new Listener() {

        @Override
        public void handleEvent(Event e) {
            getCSV();
        }
    };
    wCancel.addListener(SWT.Selection, lsCancel);
    wOK.addListener(SWT.Selection, lsOK);
    wPreview.addListener(SWT.Selection, lsPreview);
    wGet.addListener(SWT.Selection, lsGet);
    lsDef = new SelectionAdapter() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            ok();
        }
    };
    wStepname.addSelectionListener(lsDef);
    if (wFilename != null) {
        wFilename.addSelectionListener(lsDef);
    }
    if (wFilenameField != null) {
        wFilenameField.addSelectionListener(lsDef);
    }
    wDelimiter.addSelectionListener(lsDef);
    wEnclosure.addSelectionListener(lsDef);
    wMaxLineSize.addSelectionListener(lsDef);
    wRowNumField.addSelectionListener(lsDef);
    // Allow the insertion of tabs as separator...
    wbDelimiter.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent se) {
            Text t = wDelimiter.getTextWidget();
            if (t != null) {
                t.insert("\t");
            }
        }
    });
    wbBucket.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            // 
            try {
                S3CsvInputMeta meta = new S3CsvInputMeta();
                getInfo(meta);
                S3ObjectsProvider s3ObjProvider = new S3ObjectsProvider(meta.getS3Service(transMeta));
                EnterSelectionDialog dialog = new EnterSelectionDialog(shell, s3ObjProvider.getBucketsNames(), Messages.getString("S3CsvInputDialog.Exception.SelectBucket.Title"), Messages.getString("S3CsvInputDialog.Exception.SelectBucket.Message"));
                dialog.setMulti(false);
                String bucketname = dialog.open();
                if (bucketname != null) {
                    wBucket.setText(bucketname);
                }
            } catch (Exception e) {
                new ErrorDialog(shell, Messages.getString("S3CsvInputDialog.Exception.UnableToGetBuckets.Title"), Messages.getString("S3CsvInputDialog.Exception.UnableToGetBuckets.Message"), e);
            }
        }
    });
    if (wbbFilename != null) {
        // Listen to the browse button next to the file name
        wbbFilename.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent event) {
                try {
                    S3CsvInputMeta meta = new S3CsvInputMeta();
                    getInfo(meta);
                    S3ObjectsProvider s3ObjProvider = new S3ObjectsProvider(meta.getS3Service(transMeta));
                    String[] objectnames = s3ObjProvider.getS3ObjectsNames(meta.getBucket());
                    EnterSelectionDialog dialog = new EnterSelectionDialog(shell, objectnames, Messages.getString("S3CsvInputDialog.Exception.SelectObject.Title"), Messages.getString("S3CsvInputDialog.Exception.SelectObject.Message"));
                    dialog.setMulti(false);
                    if (!Utils.isEmpty(wFilename.getText())) {
                        int index = Const.indexOfString(wFilename.getText(), objectnames);
                        if (index >= 0) {
                            dialog.setSelectedNrs(new int[] { index });
                        }
                    }
                    String objectname = dialog.open();
                    if (objectname != null) {
                        wFilename.setText(objectname);
                    }
                } catch (Exception e) {
                    new ErrorDialog(shell, Messages.getString("S3CsvInputDialog.Exception.UnableToGetFiles.Title"), Messages.getString("S3CsvInputDialog.Exception.UnableToGetFiles.Message"), e);
                }
            }
        });
    }
    // Detect X or ALT-F4 or something that kills this window...
    shell.addShellListener(new ShellAdapter() {

        @Override
        public void shellClosed(ShellEvent e) {
            cancel();
        }
    });
    // Set the shell size, based upon previous time...
    setSize();
    getData();
    inputMeta.setChanged(changed);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return stepname;
}
Also used : KettleStepException(org.pentaho.di.core.exception.KettleStepException) Listener(org.eclipse.swt.widgets.Listener) ComboValuesSelectionListener(org.pentaho.di.ui.core.widget.ComboValuesSelectionListener) ModifyListener(org.eclipse.swt.events.ModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) RowMeta(org.pentaho.di.core.row.RowMeta) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) ColumnInfo(org.pentaho.di.ui.core.widget.ColumnInfo) ShellEvent(org.eclipse.swt.events.ShellEvent) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) Shell(org.eclipse.swt.widgets.Shell) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FormAttachment(org.eclipse.swt.layout.FormAttachment) EnterSelectionDialog(org.pentaho.di.ui.core.dialog.EnterSelectionDialog) TableView(org.pentaho.di.ui.core.widget.TableView) FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) ShellAdapter(org.eclipse.swt.events.ShellAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) Text(org.eclipse.swt.widgets.Text) KettleStepException(org.pentaho.di.core.exception.KettleStepException) IOException(java.io.IOException) TextVar(org.pentaho.di.ui.core.widget.TextVar) PasswordTextVar(org.pentaho.di.ui.core.widget.PasswordTextVar) PasswordTextVar(org.pentaho.di.ui.core.widget.PasswordTextVar) ComboValuesSelectionListener(org.pentaho.di.ui.core.widget.ComboValuesSelectionListener) CCombo(org.eclipse.swt.custom.CCombo) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Event(org.eclipse.swt.widgets.Event) ShellEvent(org.eclipse.swt.events.ShellEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Display(org.eclipse.swt.widgets.Display)

Aggregations

RowMeta (org.pentaho.di.core.row.RowMeta)540 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)280 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)249 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)209 Test (org.junit.Test)174 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)135 KettleException (org.pentaho.di.core.exception.KettleException)112 ArrayList (java.util.ArrayList)68 KettleStepException (org.pentaho.di.core.exception.KettleStepException)56 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)52 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)44 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)41 RowSet (org.pentaho.di.core.RowSet)34 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)27 ValueMetaBase (org.pentaho.di.core.row.value.ValueMetaBase)26 SQLException (java.sql.SQLException)24 FileObject (org.apache.commons.vfs2.FileObject)24 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)23 StepMeta (org.pentaho.di.trans.step.StepMeta)23 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)23