Search in sources :

Example 26 with XmlObject

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

the class PDI_10836_Test method testDateInsert.

@Test
public void testDateInsert() throws Exception {
    SalesforceInsert step = new SalesforceInsert(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
    SalesforceInsertMeta meta = smh.initStepMetaInterface;
    doReturn(UUID.randomUUID().toString()).when(meta).getTargetURL();
    doReturn(UUID.randomUUID().toString()).when(meta).getUsername();
    doReturn(UUID.randomUUID().toString()).when(meta).getPassword();
    doReturn(UUID.randomUUID().toString()).when(meta).getModule();
    doReturn(2).when(meta).getBatchSizeInt();
    doReturn(new String[] { "Date" }).when(meta).getUpdateLookup();
    doReturn(new Boolean[] { false }).when(meta).getUseExternalId();
    SalesforceInsertData data = smh.initStepDataInterface;
    data.nrfields = 1;
    data.fieldnrs = new int[] { 0 };
    data.sfBuffer = new SObject[] { null };
    data.outputBuffer = new Object[][] { null };
    step.init(meta, data);
    RowMeta rowMeta = new RowMeta();
    ValueMetaInterface valueMeta = new ValueMetaDate("date");
    valueMeta.setDateFormatTimeZone(TimeZone.getTimeZone("Europe/Minsk"));
    rowMeta.addValueMeta(valueMeta);
    smh.initStepDataInterface.inputRowMeta = rowMeta;
    Calendar minskTime = Calendar.getInstance(valueMeta.getDateFormatTimeZone());
    minskTime.clear();
    minskTime.set(2013, Calendar.OCTOBER, 16);
    Object[] args = new Object[] { minskTime.getTime() };
    Method m = SalesforceInsert.class.getDeclaredMethod("writeToSalesForce", Object[].class);
    m.setAccessible(true);
    m.invoke(step, new Object[] { args });
    DateFormat utc = new SimpleDateFormat("yyyy-MM-dd");
    utc.setTimeZone(TimeZone.getTimeZone("UTC"));
    XmlObject xmlObject = SalesforceConnection.getChildren(data.sfBuffer[0])[0];
    Assert.assertEquals("2013-10-16", utc.format(((Calendar) xmlObject.getValue()).getTime()));
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) Calendar(java.util.Calendar) Method(java.lang.reflect.Method) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) XmlObject(com.sforce.ws.bind.XmlObject) SObject(com.sforce.soap.partner.sobject.SObject) XmlObject(com.sforce.ws.bind.XmlObject) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 27 with XmlObject

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

the class SalesforceInsertTest method testWriteToSalesForcePentahoIntegerValue.

@Test
public void testWriteToSalesForcePentahoIntegerValue() throws Exception {
    SalesforceInsert sfInputStep = new SalesforceInsert(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
    SalesforceInsertMeta meta = generateSalesforceInsertMeta(new String[] { ACCOUNT_ID }, new Boolean[] { false });
    SalesforceInsertData data = generateSalesforceInsertData();
    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)

Example 28 with XmlObject

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

the class QueryExecutionImpl method logFields.

private void logFields(String sObjectName, List<XmlObject> fields) {
    if (!LogManager.isMessageToBeRecorded(LogConstants.CTX_CONNECTOR, MessageLevel.DETAIL)) {
        return;
    }
    // $NON-NLS-1$
    LogManager.logDetail(LogConstants.CTX_CONNECTOR, "SalesForce Object Name = " + sObjectName);
    // $NON-NLS-1$
    LogManager.logDetail(LogConstants.CTX_CONNECTOR, "FieldCount = " + fields.size());
    for (int i = 0; i < fields.size(); i++) {
        XmlObject element = fields.get(i);
        // $NON-NLS-1$ //$NON-NLS-2$
        LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Field # " + i + " is " + element.getName().getLocalPart());
    }
}
Also used : XmlObject(com.sforce.ws.bind.XmlObject)

Example 29 with XmlObject

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

the class QueryExecutionImpl method logAndMapFields.

/**
 * Load the map of response field names to index.
 * @param fields
 * @throws TranslatorException
 */
private void logAndMapFields(String sObjectName, List<XmlObject> fields) throws TranslatorException {
    if (!sObjectToResponseField.containsKey(sObjectName)) {
        logFields(sObjectName, fields);
        Map<String, Integer> responseFieldToIndexMap = new HashMap<String, Integer>();
        for (int x = 0; x < fields.size(); x++) {
            XmlObject element = fields.get(x);
            responseFieldToIndexMap.put(element.getName().getLocalPart(), x);
        }
        sObjectToResponseField.put(sObjectName, responseFieldToIndexMap);
    }
}
Also used : XmlObject(com.sforce.ws.bind.XmlObject)

Example 30 with XmlObject

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

the class QueryExecutionImpl method extractDataFromFields.

private List<Object[]> extractDataFromFields(SObject sObject, List<XmlObject> fields, List<Object[]> result) throws TranslatorException {
    Map<String, Integer> fieldToIndexMap = sObjectToResponseField.get(sObject.getType());
    int aggCount = 0;
    for (int j = 0; j < visitor.getSelectSymbolCount(); j++) {
        Expression ex = visitor.getSelectSymbolMetadata(j);
        if (ex instanceof ColumnReference) {
            Column element = ((ColumnReference) ex).getMetadataObject();
            Table table = (Table) element.getParent();
            if (table.getSourceName().equals(sObject.getType()) || AGGREGATE_RESULT.equalsIgnoreCase(sObject.getType())) {
                Integer index = fieldToIndexMap.get(element.getSourceName());
                if (null == index) {
                    // $NON-NLS-1$
                    throw new TranslatorException(SalesForcePlugin.Util.getString("SalesforceQueryExecutionImpl.missing.field") + element.getSourceName());
                }
                Object cell = getCellDatum(element.getSourceName(), element.getJavaType(), fields.get(index));
                setValueInColumn(j, cell, result);
            }
        } else if (ex instanceof AggregateFunction) {
            String name = SelectVisitor.AGG_PREFIX + (aggCount++);
            Integer index = fieldToIndexMap.get(name);
            if (null == index) {
                // $NON-NLS-1$
                throw new TranslatorException(SalesForcePlugin.Util.getString("SalesforceQueryExecutionImpl.missing.field") + ex);
            }
            Object cell = getCellDatum(name, ex.getType(), fields.get(index));
            setValueInColumn(j, cell, result);
        }
    }
    return result;
}
Also used : Table(org.teiid.metadata.Table) Column(org.teiid.metadata.Column) TranslatorException(org.teiid.translator.TranslatorException) XmlObject(com.sforce.ws.bind.XmlObject) SObject(com.sforce.soap.partner.sobject.SObject)

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