Search in sources :

Example 1 with SalesforceConnection

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

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

the class SalesforceInsertDialog method getFieldNames.

private String[] getFieldNames() throws KettleException {
    SalesforceConnection connection = null;
    String selectedModule = transMeta.environmentSubstitute(wModule.getText());
    try {
        // Define a new Salesforce connection
        connection = getConnection();
        // return fieldsname for the module
        return connection.getFields(selectedModule);
    } catch (Exception e) {
        throw new KettleException("Error getting fields from module [" + selectedModule + "]!", e);
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (Exception e) {
            // Ignore close errors
            }
        }
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) SalesforceConnection(org.pentaho.di.trans.steps.salesforce.SalesforceConnection) KettleException(org.pentaho.di.core.exception.KettleException)

Example 3 with SalesforceConnection

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

the class SalesforceInsertDialog method getConnection.

private SalesforceConnection getConnection() throws KettleException {
    String url = transMeta.environmentSubstitute(wURL.getText());
    // Define a new Salesforce connection
    SalesforceConnection connection = new SalesforceConnection(log, url, transMeta.environmentSubstitute(wUserName.getText()), Utils.resolvePassword(transMeta, wPassword.getText()));
    int realTimeOut = Const.toInt(transMeta.environmentSubstitute(wTimeOut.getText()), 0);
    connection.setTimeOut(realTimeOut);
    // connect to Salesforce
    connection.connect();
    return connection;
}
Also used : SalesforceConnection(org.pentaho.di.trans.steps.salesforce.SalesforceConnection)

Example 4 with SalesforceConnection

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

the class SalesforceInsertDialog method generateMappings.

/**
 * Reads in the fields from the previous steps and from the ONE next step and opens an EnterMappingDialog with this
 * information. After the user did the mapping, those information is put into the Select/Rename table.
 */
