use of com.sforce.soap.partner.sobject.SObject in project pentaho-kettle by pentaho.
the class SalesforceConnectionTest method createObject.
private SObject createObject(String fieldName, String value) {
SObject result = new SObject();
result.setName(new QName(Constants.PARTNER_SOBJECT_NS, fieldName));
result.setValue(value);
return result;
}
use of com.sforce.soap.partner.sobject.SObject in project pentaho-kettle by pentaho.
the class SalesforceConnection method getMessageElementForHierarchy.
/**
* Drill down the SObject hierarchy based on the given field hierarchy until either null or the correct MessageElement
* is found
*/
private XmlObject getMessageElementForHierarchy(SObject con, String[] fieldHierarchy) {
final int lastIndex = fieldHierarchy.length - 1;
SObject currentSObject = con;
for (int index = 0; index <= lastIndex; index++) {
for (XmlObject element : getChildren(currentSObject)) {
if (element.getName().getLocalPart().equals(fieldHierarchy[index])) {
if (index == lastIndex) {
return element;
} else {
if (element instanceof SObject) {
// Found the next level, keep going
currentSObject = (SObject) element;
}
break;
}
}
}
}
return null;
}
use of com.sforce.soap.partner.sobject.SObject in project pentaho-kettle by pentaho.
the class SalesforceConnection method query.
public void query(boolean specifyQuery) throws KettleException {
if (getBinding() == null) {
throw new KettleException(BaseMessages.getString(PKG, "SalesforceInput.Exception.CanNotGetBiding"));
}
try {
if (!specifyQuery) {
// check if we can query this Object
DescribeSObjectResult describeSObjectResult = getBinding().describeSObject(getModule());
if (describeSObjectResult == null) {
throw new KettleException(BaseMessages.getString(PKG, "SalesforceInput.ErrorGettingObject"));
}
if (!describeSObjectResult.isQueryable()) {
throw new KettleException(BaseMessages.getString(PKG, "SalesforceInputDialog.ObjectNotQueryable", module));
}
if (this.recordsFilter == SalesforceConnectionUtils.RECORDS_FILTER_UPDATED || this.recordsFilter == SalesforceConnectionUtils.RECORDS_FILTER_DELETED) {
// The object must be replicateable
if (!describeSObjectResult.isReplicateable()) {
throw new KettleException(BaseMessages.getString(PKG, "SalesforceInput.Error.ObjectNotReplicateable", getModule()));
}
}
}
if (getSQL() != null && log.isDetailed()) {
log.logDetailed(BaseMessages.getString(PKG, "SalesforceInput.Log.SQLString") + " : " + getSQL());
}
switch(this.recordsFilter) {
case SalesforceConnectionUtils.RECORDS_FILTER_UPDATED:
// Updated records ...
GetUpdatedResult updatedRecords = getBinding().getUpdated(getModule(), this.startDate, this.endDate);
if (updatedRecords.getIds() != null) {
int nr = updatedRecords.getIds().length;
if (nr > 0) {
String[] ids = updatedRecords.getIds();
// We can pass a maximum of 2000 object IDs
if (nr > SalesforceConnectionUtils.MAX_UPDATED_OBJECTS_IDS) {
this.sObjects = new SObject[nr];
List<String> list = new ArrayList<String>();
int desPos = 0;
for (int i = 0; i < nr; i++) {
list.add(updatedRecords.getIds()[i]);
if (i % SalesforceConnectionUtils.MAX_UPDATED_OBJECTS_IDS == 0 || i == nr - 1) {
SObject[] s = getBinding().retrieve(this.fieldsList, getModule(), list.toArray(new String[list.size()]));
System.arraycopy(s, 0, this.sObjects, desPos, s.length);
desPos += s.length;
s = null;
list = new ArrayList<String>();
}
}
} else {
this.sObjects = getBinding().retrieve(this.fieldsList, getModule(), ids);
}
if (this.sObjects != null) {
this.queryResultSize = this.sObjects.length;
}
}
}
break;
case SalesforceConnectionUtils.RECORDS_FILTER_DELETED:
// Deleted records ...
GetDeletedResult deletedRecordsResult = getBinding().getDeleted(getModule(), this.startDate, this.endDate);
DeletedRecord[] deletedRecords = deletedRecordsResult.getDeletedRecords();
if (log.isDebug()) {
log.logDebug(toString(), BaseMessages.getString(PKG, "SalesforceConnection.DeletedRecordsFound", String.valueOf(deletedRecords == null ? 0 : deletedRecords.length)));
}
if (deletedRecords != null && deletedRecords.length > 0) {
getDeletedList = new HashMap<String, Date>();
for (DeletedRecord dr : deletedRecords) {
getDeletedList.put(dr.getId(), dr.getDeletedDate().getTime());
}
this.qr = getBinding().queryAll(getSQL());
this.sObjects = getQueryResult().getRecords();
if (this.sObjects != null) {
this.queryResultSize = this.sObjects.length;
}
}
break;
default:
// return query result
this.qr = isQueryAll() ? getBinding().queryAll(getSQL()) : getBinding().query(getSQL());
this.sObjects = getQueryResult().getRecords();
this.queryResultSize = getQueryResult().getSize();
break;
}
if (this.sObjects != null) {
this.recordsCount = this.sObjects.length;
}
} catch (Exception e) {
log.logError(Const.getStackTracker(e));
throw new KettleException(BaseMessages.getString(PKG, "SalesforceConnection.Exception.Query"), e);
}
}
use of com.sforce.soap.partner.sobject.SObject in project pentaho-kettle by pentaho.
the class SalesforceConnection method buildJsonQueryResult.
@SuppressWarnings("unchecked")
private String buildJsonQueryResult(QueryResult queryResult) throws KettleException {
JSONArray list = new JSONArray();
for (SObject sobject : queryResult.getRecords()) {
list.add(buildJSONSObject(sobject));
}
StringWriter sw = new StringWriter();
try {
list.writeJSONString(sw);
} catch (IOException e) {
throw new KettleException(e);
}
return sw.toString();
}
use of com.sforce.soap.partner.sobject.SObject in project pentaho-kettle by pentaho.
the class SalesforceInsert method flushBuffers.
private void flushBuffers() throws KettleException {
try {
// create the object(s) by sending the array to the web service
data.saveResult = data.connection.insert(data.sfBuffer);
for (int j = 0; j < data.saveResult.length; j++) {
if (data.saveResult[j].isSuccess()) {
// Row was inserted
String id = data.saveResult[j].getId();
if (log.isDebug()) {
logDebug(BaseMessages.getString(PKG, "SalesforceInsert.RowInserted", 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 = getInputRowMeta().size();
newRow[newIndex++] = id;
}
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "SalesforceInsert.NewRow", newRow[0]));
}
// copy row to output rowset(s);
putRow(data.outputRowMeta, newRow);
incrementLinesOutput();
if (checkFeedback(getLinesInput())) {
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "SalesforceInsert.log.LineRow", getLinesInput()));
}
}
} else {
if (!getStepMeta().isDoingErrorHandling()) {
if (log.isDebug()) {
logDebug(BaseMessages.getString(PKG, "SalesforceInsert.ErrorFound"));
}
// Only show the first error
//
com.sforce.soap.partner.Error err = data.saveResult[j].getErrors()[0];
throw new KettleException(BaseMessages.getString(PKG, "SalesforceInsert.Error.FlushBuffer", new Integer(j), err.getStatusCode(), err.getMessage()));
}
String errorMessage = "";
for (int i = 0; i < data.saveResult[j].getErrors().length; i++) {
// get the next error
com.sforce.soap.partner.Error err = data.saveResult[j].getErrors()[i];
errorMessage += BaseMessages.getString(PKG, "SalesforceInsert.Error.FlushBuffer", new Integer(j), err.getStatusCode(), err.getMessage());
}
// Simply add this row to the error row
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "SalesforceInsert.PassingRowToErrorStep"));
}
putError(getInputRowMeta(), data.outputBuffer[j], 1, errorMessage, null, "SalesforceInsert001");
}
}
// reset the buffers
data.sfBuffer = new SObject[meta.getBatchSizeInt()];
data.outputBuffer = new Object[meta.getBatchSizeInt()][];
data.iBufferPos = 0;
} catch (Exception e) {
if (!getStepMeta().isDoingErrorHandling()) {
throw new KettleException(BaseMessages.getString(PKG, "SalesforceInsert.FailedToInsertObject", e.getMessage()));
}
// 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, "SalesforceInsert002");
}
} finally {
if (data.saveResult != null) {
data.saveResult = null;
}
}
}
Aggregations