use of com.sforce.soap.partner.sobject.SObject in project pentaho-kettle by pentaho.
the class SalesforceUpsert method flushBuffers.
private void flushBuffers() throws KettleException {
try {
if (data.sfBuffer.length > data.iBufferPos) {
SObject[] smallBuffer = new SObject[data.iBufferPos];
System.arraycopy(data.sfBuffer, 0, smallBuffer, 0, data.iBufferPos);
data.sfBuffer = smallBuffer;
}
// upsert the object(s) by sending the array to the web service
data.upsertResult = data.connection.upsert(meta.getUpsertField(), data.sfBuffer);
int nr = data.upsertResult.length;
for (int j = 0; j < nr; j++) {
if (data.upsertResult[j].isSuccess()) {
String id = data.upsertResult[j].getId();
if (data.upsertResult[j].isCreated()) {
incrementLinesOutput();
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "SalesforceUpsert.ObjectCreated", id));
}
} else {
incrementLinesUpdated();
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "SalesforceUpsert.ObjectUpdated", id));
}
}
// write out the row with the SalesForce ID
Object[] newRow = RowDataUtil.resizeArray(data.outputBuffer[j], data.outputRowMeta.size());
if (data.realSalesforceFieldName != null) {
int newIndex = data.inputRowMeta.size();
newRow[newIndex++] = id;
}
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "SalesforceUpsert.NewRow", newRow[0]));
}
// copy row to output rowset(s);
putRow(data.outputRowMeta, newRow);
if (checkFeedback(getLinesInput())) {
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "SalesforceUpsert.log.LineRow", "" + getLinesInput()));
}
}
} else {
if (!getStepMeta().isDoingErrorHandling()) {
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "SalesforceUpsert.ErrorFound"));
}
// Only throw the first error
//
com.sforce.soap.partner.Error err = data.upsertResult[j].getErrors()[0];
throw new KettleException(BaseMessages.getString(PKG, "SalesforceUpsert.Error.FlushBuffer", new Integer(j), err.getStatusCode(), err.getMessage()));
}
String errorMessage = "";
for (int i = 0; i < data.upsertResult[j].getErrors().length; i++) {
// get the next error
com.sforce.soap.partner.Error err = data.upsertResult[j].getErrors()[i];
errorMessage += BaseMessages.getString(PKG, "SalesforceUpsert.Error.FlushBuffer", new Integer(j), err.getStatusCode(), err.getMessage());
}
// Simply add this row to the error row
if (log.isDebug()) {
logDebug(BaseMessages.getString(PKG, "SalesforceUpsert.PassingRowToErrorStep"));
}
putError(getInputRowMeta(), data.outputBuffer[j], 1, errorMessage, null, "SalesforceUpsert001");
}
}
// reset the buffers
data.sfBuffer = new SObject[meta.getBatchSizeInt()];
data.outputBuffer = new Object[meta.getBatchSizeInt()][];
data.iBufferPos = 0;
} catch (Exception e) {
if (!getStepMeta().isDoingErrorHandling()) {
if (e instanceof KettleException) {
// I know, bad form usually. But I didn't want to duplicate the logic with a catch(KettleException). MB
throw (KettleException) e;
} else {
throw new KettleException(BaseMessages.getString(PKG, "SalesforceUpsert.FailedUpsert", e.getMessage()), e);
}
}
// Simply add this row to the error row
if (log.isDebug()) {
logDebug("Passing row to error step");
}
for (int i = 0; i < data.iBufferPos; i++) {
putError(data.inputRowMeta, data.outputBuffer[i], 1, e.getMessage(), null, "SalesforceUpsert002");
}
} finally {
if (data.upsertResult != null) {
data.upsertResult = null;
}
}
}
use of com.sforce.soap.partner.sobject.SObject in project pentaho-kettle by pentaho.
the class SalesforceUpsert method setFieldInSObject.
void setFieldInSObject(SObject sobjPass, XmlObject element) {
Iterator<XmlObject> children = element.getChildren();
String name = element.getName().getLocalPart();
if (!children.hasNext()) {
sobjPass.setSObjectField(name, element.getValue());
} else {
SObject child = new SObject();
child.setName(new QName(name));
while (children.hasNext()) {
setFieldInSObject(child, children.next());
}
sobjPass.setSObjectField(name, child);
}
}
use of com.sforce.soap.partner.sobject.SObject in project pentaho-kettle by pentaho.
the class SalesforceUpsertTest method testSetFieldInSObjectForeignKey.
@Test
public void testSetFieldInSObjectForeignKey() throws Exception {
SalesforceUpsert salesforceUpsert = new SalesforceUpsert(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
SObject sobjPass = new SObject();
XmlObject parentObject = new XmlObject();
String parentParam = "parentParam";
String parentValue = "parentValue";
parentObject.setName(new QName(parentParam));
parentObject.setValue(parentValue);
String child = "child";
String childParam = "childParam";
String childValue = "childValue";
XmlObject childObject = new XmlObject();
childObject.setName(new QName(child));
childObject.setField(childParam, childValue);
salesforceUpsert.setFieldInSObject(sobjPass, parentObject);
salesforceUpsert.setFieldInSObject(sobjPass, childObject);
Assert.assertEquals(parentValue, sobjPass.getField(parentParam));
Assert.assertEquals(childValue, ((SObject) sobjPass.getField(child)).getField(childParam));
}
use of com.sforce.soap.partner.sobject.SObject in project teiid by teiid.
the class SalesforceConnectionImpl method create.
public int create(DataPayload data) throws ResourceException {
SObject toCreate = new SObject();
toCreate.setType(data.getType());
for (DataPayload.Field field : data.getMessageElements()) {
toCreate.addField(field.name, field.value);
}
SObject[] objects = new SObject[] { toCreate };
SaveResult[] result;
try {
result = partnerConnection.create(objects);
} catch (InvalidFieldFault e) {
throw new ResourceException(e);
} catch (InvalidSObjectFault e) {
throw new ResourceException(e);
} catch (InvalidIdFault e) {
throw new ResourceException(e);
} catch (UnexpectedErrorFault e) {
throw new ResourceException(e);
} catch (ConnectionException e) {
throw new ResourceException(e);
}
return analyzeResult(result);
}
use of com.sforce.soap.partner.sobject.SObject in project teiid by teiid.
the class SalesforceConnectionImpl method update.
public int update(List<DataPayload> updateDataList) throws ResourceException {
List<SObject> params = new ArrayList<SObject>(updateDataList.size());
for (int i = 0; i < updateDataList.size(); i++) {
DataPayload data = updateDataList.get(i);
SObject toCreate = new SObject();
toCreate.setType(data.getType());
toCreate.setId(data.getID());
for (DataPayload.Field field : data.getMessageElements()) {
toCreate.addField(field.name, field.value);
}
params.add(i, toCreate);
}
SaveResult[] result;
try {
result = partnerConnection.update(params.toArray(new SObject[params.size()]));
} catch (InvalidFieldFault e) {
throw new ResourceException(e);
} catch (InvalidSObjectFault e) {
throw new ResourceException(e);
} catch (InvalidIdFault e) {
throw new ResourceException(e);
} catch (UnexpectedErrorFault e) {
throw new ResourceException(e);
} catch (ConnectionException e) {
throw new ResourceException(e);
}
return analyzeResult(result);
}
Aggregations