Search in sources :

Example 6 with SalesforceConnection

use of org.pentaho.di.trans.steps.salesforce.SalesforceConnection in project pentaho-kettle by pentaho.

the class SalesforceUpsertDialog method getModulesList.

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

Example 7 with SalesforceConnection

use of org.pentaho.di.trans.steps.salesforce.SalesforceConnection in project pentaho-kettle by pentaho.

the class SalesforceUpsertDialog method getModuleFields.

private String[] getModuleFields() throws KettleException {
    if (moduleFields != null) {
        return moduleFields;
    } else if (skipFetchModules() || Utils.isEmpty(wModule.getText())) {
        getModulesListError = false;
        return new String[0];
    }
    getModulesListError = true;
    SalesforceUpsertMeta meta = new SalesforceUpsertMeta();
    getInfo(meta);
    String url = transMeta.environmentSubstitute(meta.getTargetURL());
    String selectedModule = transMeta.environmentSubstitute(meta.getModule());
    // Define a new Salesforce connection
    SalesforceConnection connection = new SalesforceConnection(log, url, transMeta.environmentSubstitute(meta.getUsername()), Utils.resolvePassword(transMeta, meta.getPassword()));
    int realTimeOut = Const.toInt(transMeta.environmentSubstitute(meta.getTimeout()), 0);
    connection.setTimeOut(realTimeOut);
    Cursor busy = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT);
    try {
        shell.setCursor(busy);
        // connect to Salesforce
        connection.connect();
        moduleFields = connection.getFields(selectedModule, excludeNonUpdatableFields);
        getModulesListError = false;
        return moduleFields;
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (Exception e) {
            /* Ignore */
            }
        }
        shell.setCursor(null);
        busy.dispose();
    }
}
Also used : SalesforceUpsertMeta(org.pentaho.di.trans.steps.salesforceupsert.SalesforceUpsertMeta) SalesforceConnection(org.pentaho.di.trans.steps.salesforce.SalesforceConnection) Cursor(org.eclipse.swt.graphics.Cursor) KettleException(org.pentaho.di.core.exception.KettleException)

Example 8 with SalesforceConnection

use of org.pentaho.di.trans.steps.salesforce.SalesforceConnection in project pentaho-kettle by pentaho.

the class SalesforceDeleteDialog method getModulesList.

private void getModulesList() {
    if (!gotModule) {
        SalesforceConnection connection = null;
        try {
            SalesforceDeleteMeta meta = new SalesforceDeleteMeta();
            getInfo(meta);
            String url = transMeta.environmentSubstitute(meta.getTargetURL());
            String selectedField = wModule.getText();
            wModule.removeAll();
            // Define a new Salesforce connection
            connection = new SalesforceConnection(log, url, transMeta.environmentSubstitute(meta.getUsername()), Utils.resolvePassword(transMeta, meta.getPassword()));
            int realTimeOut = Const.toInt(transMeta.environmentSubstitute(meta.getTimeout()), 0);
            connection.setTimeOut(realTimeOut);
            // connect to Salesforce
            connection.connect();
            // return
            wModule.setItems(connection.getAllAvailableObjects(false));
            if (!Utils.isEmpty(selectedField)) {
                wModule.setText(selectedField);
            }
            gotModule = true;
            getModulesListError = false;
        } catch (Exception e) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "SalesforceDeleteDialog.ErrorRetrieveModules.DialogTitle"), BaseMessages.getString(PKG, "SalesforceDeleteDialog.ErrorRetrieveData.ErrorRetrieveModules"), e);
            getModulesListError = true;
        } finally {
            if (connection != null) {
                try {
                    connection.close();
                } catch (Exception e) {
                /* Ignore */
                }
            }
        }
    }
}
Also used : SalesforceDeleteMeta(org.pentaho.di.trans.steps.salesforcedelete.SalesforceDeleteMeta) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) SalesforceConnection(org.pentaho.di.trans.steps.salesforce.SalesforceConnection) KettleException(org.pentaho.di.core.exception.KettleException)

Example 9 with SalesforceConnection

use of org.pentaho.di.trans.steps.salesforce.SalesforceConnection in project pentaho-kettle by pentaho.

the class SalesforceStepDialog method test.

protected void test() {
    boolean successConnection = true;
    String msgError = null;
    SalesforceConnection connection = null;
    String realUsername = null;
    try {
        SalesforceStepMeta meta = META_CLASS.newInstance();
        getInfo(meta);
        // get real values
        String realURL = transMeta.environmentSubstitute(meta.getTargetURL());
        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);
        connection.connect();
    } catch (Exception e) {
        successConnection = false;
        msgError = e.getMessage();
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (Exception e) {
            /* Ignore */
            }
        }
    }
    if (successConnection) {
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
        mb.setMessage(BaseMessages.getString(PKG, "SalesforceDialog.Connected.OK", realUsername) + Const.CR);
        mb.setText(BaseMessages.getString(PKG, "SalesforceDialog.Connected.Title.Ok"));
        mb.open();
    } else {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "SalesforceDialog.Connected.Title.Error"), BaseMessages.getString(PKG, "SalesforceDialog.Connected.NOK", realUsername), new Exception(msgError));
    }
}
Also used : ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) SalesforceStepMeta(org.pentaho.di.trans.steps.salesforce.SalesforceStepMeta) SalesforceConnection(org.pentaho.di.trans.steps.salesforce.SalesforceConnection) KettleException(org.pentaho.di.core.exception.KettleException) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 10 with SalesforceConnection

use of org.pentaho.di.trans.steps.salesforce.SalesforceConnection 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

SalesforceConnection (org.pentaho.di.trans.steps.salesforce.SalesforceConnection)12 KettleException (org.pentaho.di.core.exception.KettleException)11 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)8 Field (com.sforce.soap.partner.Field)2 SalesforceInputMeta (org.pentaho.di.trans.steps.salesforceinput.SalesforceInputMeta)2 SalesforceUpdateMeta (org.pentaho.di.trans.steps.salesforceupdate.SalesforceUpdateMeta)2 SalesforceUpsertMeta (org.pentaho.di.trans.steps.salesforceupsert.SalesforceUpsertMeta)2 FieldType (com.sforce.soap.partner.FieldType)1 XmlObject (com.sforce.ws.bind.XmlObject)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Cursor (org.eclipse.swt.graphics.Cursor)1 MessageBox (org.eclipse.swt.widgets.MessageBox)1 TableItem (org.eclipse.swt.widgets.TableItem)1 SourceToTargetMapping (org.pentaho.di.core.SourceToTargetMapping)1 RowMeta (org.pentaho.di.core.row.RowMeta)1 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)1 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)1 ValueMetaNone (org.pentaho.di.core.row.value.ValueMetaNone)1 SalesforceStepMeta (org.pentaho.di.trans.steps.salesforce.SalesforceStepMeta)1