use of org.apache.camel.component.salesforce.api.SalesforceException in project camel by apache.
the class AbstractRestProcessor method processApexCall.
private void processApexCall(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
// HTTP method, URL and query params for APEX call
final String apexUrl = getApexUrl(exchange);
String apexMethod = getParameter(APEX_METHOD, exchange, IGNORE_BODY, IS_OPTIONAL);
// default to GET
if (apexMethod == null) {
apexMethod = "GET";
log.debug("Using HTTP GET method by default for APEX REST call for {}", apexUrl);
}
final Map<String, Object> queryParams = getQueryParams(exchange);
// set response class
setResponseClass(exchange, getParameter(SOBJECT_NAME, exchange, IGNORE_BODY, IS_OPTIONAL));
// set request stream
final Object requestBody = exchange.getIn().getBody();
final InputStream requestDto = (requestBody != null && !(requestBody instanceof Map)) ? getRequestStream(exchange) : null;
restClient.apexCall(apexMethod, apexUrl, queryParams, requestDto, new RestClient.ResponseCallback() {
@Override
public void onResponse(InputStream response, SalesforceException exception) {
processResponse(exchange, response, exception, callback);
}
});
}
use of org.apache.camel.component.salesforce.api.SalesforceException in project camel by apache.
the class AbstractRestProcessor method getAndClearPropertyValue.
private Object getAndClearPropertyValue(AbstractSObjectBase sObjectBase, String propertyName) throws SalesforceException {
try {
// obtain the value using the get method
Method getMethod = sObjectBase.getClass().getMethod("get" + propertyName);
Object value = getMethod.invoke(sObjectBase);
// clear the value with the set method
Method setMethod = sObjectBase.getClass().getMethod("set" + propertyName, getMethod.getReturnType());
setMethod.invoke(sObjectBase, new Object[] { null });
return value;
} catch (NoSuchMethodException e) {
throw new SalesforceException(String.format("SObject %s does not have a field %s", sObjectBase.getClass().getSimpleName(), propertyName), e);
} catch (InvocationTargetException e) {
throw new SalesforceException(String.format("Error getting/setting value %s.%s", sObjectBase.getClass().getSimpleName(), propertyName), e);
} catch (IllegalAccessException e) {
throw new SalesforceException(String.format("Error accessing value %s.%s", sObjectBase.getClass().getSimpleName(), propertyName), e);
}
}
use of org.apache.camel.component.salesforce.api.SalesforceException 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);
}
});
}
use of org.apache.camel.component.salesforce.api.SalesforceException in project camel by apache.
the class AnalyticsApiProcessor method processExecuteAsyncReport.
private void processExecuteAsyncReport(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
String reportId;
final Boolean includeDetails = getParameter(INCLUDE_DETAILS, exchange, IGNORE_BODY, IS_OPTIONAL, Boolean.class);
// try getting report metadata from body first
ReportMetadata reportMetadata = exchange.getIn().getBody(ReportMetadata.class);
if (reportMetadata != null) {
reportId = reportMetadata.getId();
if (reportId == null) {
reportId = getParameter(REPORT_ID, exchange, IGNORE_BODY, NOT_OPTIONAL);
}
} else {
reportId = getParameter(REPORT_ID, exchange, USE_BODY, NOT_OPTIONAL);
reportMetadata = getParameter(REPORT_METADATA, exchange, IGNORE_BODY, IS_OPTIONAL, ReportMetadata.class);
}
analyticsClient.executeAsyncReport(reportId, includeDetails, reportMetadata, new AnalyticsApiClient.ReportInstanceResponseCallback() {
@Override
public void onResponse(ReportInstance reportInstance, SalesforceException ex) {
processResponse(exchange, reportInstance, ex, callback);
}
});
}
use of org.apache.camel.component.salesforce.api.SalesforceException in project camel by apache.
the class AnalyticsApiProcessor method processExecuteSyncReport.
private void processExecuteSyncReport(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
String reportId;
final Boolean includeDetails = getParameter(INCLUDE_DETAILS, exchange, IGNORE_BODY, IS_OPTIONAL, Boolean.class);
// try getting report metadata from body first
ReportMetadata reportMetadata = exchange.getIn().getBody(ReportMetadata.class);
if (reportMetadata != null) {
reportId = reportMetadata.getId();
if (reportId == null) {
reportId = getParameter(REPORT_ID, exchange, IGNORE_BODY, NOT_OPTIONAL);
}
} else {
reportId = getParameter(REPORT_ID, exchange, USE_BODY, NOT_OPTIONAL);
reportMetadata = getParameter(REPORT_METADATA, exchange, IGNORE_BODY, IS_OPTIONAL, ReportMetadata.class);
}
analyticsClient.executeSyncReport(reportId, includeDetails, reportMetadata, new AnalyticsApiClient.ReportResultsResponseCallback() {
@Override
public void onResponse(AbstractReportResultsBase reportResults, SalesforceException ex) {
processResponse(exchange, reportResults, ex, callback);
}
});
}
Aggregations