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 */
}
}
}
}
}
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();
}
}
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 */
}
}
}
}
}
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));
}
}
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
}
}
}
}
Aggregations