Search in sources :

Example 1 with SObjectTree

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);
    }
}
Also used : SObjectTreeResponse(org.apache.camel.component.salesforce.api.dto.composite.SObjectTreeResponse) SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) Message(org.apache.camel.Message) ReferenceId(org.apache.camel.component.salesforce.api.dto.composite.ReferenceId) SObjectTree(org.apache.camel.component.salesforce.api.dto.composite.SObjectTree)

Example 2 with SObjectTree

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());
}
Also used : Account(org.apache.camel.component.salesforce.dto.generated.Account) Asset(org.apache.camel.component.salesforce.dto.generated.Asset) SObjectTree(org.apache.camel.component.salesforce.api.dto.composite.SObjectTree) Contact(org.apache.camel.component.salesforce.dto.generated.Contact) Test(org.junit.Test)

Aggregations

SObjectTree (org.apache.camel.component.salesforce.api.dto.composite.SObjectTree)2 Message (org.apache.camel.Message)1 SalesforceException (org.apache.camel.component.salesforce.api.SalesforceException)1 ReferenceId (org.apache.camel.component.salesforce.api.dto.composite.ReferenceId)1 SObjectTreeResponse (org.apache.camel.component.salesforce.api.dto.composite.SObjectTreeResponse)1 Account (org.apache.camel.component.salesforce.dto.generated.Account)1 Asset (org.apache.camel.component.salesforce.dto.generated.Asset)1 Contact (org.apache.camel.component.salesforce.dto.generated.Contact)1 Test (org.junit.Test)1