Search in sources :

Example 1 with SalesforceInputMeta

use of org.pentaho.di.trans.steps.salesforceinput.SalesforceInputMeta in project pentaho-kettle by pentaho.

the class SalesforceInputDialog method getInfo.

@Override
protected void getInfo(SalesforceStepMeta in) throws KettleException {
    SalesforceInputMeta meta = (SalesforceInputMeta) in;
    // return value
    stepname = wStepname.getText();
    // copy info to SalesforceInputMeta class (input)
    meta.setTargetURL(Const.NVL(wURL.getText(), SalesforceConnectionUtils.TARGET_DEFAULT_URL));
    meta.setUsername(Const.NVL(wUserName.getText(), ""));
    meta.setPassword(Const.NVL(wPassword.getText(), ""));
    meta.setModule(Const.NVL(wModule.getText(), "Account"));
    meta.setCondition(Const.NVL(wCondition.getText(), ""));
    meta.setSpecifyQuery(wspecifyQuery.getSelection());
    meta.setQuery(Const.NVL(wQuery.getText(), ""));
    meta.setCompression(wUseCompression.getSelection());
    meta.setQueryAll(wQueryAll.getSelection());
    meta.setTimeout(Const.NVL(wTimeOut.getText(), "0"));
    meta.setRowLimit(Const.NVL(wLimit.getText(), "0"));
    meta.setTargetURLField(Const.NVL(wInclURLField.getText(), ""));
    meta.setSQLField(Const.NVL(wInclSQLField.getText(), ""));
    meta.setTimestampField(Const.NVL(wInclTimestampField.getText(), ""));
    meta.setModuleField(Const.NVL(wInclModuleField.getText(), ""));
    meta.setRowNumberField(Const.NVL(wInclRownumField.getText(), ""));
    meta.setRecordsFilter(SalesforceConnectionUtils.getRecordsFilterByDesc(wRecordsFilter.getText()));
    meta.setIncludeTargetURL(wInclURL.getSelection());
    meta.setIncludeSQL(wInclSQL.getSelection());
    meta.setIncludeTimestamp(wInclTimestamp.getSelection());
    meta.setIncludeModule(wInclModule.getSelection());
    meta.setIncludeRowNumber(wInclRownum.getSelection());
    meta.setReadFrom(wReadFrom.getText());
    meta.setReadTo(wReadTo.getText());
    meta.setDeletionDateField(Const.NVL(wInclDeletionDateField.getText(), ""));
    meta.setIncludeDeletionDate(wInclDeletionDate.getSelection());
    int nrFields = wFields.nrNonEmpty();
    meta.allocate(nrFields);
    for (int i = 0; i < nrFields; i++) {
        SalesforceInputField field = new SalesforceInputField();
        TableItem item = wFields.getNonEmpty(i);
        field.setName(item.getText(1));
        field.setField(item.getText(2));
        field.setIdLookup(BaseMessages.getString(PKG, "System.Combo.Yes").equalsIgnoreCase(item.getText(3)));
        field.setType(ValueMetaFactory.getIdForValueMeta(item.getText(4)));
        field.setFormat(item.getText(5));
        field.setLength(Const.toInt(item.getText(6), -1));
        field.setPrecision(Const.toInt(item.getText(7), -1));
        field.setCurrencySymbol(item.getText(8));
        field.setDecimalSymbol(item.getText(9));
        field.setGroupSymbol(item.getText(10));
        field.setTrimType(SalesforceInputField.getTrimTypeByDesc(item.getText(11)));
        field.setRepeated(BaseMessages.getString(PKG, "System.Combo.Yes").equalsIgnoreCase(item.getText(12)));
        // CHECKSTYLE:Indentation:OFF
        meta.getInputFields()[i] = field;
    }
}
Also used : SalesforceInputField(org.pentaho.di.trans.steps.salesforceinput.SalesforceInputField) TableItem(org.eclipse.swt.widgets.TableItem) SalesforceInputMeta(org.pentaho.di.trans.steps.salesforceinput.SalesforceInputMeta)

Example 2 with SalesforceInputMeta

use of org.pentaho.di.trans.steps.salesforceinput.SalesforceInputMeta in project pentaho-kettle by pentaho.

the class SalesforceInputDialog method getModulesList.

