use of org.apache.camel.component.salesforce.api.dto.bulk.BatchInfo 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);
}
});
}
use of org.apache.camel.component.salesforce.api.dto.bulk.BatchInfo in project camel by apache.
the class BulkApiBatchIntegrationTest method testBatchLifecycle.
@Theory
public void testBatchLifecycle(BatchTest request) throws Exception {
log.info("Testing Batch lifecycle with {} content", request.contentType);
// create an UPSERT test Job for this batch request
JobInfo jobInfo = new JobInfo();
jobInfo.setOperation(OperationEnum.UPSERT);
jobInfo.setContentType(request.contentType);
jobInfo.setObject(Merchandise__c.class.getSimpleName());
jobInfo.setExternalIdFieldName("Name");
jobInfo = createJob(jobInfo);
// test createBatch
Map<String, Object> headers = new HashMap<String, Object>();
headers.put(SalesforceEndpointConfig.JOB_ID, jobInfo.getId());
headers.put(SalesforceEndpointConfig.CONTENT_TYPE, jobInfo.getContentType());
BatchInfo batchInfo = template().requestBodyAndHeaders("direct:createBatch", request.stream, headers, BatchInfo.class);
assertNotNull("Null batch", batchInfo);
assertNotNull("Null batch id", batchInfo.getId());
// test getAllBatches
@SuppressWarnings("unchecked") List<BatchInfo> batches = template().requestBody("direct:getAllBatches", jobInfo, List.class);
assertNotNull("Null batches", batches);
assertFalse("Empty batch list", batches.isEmpty());
// test getBatch
batchInfo = batches.get(0);
batchInfo = getBatchInfo(batchInfo);
// 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 batch to finish...");
while (!batchProcessed(batchInfo)) {
// sleep 5 seconds
Thread.sleep(5000);
// check again
batchInfo = getBatchInfo(batchInfo);
}
log.info("Batch finished with state " + batchInfo.getState());
assertEquals("Batch did not succeed", BatchStateEnum.COMPLETED, batchInfo.getState());
// test getResults
InputStream results = template().requestBody("direct:getResults", batchInfo, InputStream.class);
assertNotNull("Null batch results", results);
// close the test job
template().requestBody("direct:closeJob", jobInfo, JobInfo.class);
}
use of org.apache.camel.component.salesforce.api.dto.bulk.BatchInfo 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.BatchInfo 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.BatchInfo in project camel by apache.
the class BulkApiProcessor method processGetQueryResultIds.
private void processGetQueryResultIds(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
String jobId;
BatchInfo batchBody;
String batchId;
batchBody = exchange.getIn().getBody(BatchInfo.class);
if (batchBody != null) {
jobId = batchBody.getJobId();
batchId = batchBody.getId();
} else {
jobId = getParameter(JOB_ID, exchange, IGNORE_BODY, NOT_OPTIONAL);
batchId = getParameter(BATCH_ID, exchange, USE_BODY, NOT_OPTIONAL);
}
bulkClient.getQueryResultIds(jobId, batchId, new BulkApiClient.QueryResultIdsCallback() {
@Override
public void onResponse(List<String> ids, SalesforceException ex) {
processResponse(exchange, ids, ex, callback);
}
});
}
Aggregations