use of com.sforce.soap.partner.sobject.SObject in project components by Talend.
the class SalesforceInputReader method getSchema.
@Override
protected Schema getSchema() throws IOException {
TSalesforceInputProperties inProperties = (TSalesforceInputProperties) properties;
if (querySchema == null) {
querySchema = super.getSchema();
if (inProperties.manualQuery.getValue()) {
if (AvroUtils.isIncludeAllFields(properties.module.main.schema.getValue())) {
SObject currentSObject = getCurrentSObject();
Iterator<XmlObject> children = currentSObject.getChildren();
List<String> columnsName = new ArrayList<>();
int idCount = 0;
while (children.hasNext()) {
String elementName = children.next().getName().getLocalPart();
if ("Id".equals(elementName) && idCount == 0) {
// Ignore the first 'Id' field which always return for query.
idCount++;
continue;
}
if (!columnsName.contains(elementName)) {
columnsName.add(elementName);
}
}
List<Schema.Field> copyFieldList = new ArrayList<>();
for (String columnName : columnsName) {
Schema.Field se = querySchema.getField(columnName);
if (se != null) {
Schema.Field field = new Schema.Field(se.name(), se.schema(), se.doc(), se.defaultVal());
Map<String, Object> fieldProps = se.getObjectProps();
for (String propName : fieldProps.keySet()) {
Object propValue = fieldProps.get(propName);
if (propValue != null) {
field.addProp(propName, propValue);
}
}
copyFieldList.add(field);
}
}
Map<String, Object> objectProps = querySchema.getObjectProps();
querySchema = Schema.createRecord(querySchema.getName(), querySchema.getDoc(), querySchema.getNamespace(), querySchema.isError());
querySchema.getObjectProps().putAll(objectProps);
querySchema.setFields(copyFieldList);
}
}
querySchema.addProp(SalesforceSchemaConstants.COLUMNNAME_DELIMTER, inProperties.columnNameDelimiter.getStringValue());
querySchema.addProp(SalesforceSchemaConstants.VALUE_DELIMITER, inProperties.normalizeDelimiter.getStringValue());
}
return querySchema;
}
use of com.sforce.soap.partner.sobject.SObject in project pentaho-kettle by pentaho.
the class SalesforceInputDialogTest method createObject.
private XmlObject createObject(String fieldName, String value, ObjectType type) {
XmlObject result;
switch(type) {
case SOBJECT:
result = new SObject();
break;
case XMLOBJECT:
result = new XmlObject();
break;
default:
throw new IllegalArgumentException();
}
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 getElements.
// Get SOQL meta data (not a Good way but i don't see any other way !)
// TODO : Go back to this one
// I am sure there is an easy way to return meta for a SOQL result
public XmlObject[] getElements() throws Exception {
// Query first
this.qr = getBinding().query(getSQL());
// and then return records
SObject con = getQueryResult().getRecords()[0];
if (con == null) {
return null;
}
return getChildren(con);
}
use of com.sforce.soap.partner.sobject.SObject in project pentaho-kettle by pentaho.
the class SalesforceConnection method getRecord.
public SalesforceRecordValue getRecord(int recordIndex) {
int index = recordIndex;
SObject con = this.sObjects[index];
SalesforceRecordValue retval = new SalesforceRecordValue(index);
if (con == null) {
return null;
}
if (this.recordsFilter == SalesforceConnectionUtils.RECORDS_FILTER_DELETED) {
// in getDeletedList
if (getDeletedList.containsKey(con.getId())) {
// this record was deleted in the specified range datetime
// We will return it
retval.setRecordValue(con);
retval.setDeletionDate(getDeletedList.get(con.getId()));
} else if (index < getRecordsCount() - 1) {
while (con != null && index < getRecordsCount() - 1 && !getDeletedList.containsKey(con.getId())) {
// still not a record for us !!!
// let's continue ...
index++;
con = this.sObjects[index];
}
// if we are here, it means that
// we found a record to take
// or we have fetched all available records
retval.setRecordIndexChanges(true);
retval.setRecordIndex(index);
if (con != null && getChildren(con)[index] != null && getDeletedList.containsKey(con.getId())) {
retval.setRecordValue(con);
retval.setDeletionDate(getDeletedList.get(con.getId()));
}
}
retval.setAllRecordsProcessed(index >= getRecordsCount() - 1);
} else {
// Case for retrieving record also for updated records
retval.setRecordValue(con);
}
return retval;
}
use of com.sforce.soap.partner.sobject.SObject in project pentaho-kettle by pentaho.
the class SalesforceUpdate method processRow.
@Override
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
// get one row ... This does some basic initialization of the objects, including loading the info coming in
Object[] outputRowData = getRow();
if (outputRowData == null) {
if (data.iBufferPos > 0) {
flushBuffers();
}
setOutputDone();
return false;
}
// If we haven't looked at a row before then do some basic setup.
if (first) {
first = false;
data.sfBuffer = new SObject[meta.getBatchSizeInt()];
data.outputBuffer = new Object[meta.getBatchSizeInt()][];
// get total fields in the grid
data.nrfields = meta.getUpdateLookup().length;
// Check if field list is filled
if (data.nrfields == 0) {
throw new KettleException(BaseMessages.getString(PKG, "SalesforceUpdateDialog.FieldsMissing.DialogMessage"));
}
// Create the output row meta-data
data.inputRowMeta = getInputRowMeta().clone();
data.outputRowMeta = data.inputRowMeta.clone();
meta.getFields(data.outputRowMeta, getStepname(), null, null, this, repository, metaStore);
// Build the mapping of input position to field name
data.fieldnrs = new int[meta.getUpdateStream().length];
for (int i = 0; i < meta.getUpdateStream().length; i++) {
data.fieldnrs[i] = getInputRowMeta().indexOfValue(meta.getUpdateStream()[i]);
if (data.fieldnrs[i] < 0) {
throw new KettleException("Field [" + meta.getUpdateStream()[i] + "] couldn't be found in the input stream!");
}
}
}
try {
writeToSalesForce(outputRowData);
} catch (Exception e) {
throw new KettleStepException(BaseMessages.getString(PKG, "SalesforceUpdate.log.Exception"), e);
}
return true;
}
Aggregations