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