private void generateMappings() {
    if (!checkInput()) {
        return;
    }
    // Determine the source and target fields...
    // 
    RowMetaInterface sourceFields;
    RowMetaInterface targetFields = new RowMeta();
    try {
        sourceFields = transMeta.getPrevStepFields(stepMeta);
    } catch (KettleException e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "SalesforceInsertDialog.DoMapping.UnableToFindSourceFields.Title"), BaseMessages.getString(PKG, "SalesforceInsertDialog.DoMapping.UnableToFindSourceFields.Message"), e);
        return;
    }
    try {
        SalesforceConnection connection = getConnection();
        Field[] fields = connection.getObjectFields(transMeta.environmentSubstitute(wModule.getText()));
        String[] fieldNames = connection.getFields(fields);
        FieldType dateType = FieldType.date;
        for (int i = 0; i < fields.length; i++) {
            if (dateType.equals(fields[i].getType())) {
                // Mark date columns as TYPE_DATE to strip time part later
                targetFields.addValueMeta(ValueMetaFactory.createValueMeta(fieldNames[i], ValueMetaInterface.TYPE_DATE));
            } else {
                targetFields.addValueMeta(new ValueMetaNone(fieldNames[i]));
            }
        }
    } catch (Exception e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "SalesforceInsertDialog.DoMapping.UnableToFindTargetFields.Title"), BaseMessages.getString(PKG, "SalesforceInsertDialog.DoMapping.UnableToFindTargetFields.Message"), e);
        return;
    }
    String[] inputNames = new String[sourceFields.size()];
    for (int i = 0; i < sourceFields.size(); i++) {
        ValueMetaInterface value = sourceFields.getValueMeta(i);
        inputNames[i] = value.getName() + EnterMappingDialog.STRING_ORIGIN_SEPARATOR + value.getOrigin() + ")";
    }
    // Create the existing mapping list...
    // 
    List<SourceToTargetMapping> mappings = new ArrayList<SourceToTargetMapping>();
    StringBuffer missingSourceFields = new StringBuffer();
    StringBuffer missingTargetFields = new StringBuffer();
    int nrFields = wReturn.nrNonEmpty();
    for (int i = 0; i < nrFields; i++) {
        TableItem item = wReturn.getNonEmpty(i);
        String source = item.getText(2);
        String target = item.getText(1);
        int sourceIndex = sourceFields.indexOfValue(source);
        if (sourceIndex < 0) {
            missingSourceFields.append(Const.CR + "   " + source + " --> " + target);
        }
        int targetIndex = targetFields.indexOfValue(target);
        if (targetIndex < 0) {
            missingTargetFields.append(Const.CR + "   " + source + " --> " + target);
        }
        if (sourceIndex < 0 || targetIndex < 0) {
            continue;
        }
        SourceToTargetMapping mapping = new SourceToTargetMapping(sourceIndex, targetIndex);
        mappings.add(mapping);
    }
    // 
    if (missingSourceFields.length() > 0 || missingTargetFields.length() > 0) {
        String message = "";
        if (missingSourceFields.length() > 0) {
            message += BaseMessages.getString(PKG, "SalesforceInsertDialog.DoMapping.SomeSourceFieldsNotFound", missingSourceFields.toString()) + Const.CR;
        }
        if (missingTargetFields.length() > 0) {
            message += BaseMessages.getString(PKG, "SalesforceInsertDialog.DoMapping.SomeTargetFieldsNotFound", missingSourceFields.toString()) + Const.CR;
        }
        message += Const.CR;
        message += BaseMessages.getString(PKG, "SalesforceInsertDialog.DoMapping.SomeFieldsNotFoundContinue") + Const.CR;
        MessageDialog.setDefaultImage(GUIResource.getInstance().getImageSpoon());
        boolean goOn = MessageDialog.openConfirm(shell, BaseMessages.getString(PKG, "SalesforceInsertDialog.DoMapping.SomeFieldsNotFoundTitle"), message);
        if (!goOn) {
            return;
        }
    }
    EnterMappingDialog d = new EnterMappingDialog(SalesforceInsertDialog.this.shell, sourceFields.getFieldNames(), targetFields.getFieldNames(), mappings);
    mappings = d.open();
    // 
    if (mappings != null) {
        // Clear and re-populate!
        // 
        wReturn.table.removeAll();
        wReturn.table.setItemCount(mappings.size());
        for (int i = 0; i < mappings.size(); i++) {
            SourceToTargetMapping mapping = mappings.get(i);
            TableItem item = wReturn.table.getItem(i);
            item.setText(2, sourceFields.getValueMeta(mapping.getSourcePosition()).getName());
            item.setText(1, targetFields.getValueMeta(mapping.getTargetPosition()).getName());
        }
        wReturn.setRowNums();
        wReturn.optWidth(true);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RowMeta(org.pentaho.di.core.row.RowMeta) EnterMappingDialog(org.pentaho.di.ui.core.dialog.EnterMappingDialog) TableItem(org.eclipse.swt.widgets.TableItem) ArrayList(java.util.ArrayList) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) SalesforceConnection(org.pentaho.di.trans.steps.salesforce.SalesforceConnection) KettleException(org.pentaho.di.core.exception.KettleException) FieldType(com.sforce.soap.partner.FieldType) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Field(com.sforce.soap.partner.Field) ValueMetaNone(org.pentaho.di.core.row.value.ValueMetaNone) SourceToTargetMapping(org.pentaho.di.core.SourceToTargetMapping)

Example 5 with SalesforceConnection

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

the class SalesforceUpdateDialog method getModulesList.

private void getModulesList() {
    if (!gotModule) {
        SalesforceConnection connection = null;
        try {
            SalesforceUpdateMeta meta = new SalesforceUpdateMeta();
            getInfo(meta);
            String url = transMeta.environmentSubstitute(meta.getTargetURL());
            String selectedField = meta.getModule();
            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, "SalesforceUpdateDialog.ErrorRetrieveModules.DialogTitle"), BaseMessages.getString(PKG, "SalesforceUpdateDialog.ErrorRetrieveData.ErrorRetrieveModules"), e);
            getModulesListError = true;
        } finally {
            if (connection != null) {
                try {
                    connection.close();
                } catch (Exception e) {
                /* Ignore */
                }
            }
        }
    }
}
Also used : ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) SalesforceUpdateMeta(org.pentaho.di.trans.steps.salesforceupdate.SalesforceUpdateMeta) SalesforceConnection(org.pentaho.di.trans.steps.salesforce.SalesforceConnection) KettleException(org.pentaho.di.core.exception.KettleException)

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