Search in sources :

Example 11 with JobInfo

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

the class BulkApiQueryIntegrationTest method testQueryLifecycle.

@Theory
public void testQueryLifecycle(ContentType contentType) throws Exception {
    log.info("Testing Query lifecycle with {} content", contentType);
    // create a QUERY test Job
    JobInfo jobInfo = new JobInfo();
    jobInfo.setOperation(OperationEnum.QUERY);
    jobInfo.setContentType(contentType);
    jobInfo.setObject(Merchandise__c.class.getSimpleName());
    jobInfo = createJob(jobInfo);
    // test createQuery
    BatchInfo batchInfo = template().requestBody("direct:createBatchQuery", jobInfo, BatchInfo.class);
    assertNotNull("Null batch query", batchInfo);
    assertNotNull("Null batch query id", batchInfo.getId());
    // test getRequest
    InputStream requestStream = template().requestBody("direct:getRequest", batchInfo, InputStream.class);
    assertNotNull("Null batch request", requestStream);
    // wait for batch to finish
    log.info("Waiting for query batch to finish...");
    while (!batchProcessed(batchInfo)) {
        // sleep 5 seconds
        Thread.sleep(5000);
        // check again
        batchInfo = getBatchInfo(batchInfo);
    }
    log.info("Query finished with state " + batchInfo.getState());
    assertEquals("Query did not succeed", BatchStateEnum.COMPLETED, batchInfo.getState());
    // test getQueryResultList
    @SuppressWarnings("unchecked") List<String> resultIds = template().requestBody("direct:getQueryResultIds", batchInfo, List.class);
    assertNotNull("Null query result ids", resultIds);
    assertFalse("Empty result ids", resultIds.isEmpty());
    // test getQueryResult
    for (String resultId : resultIds) {
        InputStream results = template().requestBodyAndHeader("direct:getQueryResult", batchInfo, SalesforceEndpointConfig.RESULT_ID, resultId, InputStream.class);
        assertNotNull("Null query result", results);
    }
    // close the test job
    template().requestBody("direct:closeJob", jobInfo, JobInfo.class);
}
Also used : JobInfo(org.apache.camel.component.salesforce.api.dto.bulk.JobInfo) InputStream(java.io.InputStream) Merchandise__c(org.apache.camel.component.salesforce.dto.generated.Merchandise__c) BatchInfo(org.apache.camel.component.salesforce.api.dto.bulk.BatchInfo) Theory(org.junit.experimental.theories.Theory)

Example 12 with JobInfo

use of org.apache.camel.component.salesforce.api.dto.bulk.JobInfo 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)

Example 13 with JobInfo

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

the class BulkApiProcessor method processCreateJob.

private void processCreateJob(final Exchange exchange, final AsyncCallback callback) throws InvalidPayloadException {
    JobInfo jobBody = exchange.getIn().getMandatoryBody(JobInfo.class);
    bulkClient.createJob(jobBody, new BulkApiClient.JobInfoResponseCallback() {

        @Override
        public void onResponse(JobInfo jobInfo, SalesforceException ex) {
            processResponse(exchange, jobInfo, ex, callback);
        }
    });
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) 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)

Example 14 with JobInfo

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

the class BulkApiProcessor method processAbortJob.

private void processAbortJob(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
    JobInfo jobBody;
    String jobId;
    jobBody = exchange.getIn().getBody(JobInfo.class);
    if (jobBody != null) {
        jobId = jobBody.getId();
    } else {
        jobId = getParameter(JOB_ID, exchange, USE_BODY, NOT_OPTIONAL);
    }
    bulkClient.abortJob(jobId, new BulkApiClient.JobInfoResponseCallback() {

        @Override
        public void onResponse(JobInfo jobInfo, SalesforceException ex) {
            processResponse(exchange, jobInfo, ex, callback);
        }
    });
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) 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)

Aggregations

JobInfo (org.apache.camel.component.salesforce.api.dto.bulk.JobInfo)14 SalesforceException (org.apache.camel.component.salesforce.api.SalesforceException)10 InputStream (java.io.InputStream)6 BulkApiClient (org.apache.camel.component.salesforce.internal.client.BulkApiClient)6 DefaultBulkApiClient (org.apache.camel.component.salesforce.internal.client.DefaultBulkApiClient)6 Request (org.eclipse.jetty.client.api.Request)5 BatchInfo (org.apache.camel.component.salesforce.api.dto.bulk.BatchInfo)4 Merchandise__c (org.apache.camel.component.salesforce.dto.generated.Merchandise__c)4 ContentType (org.apache.camel.component.salesforce.api.dto.bulk.ContentType)2 Test (org.junit.Test)2 Theory (org.junit.experimental.theories.Theory)2 ParallelParameterized (com.googlecode.junittoolbox.ParallelParameterized)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 JobStateEnum (org.apache.camel.component.salesforce.api.dto.bulk.JobStateEnum)1 OperationEnum (org.apache.camel.component.salesforce.api.dto.bulk.OperationEnum)1 SSLContextParameters (org.apache.camel.util.jsse.SSLContextParameters)1