Search in sources :

Example 1 with AbstractSObjectBase

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

the class AbstractRestProcessor method processGetBlobField.

private void processGetBlobField(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
    String sObjectName;
    // get blob field name
    final String sObjectBlobFieldName = getParameter(SOBJECT_BLOB_FIELD_NAME, exchange, IGNORE_BODY, NOT_OPTIONAL);
    // determine parameters from input AbstractSObject
    final AbstractSObjectBase sObjectBase = exchange.getIn().getBody(AbstractSObjectBase.class);
    String sObjectIdValue;
    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;
    restClient.getBlobField(sObjectName, sObjectId, sObjectBlobFieldName, 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)

Example 2 with AbstractSObjectBase

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

the class AbstractRestProcessor method processUpdateSobject.

private void processUpdateSobject(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
    String sObjectName;
    // determine parameters from input AbstractSObject
    final AbstractSObjectBase sObjectBase = exchange.getIn().getBody(AbstractSObjectBase.class);
    String sObjectId;
    if (sObjectBase != null) {
        sObjectName = sObjectBase.getClass().getSimpleName();
        // remember the sObject Id
        sObjectId = sObjectBase.getId();
        // clear base object fields, which cannot be updated
        sObjectBase.clearBaseFields();
    } else {
        sObjectName = getParameter(SOBJECT_NAME, exchange, IGNORE_BODY, NOT_OPTIONAL);
        sObjectId = getParameter(SOBJECT_ID, exchange, IGNORE_BODY, NOT_OPTIONAL);
    }
    final String finalsObjectId = sObjectId;
    restClient.updateSObject(sObjectName, sObjectId, getRequestStream(exchange), new RestClient.ResponseCallback() {

        @Override
        public void onResponse(InputStream response, SalesforceException exception) {
            processResponse(exchange, response, exception, callback);
            restoreFields(exchange, sObjectBase, finalsObjectId, 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)

Example 3 with AbstractSObjectBase

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

the class AbstractRestProcessor method processUpsertSobject.

private void processUpsertSobject(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
    String sObjectName;
    String sObjectExtIdValue;
    final String sObjectExtIdName = getParameter(SOBJECT_EXT_ID_NAME, exchange, IGNORE_BODY, NOT_OPTIONAL);
    // determine parameters from input AbstractSObject
    Object oldValue = null;
    final AbstractSObjectBase sObjectBase = exchange.getIn().getBody(AbstractSObjectBase.class);
    if (sObjectBase != null) {
        sObjectName = sObjectBase.getClass().getSimpleName();
        oldValue = getAndClearPropertyValue(sObjectBase, sObjectExtIdName);
        sObjectExtIdValue = oldValue.toString();
        // clear base object fields, which cannot be updated
        sObjectBase.clearBaseFields();
    } else {
        sObjectName = getParameter(SOBJECT_NAME, exchange, IGNORE_BODY, NOT_OPTIONAL);
        sObjectExtIdValue = getParameter(SOBJECT_EXT_ID_VALUE, exchange, IGNORE_BODY, NOT_OPTIONAL);
    }
    final Object finalOldValue = oldValue;
    restClient.upsertSObject(sObjectName, sObjectExtIdName, sObjectExtIdValue, getRequestStream(exchange), 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 4 with AbstractSObjectBase

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

the class AbstractRestProcessor method processDeleteSobjectWithId.

private void processDeleteSobjectWithId(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
    String sObjectName;
    final String sObjectExtIdName = getParameter(SOBJECT_EXT_ID_NAME, exchange, IGNORE_BODY, NOT_OPTIONAL);
    // determine parameters from input AbstractSObject
    Object oldValue = null;
    final AbstractSObjectBase sObjectBase = exchange.getIn().getBody(AbstractSObjectBase.class);
    String sObjectExtIdValue;
    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);
    }
    final Object finalOldValue = oldValue;
    restClient.deleteSObjectWithId(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 5 with AbstractSObjectBase

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

the class AbstractRestProcessor method processDeleteSobject.

private void processDeleteSobject(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
    String sObjectName;
    // determine parameters from input AbstractSObject
    final AbstractSObjectBase sObjectBase = exchange.getIn().getBody(AbstractSObjectBase.class);
    String sObjectIdValue;
    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;
    restClient.deleteSObject(sObjectName, sObjectId, 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