Search in sources :

Example 11 with XmlObject

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;
}
Also used : Column(org.teiid.metadata.Column) XmlObject(com.sforce.ws.bind.XmlObject) SObject(com.sforce.soap.partner.sobject.SObject) XmlObject(com.sforce.ws.bind.XmlObject) AbstractMetadataRecord(org.teiid.metadata.AbstractMetadataRecord)

Example 12 with XmlObject

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);
}
Also used : JoinQueryVisitor(org.teiid.translator.salesforce.execution.visitors.JoinQueryVisitor) XmlObject(com.sforce.ws.bind.XmlObject) XmlObject(com.sforce.ws.bind.XmlObject) SObject(com.sforce.soap.partner.sobject.SObject)

Example 13 with XmlObject

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);
        }
    }
}
Also used : Schema(org.apache.avro.Schema) XmlObject(com.sforce.ws.bind.XmlObject) SObject(com.sforce.soap.partner.sobject.SObject) Time(com.sforce.ws.types.Time) Date(java.util.Date)

Example 14 with XmlObject

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;
}
Also used : Schema(org.apache.avro.Schema) ArrayList(java.util.ArrayList) TSalesforceInputProperties(org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties) SObject(com.sforce.soap.partner.sobject.SObject) XmlObject(com.sforce.ws.bind.XmlObject) XmlObject(com.sforce.ws.bind.XmlObject) SObject(com.sforce.soap.partner.sobject.SObject)

Example 15 with XmlObject

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);
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) XmlObject(com.sforce.ws.bind.XmlObject) ValueMetaBase(org.pentaho.di.core.row.value.ValueMetaBase) Test(org.junit.Test)

Aggregations

XmlObject (com.sforce.ws.bind.XmlObject)30 SObject (com.sforce.soap.partner.sobject.SObject)15 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)6 KettleException (org.pentaho.di.core.exception.KettleException)6 LinkedHashSet (java.util.LinkedHashSet)5 QName (javax.xml.namespace.QName)5 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 KettleStepException (org.pentaho.di.core.exception.KettleStepException)3 RowMeta (org.pentaho.di.core.row.RowMeta)3 Schema (org.apache.avro.Schema)2 ValueMetaBase (org.pentaho.di.core.row.value.ValueMetaBase)2 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)2 Column (org.teiid.metadata.Column)2 Field (com.sforce.soap.partner.Field)1 ConnectionException (com.sforce.ws.ConnectionException)1 Time (com.sforce.ws.types.Time)1 Method (java.lang.reflect.Method)1 DateFormat (java.text.DateFormat)1