Search in sources :

Example 6 with XmlObject

use of com.sforce.ws.bind.XmlObject in project pentaho-kettle by pentaho.

the class SalesforceInsert method writeToSalesForce.

@VisibleForTesting
void writeToSalesForce(Object[] rowData) throws KettleException {
    try {
        if (log.isDetailed()) {
            logDetailed(BaseMessages.getString(PKG, "SalesforceInsert.WriteToSalesforce", data.iBufferPos, meta.getBatchSizeInt()));
        }
        // if there is room in the buffer
        if (data.iBufferPos < meta.getBatchSizeInt()) {
            ArrayList<XmlObject> insertfields = new ArrayList<>();
            // Reserve for empty fields
            ArrayList<String> fieldsToNull = new ArrayList<String>();
            // Add fields to insert
            for (int i = 0; i < data.nrfields; i++) {
                ValueMetaInterface valueMeta = data.inputRowMeta.getValueMeta(data.fieldnrs[i]);
                Object value = rowData[data.fieldnrs[i]];
                if (valueMeta.isNull(value)) {
                    // The value is null
                    // We need to keep track of this field
                    fieldsToNull.add(SalesforceUtils.getFieldToNullName(log, meta.getUpdateLookup()[i], meta.getUseExternalId()[i]));
                } else {
                    Object normalObject = normalizeValue(valueMeta, value);
                    insertfields.add(SalesforceConnection.createMessageElement(meta.getUpdateLookup()[i], normalObject, meta.getUseExternalId()[i]));
                }
            }
            // build the SObject
            SObject sobjPass = new SObject();
            sobjPass.setType(data.connection.getModule());
            if (insertfields.size() > 0) {
                for (XmlObject element : insertfields) {
                    sobjPass.setSObjectField(element.getName().getLocalPart(), element.getValue());
                }
            }
            if (fieldsToNull.size() > 0) {
                // Set Null to fields
                sobjPass.setFieldsToNull(fieldsToNull.toArray(new String[fieldsToNull.size()]));
            }
            // Load the buffer array
            data.sfBuffer[data.iBufferPos] = sobjPass;
            data.outputBuffer[data.iBufferPos] = rowData;
            data.iBufferPos++;
        }
        if (data.iBufferPos >= meta.getBatchSizeInt()) {
            if (log.isDetailed()) {
                logDetailed(BaseMessages.getString(PKG, "SalesforceInsert.CallingFlushBuffer"));
            }
            flushBuffers();
        }
    } catch (Exception e) {
        throw new KettleException(BaseMessages.getString(PKG, "SalesforceInsert.Error", e.getMessage()));
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ArrayList(java.util.ArrayList) 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) KettleException(org.pentaho.di.core.exception.KettleException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 7 with XmlObject

use of com.sforce.ws.bind.XmlObject in project pentaho-kettle by pentaho.

the class SalesforceUpdate method writeToSalesForce.

@VisibleForTesting
void writeToSalesForce(Object[] rowData) throws KettleException {
    try {
        if (log.isDetailed()) {
            logDetailed("Called writeToSalesForce with " + data.iBufferPos + " out of " + meta.getBatchSizeInt());
        }
        // if there is room in the buffer
        if (data.iBufferPos < meta.getBatchSizeInt()) {
            // Reserve for empty fields
            ArrayList<String> fieldsToNull = new ArrayList<String>();
            ArrayList<XmlObject> updatefields = new ArrayList<>();
            // Add fields to update
            for (int i = 0; i < data.nrfields; i++) {
                boolean valueIsNull = data.inputRowMeta.isNull(rowData, data.fieldnrs[i]);
                if (valueIsNull) {
                    // The value is null
                    // We need to keep track of this field
                    fieldsToNull.add(SalesforceUtils.getFieldToNullName(log, meta.getUpdateLookup()[i], meta.getUseExternalId()[i]));
                } else {
                    ValueMetaInterface valueMeta = data.inputRowMeta.getValueMeta(data.fieldnrs[i]);
                    Object value = rowData[data.fieldnrs[i]];
                    Object normalObject = normalizeValue(valueMeta, value);
                    updatefields.add(SalesforceConnection.createMessageElement(meta.getUpdateLookup()[i], normalObject, meta.getUseExternalId()[i]));
                }
            }
            // build the SObject
            SObject sobjPass = new SObject();
            sobjPass.setType(data.connection.getModule());
            if (updatefields.size() > 0) {
                for (XmlObject element : updatefields) {
                    sobjPass.setSObjectField(element.getName().getLocalPart(), element.getValue());
                }
            }
            if (fieldsToNull.size() > 0) {
                // Set Null to fields
                sobjPass.setFieldsToNull(fieldsToNull.toArray(new String[fieldsToNull.size()]));
            }
            // Load the buffer array
            data.sfBuffer[data.iBufferPos] = sobjPass;
            data.outputBuffer[data.iBufferPos] = rowData;
            data.iBufferPos++;
        }
        if (data.iBufferPos >= meta.getBatchSizeInt()) {
            if (log.isDetailed()) {
                logDetailed("Calling flush buffer from writeToSalesForce");
            }
            flushBuffers();
        }
    } catch (Exception e) {
        throw new KettleException("\nFailed in writeToSalesForce: " + e.getMessage());
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ArrayList(java.util.ArrayList) 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) KettleException(org.pentaho.di.core.exception.KettleException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 8 with XmlObject

use of com.sforce.ws.bind.XmlObject 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);
    }
}
Also used : QName(javax.xml.namespace.QName) SObject(com.sforce.soap.partner.sobject.SObject) XmlObject(com.sforce.ws.bind.XmlObject)

Example 9 with XmlObject

use of com.sforce.ws.bind.XmlObject 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));
}
Also used : QName(javax.xml.namespace.QName) SObject(com.sforce.soap.partner.sobject.SObject) XmlObject(com.sforce.ws.bind.XmlObject) Matchers.anyString(org.mockito.Matchers.anyString) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Test(org.junit.Test)

Example 10 with XmlObject

use of com.sforce.ws.bind.XmlObject in project teiid by teiid.

the class DirectQueryExecution method loadBatch.

private List<List<Object>> loadBatch(QueryResult queryResult) {
    List<List<Object>> batch = new ArrayList<List<Object>>();
    for (SObject sObject : queryResult.getRecords()) {
        Iterator<XmlObject> fields = sObject.getChildren();
        List<Object> row = new ArrayList<Object>();
        while (fields.hasNext()) {
            XmlObject elem = fields.next();
            if (elem.getName().getLocalPart().equals("type")) {
                // $NON-NLS-1$
                continue;
            }
            Object value = elem.getValue();
            row.add(value);
        }
        batch.add(row);
    }
    return batch;
}
Also used : ArrayList(java.util.ArrayList) SObject(com.sforce.soap.partner.sobject.SObject) ArrayList(java.util.ArrayList) List(java.util.List) XmlObject(com.sforce.ws.bind.XmlObject) SObject(com.sforce.soap.partner.sobject.SObject) XmlObject(com.sforce.ws.bind.XmlObject)

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