Search in sources :

Example 1 with SalesforceUpsertMeta

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

use of org.pentaho.di.trans.steps.salesforceupsert.SalesforceUpsertMeta 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 3 with SalesforceUpsertMeta

use of org.pentaho.di.trans.steps.salesforceupsert.SalesforceUpsertMeta in project pentaho-kettle by pentaho.

the class SalesforceUpsertDialog method getInfo.

@Override
protected void getInfo(SalesforceStepMeta in) throws KettleException {
    SalesforceUpsertMeta meta = (SalesforceUpsertMeta) in;
    // return value
    stepname = wStepname.getText();
    // copy info to SalesforceUpsertMeta class (input)
    meta.setTargetURL(Const.NVL(wURL.getText(), SalesforceConnectionUtils.TARGET_DEFAULT_URL));
    meta.setUsername(wUserName.getText());
    meta.setPassword(wPassword.getText());
    meta.setModule(Const.NVL(wModule.getText(), "Account"));
    meta.setUpsertField(Const.NVL(wUpsertField.getText(), "Id"));
    meta.setSalesforceIDFieldName(wSalesforceIDFieldName.getText());
    meta.setBatchSize(wBatchSize.getText());
    int nrfields = wReturn.nrNonEmpty();
    meta.allocate(nrfields);
    // CHECKSTYLE:Indentation:OFF
    for (int i = 0; i < nrfields; i++) {
        TableItem item = wReturn.getNonEmpty(i);
        meta.getUpdateLookup()[i] = item.getText(1);
        meta.getUpdateStream()[i] = item.getText(2);
        meta.getUseExternalId()[i] = Boolean.valueOf("Y".equals(item.getText(3)));
    }
    meta.setCompression(wUseCompression.getSelection());
    meta.setTimeout(Const.NVL(wTimeOut.getText(), "0"));
    meta.setRollbackAllChangesOnError(wRollbackAllChangesOnError.getSelection());
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) SalesforceUpsertMeta(org.pentaho.di.trans.steps.salesforceupsert.SalesforceUpsertMeta)

Aggregations

SalesforceUpsertMeta (org.pentaho.di.trans.steps.salesforceupsert.SalesforceUpsertMeta)3 KettleException (org.pentaho.di.core.exception.KettleException)2 SalesforceConnection (org.pentaho.di.trans.steps.salesforce.SalesforceConnection)2 Cursor (org.eclipse.swt.graphics.Cursor)1 TableItem (org.eclipse.swt.widgets.TableItem)1 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)1