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