use of org.apache.camel.component.salesforce.api.dto.composite.SObjectTree in project camel by apache.
the class CompositeApiProcessor method processCompositeTreeResponse.
void processCompositeTreeResponse(final Exchange exchange, final Optional<SObjectTreeResponse> responseBody, final SalesforceException exception, final AsyncCallback callback) {
try {
if (!responseBody.isPresent()) {
exchange.setException(exception);
} else {
final Message in = exchange.getIn();
final Message out = exchange.getOut();
final SObjectTree tree = in.getBody(SObjectTree.class);
final SObjectTreeResponse response = responseBody.get();
final boolean hasErrors = response.hasErrors();
for (final ReferenceId referenceId : response.getResults()) {
tree.setIdFor(referenceId.getReferenceId(), referenceId.getId());
if (hasErrors) {
tree.setErrorFor(referenceId.getReferenceId(), referenceId.getErrors());
}
}
if (hasErrors) {
final SalesforceException withErrors = new SalesforceException(response.getAllErrors(), exception.getStatusCode(), exception);
exchange.setException(withErrors);
}
out.copyFromWithNewBody(in, tree);
}
} finally {
// notify callback that exchange is done
callback.done(false);
}
}
use of org.apache.camel.component.salesforce.api.dto.composite.SObjectTree in project camel by apache.
the class CompositeApiTreeIntegrationTest method shouldSubmitTreeUsingCompositeApi.
@Test
public void shouldSubmitTreeUsingCompositeApi() {
final Account simpleAccount = new Account();
final Contact smith = new Contact();
final Contact evans = new Contact();
final Account simpleAccount2 = new Account();
simpleAccount.setName("SampleAccount");
simpleAccount.setPhone("1234567890");
simpleAccount.setWebsite("www.salesforce.com");
simpleAccount.setNumberOfEmployees(100);
simpleAccount.setIndustry(Account_IndustryEnum.BANKING);
smith.setLastName("Smith");
smith.setTitle("President");
smith.setEmail("sample@salesforce.com");
evans.setLastName("Evans");
evans.setTitle("Vice President");
evans.setEmail("sample@salesforce.com");
simpleAccount2.setName("SampleAccount2");
simpleAccount2.setPhone("1234567890");
simpleAccount2.setWebsite("www.salesforce2.com");
simpleAccount2.setNumberOfEmployees(100);
simpleAccount2.setIndustry(Account_IndustryEnum.BANKING);
final SObjectTree tree = new SObjectTree();
tree.addObject(simpleAccount).addChildren("Contacts", smith, evans);
tree.addObject(simpleAccount2);
final Account simpleAccount3 = new Account();
simpleAccount3.setName("SimpleAccount3");
final Contact contact = new Contact();
contact.setFirstName("Simple");
contact.setLastName("Contact");
final Asset asset = new Asset();
asset.setName("Asset Name");
asset.setDescription("Simple asset");
tree.addObject(simpleAccount3).addChild("Contacts", contact).addChild("Assets", asset);
final SObjectTree response = template.requestBody("salesforce:composite-tree?format=" + format, tree, SObjectTree.class);
assertNotNull("Response should be provided", response);
assertNotNull("First account should have Id set", simpleAccount.getId());
assertNotNull("President of the first account should have Id set", smith.getId());
assertNotNull("Vice president of the first account should have Id set", evans.getId());
assertNotNull("Second account should have Id set", simpleAccount2.getId());
assertNotNull("Third account should have Id set", simpleAccount3.getId());
assertNotNull("Simple contact on third account should have Id set", contact.getId());
assertNotNull("Simple asset on the contact of the third account should have Id set", asset.getId());
}
Aggregations