use of org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties in project components by Talend.
the class SalesforceReader method getQueryString.
protected String getQueryString(SalesforceConnectionModuleProperties properties) throws IOException {
String condition = null;
if (properties instanceof TSalesforceInputProperties) {
TSalesforceInputProperties inProperties = (TSalesforceInputProperties) properties;
if (inProperties.manualQuery.getValue()) {
return inProperties.query.getStringValue();
} else {
condition = inProperties.condition.getStringValue();
}
}
StringBuilder sb = new StringBuilder();
// $NON-NLS-1$
sb.append("select ");
int count = 0;
for (Schema.Field se : getSchema().getFields()) {
if (count++ > 0) {
// $NON-NLS-1$
sb.append(", ");
}
sb.append(se.name());
}
// $NON-NLS-1$
sb.append(" from ");
sb.append(properties.module.moduleName.getStringValue());
if (condition != null && condition.trim().length() > 0) {
sb.append(" where ");
sb.append(condition);
}
return sb.toString();
}
use of org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties 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;
}
use of org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties in project components by Talend.
the class SalesforceInputReader method executeSalesforceQuery.
protected QueryResult executeSalesforceQuery() throws IOException, ConnectionException {
TSalesforceInputProperties inProperties = (TSalesforceInputProperties) properties;
getConnection().setQueryOptions(inProperties.batchSize.getValue());
if (inProperties.includeDeleted.getValue()) {
return getConnection().queryAll(getQueryString(inProperties));
} else {
return getConnection().query(getQueryString(inProperties));
}
}
use of org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties in project components by Talend.
the class SalesforceInputReaderTestIT method testAggregrateQueryWithDateTypeAndStringOutputAndBasicQuery.
@Test
public void testAggregrateQueryWithDateTypeAndStringOutputAndBasicQuery() throws Throwable {
TSalesforceInputProperties props = createTSalesforceInputProperties(true, false);
props.manualQuery.setValue(true);
// alias is
props.query.setValue("SELECT MIN(CreatedDate) VALUE FROM Contact GROUP BY FirstName, LastName LIMIT 1");
// necessary
// and
// should
// be the
// same
// with
// schema
props.module.main.schema.setValue(SCHEMA_STRING);
List<IndexedRecord> outputRows = readRows(props);
if (outputRows.isEmpty()) {
return;
}
IndexedRecord record = outputRows.get(0);
assertNotNull(record.getSchema());
Object value = record.get(0);
Assert.assertTrue(value != null && value instanceof String);
}
use of org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties in project components by Talend.
the class SalesforceInputReaderTestIT method testBulkQueryNullValue.
protected void testBulkQueryNullValue(SalesforceConnectionModuleProperties props, String random) throws Throwable {
ComponentDefinition sfInputDef = new TSalesforceInputDefinition();
TSalesforceInputProperties sfInputProps = (TSalesforceInputProperties) sfInputDef.createRuntimeProperties();
sfInputProps.copyValuesFrom(props);
sfInputProps.manualQuery.setValue(false);
sfInputProps.module.main.schema.setValue(SCHEMA_QUERY_ACCOUNT);
sfInputProps.queryMode.setValue(TSalesforceInputProperties.QueryMode.Bulk);
sfInputProps.condition.setValue("BillingPostalCode = '" + random + "'");
List<IndexedRecord> inpuRecords = readRows(sfInputProps);
for (IndexedRecord record : inpuRecords) {
assertNull(record.get(5));
assertNull(record.get(6));
}
}
Aggregations