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()));
}
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);
}
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());
}
}
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);
}
}
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;
}
Aggregations