use of com.sforce.ws.bind.XmlObject in project pentaho-kettle by pentaho.
the class SalesforceInputDialogTest method testAddFields_nullIdNotAdded.
@Test
public void testAddFields_nullIdNotAdded() throws Exception {
final Set<String> fields = new LinkedHashSet<>();
XmlObject testObject = createObject("Id", null, ObjectType.XMLOBJECT);
dialog.addFields("", fields, testObject);
assertArrayEquals("Null Id field not added", new String[] {}, fields.toArray());
}
use of com.sforce.ws.bind.XmlObject in project pentaho-kettle by pentaho.
the class SalesforceConnection method fromTemplateElement.
public static XmlObject fromTemplateElement(String name, Object value, boolean setValue) throws SOAPException {
// Use the TEMPLATE org.w3c.dom.Element to create new Message Elements
XmlObject me = new XmlObject();
if (setValue) {
me.setValue(value);
}
me.setName(new QName(name));
return me;
}
use of com.sforce.ws.bind.XmlObject in project pentaho-kettle by pentaho.
the class SalesforceUpsert method writeToSalesForce.
@VisibleForTesting
void writeToSalesForce(Object[] rowData) throws KettleException {
try {
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "SalesforceUpsert.CalledWrite", data.iBufferPos, meta.getBatchSizeInt()));
}
// if there is room in the buffer
if (data.iBufferPos < meta.getBatchSizeInt()) {
// Reserve for empty fields
ArrayList<String> fieldsToNull = new ArrayList<String>();
ArrayList<XmlObject> upsertfields = new ArrayList<>();
// Add fields to update
for (int i = 0; i < data.nrfields; i++) {
ValueMetaInterface valueMeta = data.inputRowMeta.getValueMeta(data.fieldnrs[i]);
Object object = rowData[data.fieldnrs[i]];
if (valueMeta.isNull(object)) {
// The value is null
// We need to keep track of this field
fieldsToNull.add(SalesforceUtils.getFieldToNullName(log, meta.getUpdateLookup()[i], meta.getUseExternalId()[i]));
} else {
Object normalObject = normalizeValue(valueMeta, rowData[data.fieldnrs[i]]);
upsertfields.add(SalesforceConnection.createMessageElement(meta.getUpdateLookup()[i], normalObject, meta.getUseExternalId()[i]));
}
}
// build the SObject
SObject sobjPass = new SObject();
sobjPass.setType(data.connection.getModule());
if (upsertfields.size() > 0) {
for (XmlObject element : upsertfields) {
setFieldInSObject(sobjPass, element);
}
}
if (fieldsToNull.size() > 0) {
// Set Null to fields
sobjPass.setFieldsToNull(fieldsToNull.toArray(new String[fieldsToNull.size()]));
}
// Load the buffer array
data.sfBuffer[data.iBufferPos] = sobjPass;
data.outputBuffer[data.iBufferPos] = rowData;
data.iBufferPos++;
}
if (data.iBufferPos >= meta.getBatchSizeInt()) {
if (log.isDetailed()) {
logDetailed("Calling flush buffer from writeToSalesForce");
}
flushBuffers();
}
} catch (KettleException ke) {
throw ke;
} catch (Exception e) {
throw new KettleException(BaseMessages.getString(PKG, "SalesforceUpsert.FailedInWrite", e.toString()));
}
}
use of com.sforce.ws.bind.XmlObject 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
}
}
}
}
use of com.sforce.ws.bind.XmlObject in project pentaho-kettle by pentaho.
the class SalesforceConnectionTest method testGetRecordValue.
// PDI-15973
@Test
public void testGetRecordValue() throws Exception {
// PDI-15973
SalesforceConnection conn = mock(SalesforceConnection.class, Mockito.CALLS_REAL_METHODS);
SObject sObject = new SObject();
sObject.setName(new QName(Constants.PARTNER_SOBJECT_NS, "sObject"));
SObject testObject = createObject("field", "value");
sObject.addField("field", testObject);
assertEquals("Get value of simple record", "value", conn.getRecordValue(sObject, "field"));
SObject parentObject = createObject("parentField", null);
sObject.addField("parentField", parentObject);
SObject childObject = createObject("subField", "subValue");
parentObject.addField("subField", childObject);
assertEquals("Get value of record with hierarchy", "subValue", conn.getRecordValue(sObject, "parentField.subField"));
XmlObject nullObject = new XmlObject(new QName("nullField"));
sObject.addField("nullField", nullObject);
assertEquals("Get null value when relational query id is null", null, conn.getRecordValue(sObject, "nullField.childField"));
}
Aggregations