Search in sources :

Example 11 with TSalesforceInputProperties

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();
}
Also used : Schema(org.apache.avro.Schema) TSalesforceInputProperties(org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties)

Example 12 with TSalesforceInputProperties

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;
}
Also used : Schema(org.apache.avro.Schema) ArrayList(java.util.ArrayList) TSalesforceInputProperties(org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties) 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)

Example 13 with TSalesforceInputProperties

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));
    }
}
Also used : TSalesforceInputProperties(org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties)

Example 14 with TSalesforceInputProperties

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);
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) TSalesforceInputProperties(org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties) Test(org.junit.Test)

Example 15 with TSalesforceInputProperties

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));
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) TSalesforceInputDefinition(org.talend.components.salesforce.tsalesforceinput.TSalesforceInputDefinition) TSalesforceInputProperties(org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties) ComponentDefinition(org.talend.components.api.component.ComponentDefinition)

Aggregations

TSalesforceInputProperties (org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties)55 Test (org.junit.Test)32 IndexedRecord (org.apache.avro.generic.IndexedRecord)30 Schema (org.apache.avro.Schema)11 ArrayList (java.util.ArrayList)10 ComponentDefinition (org.talend.components.api.component.ComponentDefinition)10 TSalesforceOutputProperties (org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputProperties)9 TSalesforceOutputDefinition (org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputDefinition)7 Result (org.talend.components.api.component.runtime.Result)6 DefaultComponentRuntimeContainerImpl (org.talend.components.api.container.DefaultComponentRuntimeContainerImpl)5 IOException (java.io.IOException)4 SalesforceConnectionProperties (org.talend.components.salesforce.SalesforceConnectionProperties)4 Form (org.talend.daikon.properties.presentation.Form)4 PartnerConnection (com.sforce.soap.partner.PartnerConnection)3 LoginFault (com.sforce.soap.partner.fault.LoginFault)3 File (java.io.File)3 List (java.util.List)3 Ignore (org.junit.Ignore)3 RuntimeContainer (org.talend.components.api.container.RuntimeContainer)3 TSalesforceInputDefinition (org.talend.components.salesforce.tsalesforceinput.TSalesforceInputDefinition)3