Search in sources :

Example 1 with ReferenceId

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

Aggregations

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 SObjectTree (org.apache.camel.component.salesforce.api.dto.composite.SObjectTree)1 SObjectTreeResponse (org.apache.camel.component.salesforce.api.dto.composite.SObjectTreeResponse)1