use of com.sforce.ws.bind.XmlObject in project teiid by teiid.
the class QueryExecutionImpl method extractValuesFromElement.
// TODO: this looks inefficient as getChild is linear
private List<Object[]> extractValuesFromElement(XmlObject sObject, List<Object[]> result, String sObjectName) throws TranslatorException {
Object[] row = new Object[visitor.getSelectSymbolCount()];
for (int j = 0; j < visitor.getSelectSymbolCount(); j++) {
// must be a column reference as we won't allow an agg over a join
Column element = ((ColumnReference) visitor.getSelectSymbolMetadata(j)).getMetadataObject();
AbstractMetadataRecord table = element.getParent();
if (table.getSourceName().equals(sObjectName)) {
XmlObject child = sObject.getChild(element.getSourceName());
Object cell = getCellDatum(element.getSourceName(), element.getJavaType(), child);
setElementValueInColumn(j, cell, row);
}
}
result.add(row);
return result;
}
use of com.sforce.ws.bind.XmlObject in project teiid by teiid.
the class QueryExecutionImpl method getObjectData.
private List<Object[]> getObjectData(SObject sObject) throws TranslatorException {
Iterator<XmlObject> topFields = sObject.getChildren();
ArrayList<XmlObject> children = new ArrayList<XmlObject>();
while (topFields.hasNext()) {
children.add(topFields.next());
}
logAndMapFields(sObject.getType(), children);
List<Object[]> result = new ArrayList<Object[]>();
if (visitor instanceof JoinQueryVisitor) {
for (int i = 0; i < children.size(); i++) {
XmlObject element = children.get(i);
extactJoinResults(element, result);
}
}
return extractDataFromFields(sObject, children, result);
}
use of com.sforce.ws.bind.XmlObject in project components by Talend.
the class SalesforceWriter method addSObjectField.
private void addSObjectField(XmlObject xmlObject, Schema expected, String fieldName, Object value) {
Object valueToAdd = null;
// Convert stuff here
// For Nillable base64 type field, we retrieve it as UNION type:[bytes,null]
// So need to unwrap it and get its real type
Schema unwrapSchema = AvroUtils.unwrapIfNullable(expected);
switch(unwrapSchema.getType()) {
case BYTES:
if ((value instanceof String) || (value instanceof byte[])) {
byte[] base64Data = null;
if (value instanceof byte[]) {
base64Data = (byte[]) value;
} else {
base64Data = ((String) value).getBytes();
}
if (Base64.isBase64(new String(base64Data))) {
valueToAdd = Base64.decode(base64Data);
break;
}
}
default:
valueToAdd = value;
break;
}
if (valueToAdd instanceof Date) {
xmlObject.setField(fieldName, SalesforceRuntime.convertDateToCalendar((Date) valueToAdd, true));
} else {
Schema.Field se = moduleSchema.getField(fieldName);
if (se != null && valueToAdd instanceof String) {
String datePattern = se.getProp(SchemaConstants.TALEND_COLUMN_PATTERN);
if (datePattern != null && !datePattern.toString().isEmpty()) {
if ("yyyy-MM-dd'T'HH:mm:ss'.000Z'".equals(datePattern)) {
xmlObject.setField(fieldName, calendarCodec.deserialize((String) valueToAdd));
} else if ("yyyy-MM-dd".equals(datePattern)) {
xmlObject.setField(fieldName, dateCodec.deserialize((String) valueToAdd));
} else {
xmlObject.setField(fieldName, new Time((String) valueToAdd));
}
} else {
xmlObject.setField(fieldName, SalesforceAvroRegistry.get().getConverterFromString(se).convertToAvro((String) valueToAdd));
}
} else {
xmlObject.setField(fieldName, valueToAdd);
}
}
}
use of com.sforce.ws.bind.XmlObject 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.ws.bind.XmlObject in project pentaho-kettle by pentaho.
the class SalesforceUpsertTest method testWriteToSalesForcePentahoIntegerValue.
@Test
public void testWriteToSalesForcePentahoIntegerValue() throws Exception {
SalesforceUpsert sfInputStep = new SalesforceUpsert(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
SalesforceUpsertMeta meta = generateSalesforceUpsertMeta(new String[] { ACCOUNT_ID }, new Boolean[] { false });
SalesforceUpsertData data = generateSalesforceUpsertData();
sfInputStep.init(meta, data);
RowMeta rowMeta = new RowMeta();
ValueMetaBase valueMeta = new ValueMetaInteger("IntValue");
rowMeta.addValueMeta(valueMeta);
smh.initStepDataInterface.inputRowMeta = rowMeta;
sfInputStep.writeToSalesForce(new Object[] { 1L });
XmlObject sObject = data.sfBuffer[0].getChild(ACCOUNT_ID);
Assert.assertEquals(sObject.getValue(), 1);
}
Aggregations