Search in sources :

Example 1 with ContentType

use of org.apache.camel.component.salesforce.api.dto.bulk.ContentType in project camel by apache.

the class BulkApiProcessor method processCreateBatch.

private void processCreateBatch(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
    String jobId;
    // since request is in the body, use headers or endpoint params
    ContentType contentType = ContentType.fromValue(getParameter(CONTENT_TYPE, exchange, IGNORE_BODY, NOT_OPTIONAL));
    jobId = getParameter(JOB_ID, exchange, IGNORE_BODY, NOT_OPTIONAL);
    InputStream request;
    try {
        request = exchange.getIn().getMandatoryBody(InputStream.class);
    } catch (CamelException e) {
        String msg = "Error preparing batch request: " + e.getMessage();
        throw new SalesforceException(msg, e);
    }
    bulkClient.createBatch(request, jobId, contentType, new BulkApiClient.BatchInfoResponseCallback() {

        @Override
        public void onResponse(BatchInfo batchInfo, SalesforceException ex) {
            processResponse(exchange, batchInfo, ex, callback);
        }
    });
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) ContentType(org.apache.camel.component.salesforce.api.dto.bulk.ContentType) CamelException(org.apache.camel.CamelException) InputStream(java.io.InputStream) DefaultBulkApiClient(org.apache.camel.component.salesforce.internal.client.DefaultBulkApiClient) BulkApiClient(org.apache.camel.component.salesforce.internal.client.BulkApiClient) BatchInfo(org.apache.camel.component.salesforce.api.dto.bulk.BatchInfo)

Example 2 with ContentType

use of org.apache.camel.component.salesforce.api.dto.bulk.ContentType in project camel by apache.

the class BulkApiProcessor method processCreateBatchQuery.

private void processCreateBatchQuery(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
    JobInfo jobBody;
    String jobId;
    ContentType contentType;
    jobBody = exchange.getIn().getBody(JobInfo.class);
    String soqlQuery;
    if (jobBody != null) {
        jobId = jobBody.getId();
        contentType = jobBody.getContentType();
        // use SOQL query from header or endpoint config
        soqlQuery = getParameter(SOBJECT_QUERY, exchange, IGNORE_BODY, NOT_OPTIONAL);
    } else {
        jobId = getParameter(JOB_ID, exchange, IGNORE_BODY, NOT_OPTIONAL);
        contentType = ContentType.fromValue(getParameter(CONTENT_TYPE, exchange, IGNORE_BODY, NOT_OPTIONAL));
        // reuse SOBJECT_QUERY property
        soqlQuery = getParameter(SOBJECT_QUERY, exchange, USE_BODY, NOT_OPTIONAL);
    }
    bulkClient.createBatchQuery(jobId, soqlQuery, contentType, new BulkApiClient.BatchInfoResponseCallback() {

        @Override
        public void onResponse(BatchInfo batchInfo, SalesforceException ex) {
            processResponse(exchange, batchInfo, ex, callback);
        }
    });
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) ContentType(org.apache.camel.component.salesforce.api.dto.bulk.ContentType) JobInfo(org.apache.camel.component.salesforce.api.dto.bulk.JobInfo) DefaultBulkApiClient(org.apache.camel.component.salesforce.internal.client.DefaultBulkApiClient) BulkApiClient(org.apache.camel.component.salesforce.internal.client.BulkApiClient) BatchInfo(org.apache.camel.component.salesforce.api.dto.bulk.BatchInfo)

Aggregations

SalesforceException (org.apache.camel.component.salesforce.api.SalesforceException)2 BatchInfo (org.apache.camel.component.salesforce.api.dto.bulk.BatchInfo)2 ContentType (org.apache.camel.component.salesforce.api.dto.bulk.ContentType)2 BulkApiClient (org.apache.camel.component.salesforce.internal.client.BulkApiClient)2 DefaultBulkApiClient (org.apache.camel.component.salesforce.internal.client.DefaultBulkApiClient)2 InputStream (java.io.InputStream)1 CamelException (org.apache.camel.CamelException)1 JobInfo (org.apache.camel.component.salesforce.api.dto.bulk.JobInfo)1