use of org.pentaho.di.trans.steps.salesforceinput.SalesforceInputMeta in project pentaho-kettle by pentaho.
the class SalesforceInputDialog method getInfo.
@Override
protected void getInfo(SalesforceStepMeta in) throws KettleException {
SalesforceInputMeta meta = (SalesforceInputMeta) in;
// return value
stepname = wStepname.getText();
// copy info to SalesforceInputMeta class (input)
meta.setTargetURL(Const.NVL(wURL.getText(), SalesforceConnectionUtils.TARGET_DEFAULT_URL));
meta.setUsername(Const.NVL(wUserName.getText(), ""));
meta.setPassword(Const.NVL(wPassword.getText(), ""));
meta.setModule(Const.NVL(wModule.getText(), "Account"));
meta.setCondition(Const.NVL(wCondition.getText(), ""));
meta.setSpecifyQuery(wspecifyQuery.getSelection());
meta.setQuery(Const.NVL(wQuery.getText(), ""));
meta.setCompression(wUseCompression.getSelection());
meta.setQueryAll(wQueryAll.getSelection());
meta.setTimeout(Const.NVL(wTimeOut.getText(), "0"));
meta.setRowLimit(Const.NVL(wLimit.getText(), "0"));
meta.setTargetURLField(Const.NVL(wInclURLField.getText(), ""));
meta.setSQLField(Const.NVL(wInclSQLField.getText(), ""));
meta.setTimestampField(Const.NVL(wInclTimestampField.getText(), ""));
meta.setModuleField(Const.NVL(wInclModuleField.getText(), ""));
meta.setRowNumberField(Const.NVL(wInclRownumField.getText(), ""));
meta.setRecordsFilter(SalesforceConnectionUtils.getRecordsFilterByDesc(wRecordsFilter.getText()));
meta.setIncludeTargetURL(wInclURL.getSelection());
meta.setIncludeSQL(wInclSQL.getSelection());
meta.setIncludeTimestamp(wInclTimestamp.getSelection());
meta.setIncludeModule(wInclModule.getSelection());
meta.setIncludeRowNumber(wInclRownum.getSelection());
meta.setReadFrom(wReadFrom.getText());
meta.setReadTo(wReadTo.getText());
meta.setDeletionDateField(Const.NVL(wInclDeletionDateField.getText(), ""));
meta.setIncludeDeletionDate(wInclDeletionDate.getSelection());
int nrFields = wFields.nrNonEmpty();
meta.allocate(nrFields);
for (int i = 0; i < nrFields; i++) {
SalesforceInputField field = new SalesforceInputField();
TableItem item = wFields.getNonEmpty(i);
field.setName(item.getText(1));
field.setField(item.getText(2));
field.setIdLookup(BaseMessages.getString(PKG, "System.Combo.Yes").equalsIgnoreCase(item.getText(3)));
field.setType(ValueMetaFactory.getIdForValueMeta(item.getText(4)));
field.setFormat(item.getText(5));
field.setLength(Const.toInt(item.getText(6), -1));
field.setPrecision(Const.toInt(item.getText(7), -1));
field.setCurrencySymbol(item.getText(8));
field.setDecimalSymbol(item.getText(9));
field.setGroupSymbol(item.getText(10));
field.setTrimType(SalesforceInputField.getTrimTypeByDesc(item.getText(11)));
field.setRepeated(BaseMessages.getString(PKG, "System.Combo.Yes").equalsIgnoreCase(item.getText(12)));
// CHECKSTYLE:Indentation:OFF
meta.getInputFields()[i] = field;
}
}
use of org.pentaho.di.trans.steps.salesforceinput.SalesforceInputMeta 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.salesforceinput.SalesforceInputMeta in project pentaho-kettle by pentaho.
the class SalesforceInputDialog method preview.
// Preview the data
private void preview() {
try {
SalesforceInputMeta oneMeta = new SalesforceInputMeta();
getInfo(oneMeta);
// check if the path is given
TransMeta previewMeta = TransPreviewFactory.generatePreviewTransformation(transMeta, oneMeta, wStepname.getText());
EnterNumberDialog numberDialog = new EnterNumberDialog(shell, props.getDefaultPreviewSize(), BaseMessages.getString(PKG, "SalesforceInputDialog.NumberRows.DialogTitle"), BaseMessages.getString(PKG, "SalesforceInputDialog.NumberRows.DialogMessage"));
int previewSize = numberDialog.open();
if (previewSize > 0) {
TransPreviewProgressDialog progressDialog = new TransPreviewProgressDialog(shell, previewMeta, new String[] { wStepname.getText() }, new int[] { previewSize });
progressDialog.open();
if (!progressDialog.isCancelled()) {
Trans trans = progressDialog.getTrans();
String loggingText = progressDialog.getLoggingText();
if (trans.getResult() != null && trans.getResult().getNrErrors() > 0) {
EnterTextDialog etd = new EnterTextDialog(shell, BaseMessages.getString(PKG, "System.Dialog.PreviewError.Title"), BaseMessages.getString(PKG, "System.Dialog.PreviewError.Message"), loggingText, true);
etd.setReadOnly();
etd.open();
}
PreviewRowsDialog prd = new PreviewRowsDialog(shell, transMeta, SWT.NONE, wStepname.getText(), progressDialog.getPreviewRowsMeta(wStepname.getText()), progressDialog.getPreviewRows(wStepname.getText()), loggingText);
prd.open();
}
}
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "SalesforceInputDialog.ErrorPreviewingData.DialogTitle"), BaseMessages.getString(PKG, "SalesforceInputDialog.ErrorPreviewingData.DialogMessage"), e);
}
}
use of org.pentaho.di.trans.steps.salesforceinput.SalesforceInputMeta in project pentaho-kettle by pentaho.
the class SalesforceInputDialogTest method setUp.
@Before
public void setUp() {
dialog = spy(new SalesforceInputDialog(mock(Shell.class), new SalesforceInputMeta(), mock(TransMeta.class), "SalesforceInputDialogTest"));
doNothing().when(dialog).addFieldToTable(any(), any(), anyBoolean(), any(), any(), any());
}
use of org.pentaho.di.trans.steps.salesforceinput.SalesforceInputMeta 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