Search in sources :

Example 21 with XmlObject

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

the class SalesforceInputDialogTest method testAddFields_nullIdNotAdded.

@Test
public void testAddFields_nullIdNotAdded() throws Exception {
    final Set<String> fields = new LinkedHashSet<>();
    XmlObject testObject = createObject("Id", null, ObjectType.XMLOBJECT);
    dialog.addFields("", fields, testObject);
    assertArrayEquals("Null Id field not added", new String[] {}, fields.toArray());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) XmlObject(com.sforce.ws.bind.XmlObject) Test(org.junit.Test)

Example 22 with XmlObject

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

the class SalesforceConnection method fromTemplateElement.

public static XmlObject fromTemplateElement(String name, Object value, boolean setValue) throws SOAPException {
    // Use the TEMPLATE org.w3c.dom.Element to create new Message Elements
    XmlObject me = new XmlObject();
    if (setValue) {
        me.setValue(value);
    }
    me.setName(new QName(name));
    return me;
}
Also used : QName(javax.xml.namespace.QName) XmlObject(com.sforce.ws.bind.XmlObject)

Example 23 with XmlObject

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

the class SalesforceUpsert method writeToSalesForce.

@VisibleForTesting
void writeToSalesForce(Object[] rowData) throws KettleException {
    try {
        if (log.isDetailed()) {
            logDetailed(BaseMessages.getString(PKG, "SalesforceUpsert.CalledWrite", data.iBufferPos, 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> upsertfields = new ArrayList<>();
            // Add fields to update
            for (int i = 0; i < data.nrfields; i++) {
                ValueMetaInterface valueMeta = data.inputRowMeta.getValueMeta(data.fieldnrs[i]);
                Object object = rowData[data.fieldnrs[i]];
                if (valueMeta.isNull(object)) {
                    // 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, rowData[data.fieldnrs[i]]);
                    upsertfields.add(SalesforceConnection.createMessageElement(meta.getUpdateLookup()[i], normalObject, meta.getUseExternalId()[i]));
                }
            }
            // build the SObject
            SObject sobjPass = new SObject();
            sobjPass.setType(data.connection.getModule());
            if (upsertfields.size() > 0) {
                for (XmlObject element : upsertfields) {
                    setFieldInSObject(sobjPass, element);
                }
            }
            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 (KettleException ke) {
        throw ke;
    } catch (Exception e) {
        throw new KettleException(BaseMessages.getString(PKG, "SalesforceUpsert.FailedInWrite", e.toString()));
    }
}
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 24 with XmlObject

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

the class SalesforceInputDialog method get.

private void get() {
    SalesforceConnection connection = null;
    try {
        SalesforceInputMeta meta = new SalesforceInputMeta();
        getInfo(meta);
        // Clear Fields Grid
        wFields.removeAll();
        // get real values
        String realModule = transMeta.environmentSubstitute(meta.getModule());
        String realURL = transMeta.environmentSubstitute(meta.getTargetURL());
        String realUsername = transMeta.environmentSubstitute(meta.getUsername());
        String realPassword = Utils.resolvePassword(transMeta, meta.getPassword());
        int realTimeOut = Const.toInt(transMeta.environmentSubstitute(meta.getTimeout()), 0);
        connection = new SalesforceConnection(log, realURL, realUsername, realPassword);
        connection.setTimeOut(realTimeOut);
        String[] fieldsName = null;
        if (meta.isSpecifyQuery()) {
            // Free hand SOQL
            String realQuery = transMeta.environmentSubstitute(meta.getQuery());
            connection.setSQL(realQuery);
            connection.connect();
            // We are connected, so let's query
            XmlObject[] fields = connection.getElements();
            int nrFields = fields.length;
            Set<String> fieldNames = new HashSet<>();
            for (int i = 0; i < nrFields; i++) {
                addFields("", fieldNames, fields[i]);
            }
            fieldsName = fieldNames.toArray(new String[fieldNames.size()]);
        } else {
            connection.connect();
            Field[] fields = connection.getObjectFields(realModule);
            fieldsName = new String[fields.length];
            for (int i = 0; i < fields.length; i++) {
                Field field = fields[i];
                fieldsName[i] = field.getName();
                addField(field);
            }
        }
        if (fieldsName != null) {
            colinf[1].setComboValues(fieldsName);
        }
        wFields.removeEmptyRows();
        wFields.setRowNums();
        wFields.optWidth(true);
    } catch (KettleException e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "SalesforceInputMeta.ErrorRetrieveData.DialogTitle"), BaseMessages.getString(PKG, "SalesforceInputMeta.ErrorRetrieveData.DialogMessage"), e);
    } catch (Exception e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "SalesforceInputMeta.ErrorRetrieveData.DialogTitle"), BaseMessages.getString(PKG, "SalesforceInputMeta.ErrorRetrieveData.DialogMessage"), e);
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (Exception e) {
            // Ignore errors
            }
        }
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) SalesforceConnection(org.pentaho.di.trans.steps.salesforce.SalesforceConnection) KettleException(org.pentaho.di.core.exception.KettleException) Field(com.sforce.soap.partner.Field) SalesforceInputField(org.pentaho.di.trans.steps.salesforceinput.SalesforceInputField) XmlObject(com.sforce.ws.bind.XmlObject) SalesforceInputMeta(org.pentaho.di.trans.steps.salesforceinput.SalesforceInputMeta) HashSet(java.util.HashSet)

Example 25 with XmlObject

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

the class SalesforceConnectionTest method testGetRecordValue.

// PDI-15973
@Test
public void testGetRecordValue() throws Exception {
    // PDI-15973
    SalesforceConnection conn = mock(SalesforceConnection.class, Mockito.CALLS_REAL_METHODS);
    SObject sObject = new SObject();
    sObject.setName(new QName(Constants.PARTNER_SOBJECT_NS, "sObject"));
    SObject testObject = createObject("field", "value");
    sObject.addField("field", testObject);
    assertEquals("Get value of simple record", "value", conn.getRecordValue(sObject, "field"));
    SObject parentObject = createObject("parentField", null);
    sObject.addField("parentField", parentObject);
    SObject childObject = createObject("subField", "subValue");
    parentObject.addField("subField", childObject);
    assertEquals("Get value of record with hierarchy", "subValue", conn.getRecordValue(sObject, "parentField.subField"));
    XmlObject nullObject = new XmlObject(new QName("nullField"));
    sObject.addField("nullField", nullObject);
    assertEquals("Get null value when relational query id is null", null, conn.getRecordValue(sObject, "nullField.childField"));
}
Also used : QName(javax.xml.namespace.QName) SObject(com.sforce.soap.partner.sobject.SObject) XmlObject(com.sforce.ws.bind.XmlObject) 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