Search in sources :

Example 1 with OperationName

use of org.apache.camel.component.salesforce.internal.OperationName in project camel by apache.

the class SalesforceComponent method createEndpoint.

protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    // get Operation from remaining URI
    OperationName operationName = null;
    String topicName = null;
    String apexUrl = null;
    try {
        LOG.debug("Creating endpoint for: {}", remaining);
        if (remaining.startsWith(APEX_CALL_PREFIX)) {
            // extract APEX URL
            apexUrl = remaining.substring(APEX_CALL_PREFIX.length());
            remaining = OperationName.APEX_CALL.value();
        }
        operationName = OperationName.fromValue(remaining);
    } catch (IllegalArgumentException ex) {
        // if its not an operation name, treat is as topic name for consumer endpoints
        topicName = remaining;
    }
    // create endpoint config
    if (config == null) {
        config = new SalesforceEndpointConfig();
    }
    if (config.getHttpClient() == null) {
        // set the component's httpClient as default
        config.setHttpClient(httpClient);
    }
    // create a deep copy and map parameters
    final SalesforceEndpointConfig copy = config.copy();
    setProperties(copy, parameters);
    // set apexUrl in endpoint config
    if (apexUrl != null) {
        copy.setApexUrl(apexUrl);
    }
    final SalesforceEndpoint endpoint = new SalesforceEndpoint(uri, this, copy, operationName, topicName);
    // map remaining parameters to endpoint (specifically, synchronous)
    setProperties(endpoint, parameters);
    // if operation is APEX call, map remaining parameters to query params
    if (operationName == OperationName.APEX_CALL && !parameters.isEmpty()) {
        Map<String, Object> queryParams = new HashMap<String, Object>(copy.getApexQueryParams());
        // override component params with endpoint params
        queryParams.putAll(parameters);
        parameters.clear();
        copy.setApexQueryParams(queryParams);
    }
    return endpoint;
}
Also used : OperationName(org.apache.camel.component.salesforce.internal.OperationName) HashMap(java.util.HashMap)

Example 2 with OperationName

use of org.apache.camel.component.salesforce.internal.OperationName in project camel by apache.

the class JsonRestProcessorTest method getRequestStream.

@Test
public void getRequestStream() throws Exception {
    SalesforceComponent comp = new SalesforceComponent();
    SalesforceEndpointConfig conf = new SalesforceEndpointConfig();
    OperationName op = OperationName.CREATE_BATCH;
    SalesforceEndpoint endpoint = new SalesforceEndpoint("", comp, conf, op, "");
    JsonRestProcessor jsonRestProcessor = new JsonRestProcessor(endpoint);
    DefaultCamelContext context = new DefaultCamelContext();
    Exchange exchange = new DefaultExchange(context, ExchangePattern.InOut);
    TestObject doc = new TestObject();
    doc.setCreationDate(ZonedDateTime.of(1717, 1, 2, 3, 4, 5, 6, ZoneId.systemDefault()));
    exchange.getIn().setBody(doc);
    ByteArrayInputStream is = (ByteArrayInputStream) jsonRestProcessor.getRequestStream(exchange);
    String result = IOUtils.toString(is);
    assertThat(result, result.length() <= 48, Is.is(true));
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) SalesforceEndpoint(org.apache.camel.component.salesforce.SalesforceEndpoint) OperationName(org.apache.camel.component.salesforce.internal.OperationName) ByteArrayInputStream(java.io.ByteArrayInputStream) SalesforceEndpointConfig(org.apache.camel.component.salesforce.SalesforceEndpointConfig) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) SalesforceComponent(org.apache.camel.component.salesforce.SalesforceComponent) Test(org.junit.Test)

Example 3 with OperationName

use of org.apache.camel.component.salesforce.internal.OperationName in project camel by apache.

the class SalesforceComponent method completeEndpointPath.

@Override
public List<String> completeEndpointPath(ComponentConfiguration configuration, String completionText) {
    final List<String> result = new ArrayList<String>();
    // return operations names on empty completion text
    final boolean empty = ObjectHelper.isEmpty(completionText);
    if (empty || completionText.indexOf('?') == -1) {
        if (empty) {
            completionText = "";
        }
        final OperationName[] values = OperationName.values();
        for (OperationName val : values) {
            final String strValue = val.value();
            if (strValue.startsWith(completionText)) {
                result.add(strValue);
            }
        }
        // also add place holder for user defined push topic name for empty completionText
        if (empty) {
            result.add("[PushTopicName]");
        }
    } else {
        // handle package parameters
        if (completionText.matches("^.*[\\?&]sObjectName=$")) {
            result.addAll(classMap.keySet());
        } else if (completionText.matches("^.*[\\?&]sObjectFields=$")) {
            // find sObjectName from configuration or completionText
            String sObjectName = (String) configuration.getParameter("sObjectName");
            if (sObjectName == null) {
                final Matcher matcher = SOBJECT_NAME_PATTERN.matcher(completionText);
                if (matcher.matches()) {
                    sObjectName = matcher.group(1);
                }
            }
            // return all fields of sObject
            if (sObjectName != null) {
                final Class<?> aClass = classMap.get(sObjectName);
                ReflectionHelper.doWithFields(aClass, new ReflectionHelper.FieldCallback() {

                    @Override
                    public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
                        // get non-static fields
                        if ((field.getModifiers() & Modifier.STATIC) == 0) {
                            result.add(field.getName());
                        }
                    }
                });
            }
        } else if (completionText.matches("^.*[\\?&]sObjectClass=$")) {
            for (Class c : classMap.values()) {
                result.add(c.getName());
            }
            // also add Query records classes
            Set<Class<?>> classes = getCamelContext().getPackageScanClassResolver().findImplementations(AbstractQueryRecordsBase.class, packages);
            for (Class<?> aClass : classes) {
                // findImplementations also returns AbstractQueryRecordsBase for some reason!!!
                if (AbstractQueryRecordsBase.class != aClass) {
                    result.add(aClass.getName());
                }
            }
        }
    }
    return result;
}
Also used : Field(java.lang.reflect.Field) OperationName(org.apache.camel.component.salesforce.internal.OperationName) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList)

Aggregations

OperationName (org.apache.camel.component.salesforce.internal.OperationName)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Matcher (java.util.regex.Matcher)1 Exchange (org.apache.camel.Exchange)1 SalesforceComponent (org.apache.camel.component.salesforce.SalesforceComponent)1 SalesforceEndpoint (org.apache.camel.component.salesforce.SalesforceEndpoint)1 SalesforceEndpointConfig (org.apache.camel.component.salesforce.SalesforceEndpointConfig)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 DefaultExchange (org.apache.camel.impl.DefaultExchange)1 Test (org.junit.Test)1