use of com.sforce.soap.partner.sobject.SObject 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.soap.partner.sobject.SObject 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"));
}
use of com.sforce.soap.partner.sobject.SObject in project pentaho-kettle by pentaho.
the class PDI_10836_Test method testDateInsert.
@Test
public void testDateInsert() throws Exception {
SalesforceInsert step = new SalesforceInsert(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
SalesforceInsertMeta meta = smh.initStepMetaInterface;
doReturn(UUID.randomUUID().toString()).when(meta).getTargetURL();
doReturn(UUID.randomUUID().toString()).when(meta).getUsername();
doReturn(UUID.randomUUID().toString()).when(meta).getPassword();
doReturn(UUID.randomUUID().toString()).when(meta).getModule();
doReturn(2).when(meta).getBatchSizeInt();
doReturn(new String[] { "Date" }).when(meta).getUpdateLookup();
doReturn(new Boolean[] { false }).when(meta).getUseExternalId();
SalesforceInsertData data = smh.initStepDataInterface;
data.nrfields = 1;
data.fieldnrs = new int[] { 0 };
data.sfBuffer = new SObject[] { null };
data.outputBuffer = new Object[][] { null };
step.init(meta, data);
RowMeta rowMeta = new RowMeta();
ValueMetaInterface valueMeta = new ValueMetaDate("date");
valueMeta.setDateFormatTimeZone(TimeZone.getTimeZone("Europe/Minsk"));
rowMeta.addValueMeta(valueMeta);
smh.initStepDataInterface.inputRowMeta = rowMeta;
Calendar minskTime = Calendar.getInstance(valueMeta.getDateFormatTimeZone());
minskTime.clear();
minskTime.set(2013, Calendar.OCTOBER, 16);
Object[] args = new Object[] { minskTime.getTime() };
Method m = SalesforceInsert.class.getDeclaredMethod("writeToSalesForce", Object[].class);
m.setAccessible(true);
m.invoke(step, new Object[] { args });
DateFormat utc = new SimpleDateFormat("yyyy-MM-dd");
utc.setTimeZone(TimeZone.getTimeZone("UTC"));
XmlObject xmlObject = SalesforceConnection.getChildren(data.sfBuffer[0])[0];
Assert.assertEquals("2013-10-16", utc.format(((Calendar) xmlObject.getValue()).getTime()));
}
use of com.sforce.soap.partner.sobject.SObject in project components by Talend.
the class SalesforceRuntimeTestUtil method createTestData.
public List<String> createTestData() throws ConnectionException {
this.login(SalesforceConnectionProperties.URL);
List<String> ids = new ArrayList<String>();
try {
List<SObject> contacts = new ArrayList<SObject>();
for (Map<String, String> row : testData) {
SObject contact = new SObject();
contact.setType(module);
contact.setField("FirstName", row.get("FirstName"));
contact.setField("LastName", row.get("LastName"));
contact.setField("Phone", row.get("Phone"));
contacts.add(contact);
}
SaveResult[] results = partnerConnection.create(contacts.toArray(new SObject[0]));
for (SaveResult result : results) {
if (result.isSuccess()) {
ids.add(result.getId());
} else {
for (int i = 0; i < result.getErrors().length; i++) {
com.sforce.soap.partner.Error err = result.getErrors()[i];
Assert.fail(err.getMessage());
}
}
}
} catch (ConnectionException ce) {
Assert.fail(ce.getMessage());
}
return ids;
}
use of com.sforce.soap.partner.sobject.SObject in project teiid by teiid.
the class AbstractUpdateExecution method execute.
void execute(Condition criteria, IQueryProvidingVisitor visitor) throws TranslatorException {
// Salesforce limit
int batchSize = 2000;
// Salesforce limit
int updateSize = 200;
String[] Ids = null;
if (visitor.hasOnlyIDCriteria()) {
try {
String Id = ((Comparison) criteria).getRightExpression().toString();
Id = Util.stripQutes(Id);
Ids = new String[] { Id };
result = processIds(Ids, visitor);
} catch (ClassCastException cce) {
throw new RuntimeException(SalesForcePlugin.Util.gs(SalesForcePlugin.Event.TEIID13008));
} catch (ResourceException e) {
throw new TranslatorException(e);
}
} else {
try {
String query = visitor.getQuery();
context.logCommand(query);
QueryResult results = getConnection().query(query, batchSize, Boolean.FALSE);
ArrayList<String> idList = new ArrayList<String>(results.getRecords().length);
while (results != null) {
if (results.getSize() > 0) {
for (int i = 0; i < results.getRecords().length; i++) {
SObject sObject = results.getRecords()[i];
idList.add(sObject.getId());
if (idList.size() == updateSize) {
Ids = idList.toArray(new String[0]);
result += processIds(Ids, visitor);
idList.clear();
}
}
}
if (results.isDone()) {
break;
}
results = connection.queryMore(results.getQueryLocator(), batchSize);
}
if (!idList.isEmpty()) {
Ids = idList.toArray(new String[0]);
result += processIds(Ids, visitor);
}
} catch (ResourceException e) {
throw new TranslatorException(e);
}
}
}
Aggregations