private void getModulesList() {
    if (!gotModule) {
        SalesforceConnection connection = null;
        String selectedField = wModule.getText();
        wModule.removeAll();
        try {
            SalesforceInputMeta meta = new SalesforceInputMeta();
            getInfo(meta);
            String url = transMeta.environmentSubstitute(meta.getTargetURL());
            // Define a new Salesforce connection
            connection = new SalesforceConnection(log, url, transMeta.environmentSubstitute(meta.getUsername()), Utils.resolvePassword(transMeta, meta.getPassword()));
            // connect to Salesforce
            connection.connect();
            // retrieve modules list
            String[] modules = connection.getAllAvailableObjects(true);
            if (modules != null && modules.length > 0) {
                // populate Combo
                wModule.setItems(modules);
            }
            gotModule = true;
            getModulesListError = false;
        } catch (Exception e) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "SalesforceInputDialog.ErrorRetrieveModules.DialogTitle"), BaseMessages.getString(PKG, "SalesforceInputDialog.ErrorRetrieveData.ErrorRetrieveModules"), e);
            getModulesListError = true;
        } finally {
            if (!Utils.isEmpty(selectedField)) {
                wModule.setText(selectedField);
            }
            if (connection != null) {
                try {
                    connection.close();
                } catch (Exception e) {
                /* Ignore */
                }
            }
        }
    }
}
Also used : ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) SalesforceConnection(org.pentaho.di.trans.steps.salesforce.SalesforceConnection) SalesforceInputMeta(org.pentaho.di.trans.steps.salesforceinput.SalesforceInputMeta) KettleException(org.pentaho.di.core.exception.KettleException)

Example 3 with SalesforceInputMeta

use of org.pentaho.di.trans.steps.salesforceinput.SalesforceInputMeta in project pentaho-kettle by pentaho.

the class SalesforceInputDialog method preview.

// Preview the data
private void preview() {
    try {
        SalesforceInputMeta oneMeta = new SalesforceInputMeta();
        getInfo(oneMeta);
        // check if the path is given
        TransMeta previewMeta = TransPreviewFactory.generatePreviewTransformation(transMeta, oneMeta, wStepname.getText());
        EnterNumberDialog numberDialog = new EnterNumberDialog(shell, props.getDefaultPreviewSize(), BaseMessages.getString(PKG, "SalesforceInputDialog.NumberRows.DialogTitle"), BaseMessages.getString(PKG, "SalesforceInputDialog.NumberRows.DialogMessage"));
        int previewSize = numberDialog.open();
        if (previewSize > 0) {
            TransPreviewProgressDialog progressDialog = new TransPreviewProgressDialog(shell, previewMeta, new String[] { wStepname.getText() }, new int[] { previewSize });
            progressDialog.open();
            if (!progressDialog.isCancelled()) {
                Trans trans = progressDialog.getTrans();
                String loggingText = progressDialog.getLoggingText();
                if (trans.getResult() != null && trans.getResult().getNrErrors() > 0) {
                    EnterTextDialog etd = new EnterTextDialog(shell, BaseMessages.getString(PKG, "System.Dialog.PreviewError.Title"), BaseMessages.getString(PKG, "System.Dialog.PreviewError.Message"), loggingText, true);
                    etd.setReadOnly();
                    etd.open();
                }
                PreviewRowsDialog prd = new PreviewRowsDialog(shell, transMeta, SWT.NONE, wStepname.getText(), progressDialog.getPreviewRowsMeta(wStepname.getText()), progressDialog.getPreviewRows(wStepname.getText()), loggingText);
                prd.open();
            }
        }
    } catch (KettleException e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "SalesforceInputDialog.ErrorPreviewingData.DialogTitle"), BaseMessages.getString(PKG, "SalesforceInputDialog.ErrorPreviewingData.DialogMessage"), e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) TransPreviewProgressDialog(org.pentaho.di.ui.trans.dialog.TransPreviewProgressDialog) TransMeta(org.pentaho.di.trans.TransMeta) EnterTextDialog(org.pentaho.di.ui.core.dialog.EnterTextDialog) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) PreviewRowsDialog(org.pentaho.di.ui.core.dialog.PreviewRowsDialog) SalesforceInputMeta(org.pentaho.di.trans.steps.salesforceinput.SalesforceInputMeta) EnterNumberDialog(org.pentaho.di.ui.core.dialog.EnterNumberDialog) Trans(org.pentaho.di.trans.Trans)

Example 4 with SalesforceInputMeta

use of org.pentaho.di.trans.steps.salesforceinput.SalesforceInputMeta in project pentaho-kettle by pentaho.

the class SalesforceInputDialogTest method setUp.

@Before
public void setUp() {
    dialog = spy(new SalesforceInputDialog(mock(Shell.class), new SalesforceInputMeta(), mock(TransMeta.class), "SalesforceInputDialogTest"));
    doNothing().when(dialog).addFieldToTable(any(), any(), anyBoolean(), any(), any(), any());
}
Also used : Shell(org.eclipse.swt.widgets.Shell) TransMeta(org.pentaho.di.trans.TransMeta) SalesforceInputMeta(org.pentaho.di.trans.steps.salesforceinput.SalesforceInputMeta) Before(org.junit.Before)

