Search in sources :

Example 6 with AbstractSObjectBase

use of org.apache.camel.component.salesforce.api.dto.AbstractSObjectBase in project camel by apache.

the class AbstractRestProcessor method processGetSobjectWithId.

private void processGetSobjectWithId(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
    String sObjectName;
    Object oldValue = null;
    String sObjectExtIdValue;
    final String sObjectExtIdName = getParameter(SOBJECT_EXT_ID_NAME, exchange, IGNORE_BODY, NOT_OPTIONAL);
    // determine parameters from input AbstractSObject
    final AbstractSObjectBase sObjectBase = exchange.getIn().getBody(AbstractSObjectBase.class);
    if (sObjectBase != null) {
        sObjectName = sObjectBase.getClass().getSimpleName();
        oldValue = getAndClearPropertyValue(sObjectBase, sObjectExtIdName);
        sObjectExtIdValue = oldValue.toString();
    } else {
        sObjectName = getParameter(SOBJECT_NAME, exchange, IGNORE_BODY, NOT_OPTIONAL);
        sObjectExtIdValue = getParameter(SOBJECT_EXT_ID_VALUE, exchange, USE_BODY, NOT_OPTIONAL);
    }
    // use sObject name to load class
    setResponseClass(exchange, sObjectName);
    final Object finalOldValue = oldValue;
    restClient.getSObjectWithId(sObjectName, sObjectExtIdName, sObjectExtIdValue, new RestClient.ResponseCallback() {

        @Override
        public void onResponse(InputStream response, SalesforceException exception) {
            processResponse(exchange, response, exception, callback);
            restoreFields(exchange, sObjectBase, null, sObjectExtIdName, finalOldValue);
        }
    });
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) AbstractSObjectBase(org.apache.camel.component.salesforce.api.dto.AbstractSObjectBase) InputStream(java.io.InputStream) RestClient(org.apache.camel.component.salesforce.internal.client.RestClient) DefaultRestClient(org.apache.camel.component.salesforce.internal.client.DefaultRestClient)

Example 7 with AbstractSObjectBase

use of org.apache.camel.component.salesforce.api.dto.AbstractSObjectBase in project camel by apache.

the class AbstractRestProcessor method processCreateSobject.

private void processCreateSobject(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
    String sObjectName;
    // determine parameters from input AbstractSObject
    AbstractSObjectBase sObjectBase = exchange.getIn().getBody(AbstractSObjectBase.class);
    if (sObjectBase != null) {
        sObjectName = sObjectBase.getClass().getSimpleName();
    } else {
        sObjectName = getParameter(SOBJECT_NAME, exchange, IGNORE_BODY, NOT_OPTIONAL);
    }
    restClient.createSObject(sObjectName, getRequestStream(exchange), new RestClient.ResponseCallback() {

        @Override
        public void onResponse(InputStream response, SalesforceException exception) {
            processResponse(exchange, response, exception, callback);
        }
    });
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) AbstractSObjectBase(org.apache.camel.component.salesforce.api.dto.AbstractSObjectBase) InputStream(java.io.InputStream) RestClient(org.apache.camel.component.salesforce.internal.client.RestClient) DefaultRestClient(org.apache.camel.component.salesforce.internal.client.DefaultRestClient)

Example 8 with AbstractSObjectBase

use of org.apache.camel.component.salesforce.api.dto.AbstractSObjectBase in project camel by apache.

the class AbstractRestProcessor method processGetSobject.

private void processGetSobject(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
    String sObjectName;
    String sObjectIdValue;
    // determine parameters from input AbstractSObject
    final AbstractSObjectBase sObjectBase = exchange.getIn().getBody(AbstractSObjectBase.class);
    if (sObjectBase != null) {
        sObjectName = sObjectBase.getClass().getSimpleName();
        sObjectIdValue = sObjectBase.getId();
    } else {
        sObjectName = getParameter(SOBJECT_NAME, exchange, IGNORE_BODY, NOT_OPTIONAL);
        sObjectIdValue = getParameter(SOBJECT_ID, exchange, USE_BODY, NOT_OPTIONAL);
    }
    final String sObjectId = sObjectIdValue;
    // use sObject name to load class
    setResponseClass(exchange, sObjectName);
    // get optional field list
    String fieldsValue = getParameter(SOBJECT_FIELDS, exchange, IGNORE_BODY, IS_OPTIONAL);
    String[] fields = null;
    if (fieldsValue != null) {
        fields = fieldsValue.split(",");
    }
    restClient.getSObject(sObjectName, sObjectId, fields, new RestClient.ResponseCallback() {

        @Override
        public void onResponse(InputStream response, SalesforceException exception) {
            processResponse(exchange, response, exception, callback);
            restoreFields(exchange, sObjectBase, sObjectId, null, null);
        }
    });
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) AbstractSObjectBase(org.apache.camel.component.salesforce.api.dto.AbstractSObjectBase) InputStream(java.io.InputStream) RestClient(org.apache.camel.component.salesforce.internal.client.RestClient) DefaultRestClient(org.apache.camel.component.salesforce.internal.client.DefaultRestClient)

Aggregations

InputStream (java.io.InputStream)8 SalesforceException (org.apache.camel.component.salesforce.api.SalesforceException)8 AbstractSObjectBase (org.apache.camel.component.salesforce.api.dto.AbstractSObjectBase)8 DefaultRestClient (org.apache.camel.component.salesforce.internal.client.DefaultRestClient)8 RestClient (org.apache.camel.component.salesforce.internal.client.RestClient)8