Example 5 with SalesforceInputMeta

use of org.pentaho.di.trans.steps.salesforceinput.SalesforceInputMeta in project pentaho-kettle by pentaho.

the class SalesforceInputDialog method get.

private void get() {
    SalesforceConnection connection = null;
    try {
        SalesforceInputMeta meta = new SalesforceInputMeta();
        getInfo(meta);
        // Clear Fields Grid
        wFields.removeAll();
        // get real values
        String realModule = transMeta.environmentSubstitute(meta.getModule());
        String realURL = transMeta.environmentSubstitute(meta.getTargetURL());
        String realUsername = transMeta.environmentSubstitute(meta.getUsername());
        String realPassword = Utils.resolvePassword(transMeta, meta.getPassword());
        int realTimeOut = Const.toInt(transMeta.environmentSubstitute(meta.getTimeout()), 0);
        connection = new SalesforceConnection(log, realURL, realUsername, realPassword);
        connection.setTimeOut(realTimeOut);
        String[] fieldsName = null;
        if (meta.isSpecifyQuery()) {
            // Free hand SOQL
            String realQuery = transMeta.environmentSubstitute(meta.getQuery());
            connection.setSQL(realQuery);
            connection.connect();
            // We are connected, so let's query
            XmlObject[] fields = connection.getElements();
            int nrFields = fields.length;
            Set<String> fieldNames = new HashSet<>();
            for (int i = 0; i < nrFields; i++) {
                addFields("", fieldNames, fields[i]);
            }
            fieldsName = fieldNames.toArray(new String[fieldNames.size()]);
        } else {
            connection.connect();
            Field[] fields = connection.getObjectFields(realModule);
            fieldsName = new String[fields.length];
            for (int i = 0; i < fields.length; i++) {
                Field field = fields[i];
                fieldsName[i] = field.getName();
                addField(field);
            }
        }
        if (fieldsName != null) {
            colinf[1].setComboValues(fieldsName);
        }
        wFields.removeEmptyRows();
        wFields.setRowNums();
        wFields.optWidth(true);
    } catch (KettleException e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "SalesforceInputMeta.ErrorRetrieveData.DialogTitle"), BaseMessages.getString(PKG, "SalesforceInputMeta.ErrorRetrieveData.DialogMessage"), e);
    } catch (Exception e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "SalesforceInputMeta.ErrorRetrieveData.DialogTitle"), BaseMessages.getString(PKG, "SalesforceInputMeta.ErrorRetrieveData.DialogMessage"), e);
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (Exception e) {
            // Ignore errors
            }
        }
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) SalesforceConnection(org.pentaho.di.trans.steps.salesforce.SalesforceConnection) KettleException(org.pentaho.di.core.exception.KettleException) Field(com.sforce.soap.partner.Field) SalesforceInputField(org.pentaho.di.trans.steps.salesforceinput.SalesforceInputField) XmlObject(com.sforce.ws.bind.XmlObject) SalesforceInputMeta(org.pentaho.di.trans.steps.salesforceinput.SalesforceInputMeta) HashSet(java.util.HashSet)

Aggregations

SalesforceInputMeta (org.pentaho.di.trans.steps.salesforceinput.SalesforceInputMeta)5 KettleException (org.pentaho.di.core.exception.KettleException)3 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)3 TransMeta (org.pentaho.di.trans.TransMeta)2 SalesforceConnection (org.pentaho.di.trans.steps.salesforce.SalesforceConnection)2 SalesforceInputField (org.pentaho.di.trans.steps.salesforceinput.SalesforceInputField)2 Field (com.sforce.soap.partner.Field)1 XmlObject (com.sforce.ws.bind.XmlObject)1 HashSet (java.util.HashSet)1 Shell (org.eclipse.swt.widgets.Shell)1 TableItem (org.eclipse.swt.widgets.TableItem)1 Before (org.junit.Before)1 Trans (org.pentaho.di.trans.Trans)1 EnterNumberDialog (org.pentaho.di.ui.core.dialog.EnterNumberDialog)1 EnterTextDialog (org.pentaho.di.ui.core.dialog.EnterTextDialog)1 PreviewRowsDialog (org.pentaho.di.ui.core.dialog.PreviewRowsDialog)1 TransPreviewProgressDialog (org.pentaho.di.ui.trans.dialog.TransPreviewProgressDialog)1