Search in sources :

Example 1 with ComponentProxyCustomizer

use of io.syndesis.integration.component.proxy.ComponentProxyCustomizer in project syndesis by syndesisio.

the class ConnectorStepHandler method handle.

@SuppressWarnings("PMD")
@Override
public Optional<ProcessorDefinition> handle(Step step, ProcessorDefinition route, IntegrationRouteBuilder builder, final String index) {
    // Model
    final Connection connection = step.getConnection().get();
    final Connector connector = connection.getConnector().get();
    final ConnectorAction action = step.getActionAs(ConnectorAction.class).get();
    final ConnectorDescriptor descriptor = action.getDescriptor();
    // Camel
    final String scheme = Optionals.first(descriptor.getComponentScheme(), connector.getComponentScheme()).get();
    final CamelContext context = builder.getContext();
    final String componentId = scheme + "-" + index;
    final ComponentProxyComponent component = resolveComponent(componentId, scheme, context, connector, descriptor);
    final List<String> customizers = CollectionsUtils.aggregate(ArrayList::new, connector.getConnectorCustomizers(), descriptor.getConnectorCustomizers());
    final Map<String, String> properties = CollectionsUtils.aggregate(connection.getConfiguredProperties(), step.getConfiguredProperties());
    final Map<String, ConfigurationProperty> configurationProperties = CollectionsUtils.aggregate(connector.getProperties(), action.getProperties());
    // Workaround for https://github.com/syndesisio/syndesis/issues/1713
    for (Map.Entry<String, ConfigurationProperty> entry : configurationProperties.entrySet()) {
        if (ObjectHelper.isNotEmpty(entry.getValue().getDefaultValue())) {
            properties.putIfAbsent(entry.getKey(), entry.getValue().getDefaultValue());
        }
    }
    // if the option is marked as secret use property placeholder as the
    // value is added to the integration secret.
    properties.entrySet().stream().filter(Predicates.or(connector::isSecret, action::isSecret)).forEach(e -> e.setValue(String.format("{{%s-%s.%s}}", scheme, index, e.getKey())));
    // raw values.
    properties.entrySet().stream().filter(Predicates.or(connector::isRaw, action::isRaw)).forEach(e -> e.setValue(String.format("RAW(%s)", e.getValue())));
    // Connector/Action properties have the precedence
    connector.getConfiguredProperties().forEach(properties::put);
    descriptor.getConfiguredProperties().forEach(properties::put);
    try {
        final Map<String, Object> proxyProperties = new HashMap<>(properties);
        // Set input/output data shape if the component proxy implements
        // Input/OutputDataShapeAware
        descriptor.getInputDataShape().ifPresent(ds -> trySetInputDataShape(component, ds));
        descriptor.getOutputDataShape().ifPresent(ds -> trySetOutputDataShape(component, ds));
        // Try to set properties to the component
        setProperties(context, component, proxyProperties);
        for (String customizerType : customizers) {
            final ComponentProxyCustomizer customizer = resolveCustomizer(context, customizerType);
            // Set the camel context if the customizer implements
            // the CamelContextAware interface.
            ObjectHelper.trySetCamelContext(customizer, context);
            // Set input/output data shape if the customizer implements
            // Input/OutputDataShapeAware
            descriptor.getInputDataShape().ifPresent(ds -> trySetInputDataShape(customizer, ds));
            descriptor.getOutputDataShape().ifPresent(ds -> trySetOutputDataShape(customizer, ds));
            // Try to set properties to the component
            setProperties(context, customizer, proxyProperties);
            // Invoke the customizer
            customizer.customize(component, proxyProperties);
        }
        component.setCamelContext(context);
        component.setOptions(proxyProperties);
        // Remove component
        context.removeComponent(component.getComponentId());
        context.removeService(component);
        // Register component
        context.addService(component, true, true);
        context.addComponent(component.getComponentId(), component);
        if (route == null) {
            route = builder.from(componentId);
        } else {
            route = route.to(componentId);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return Optional.ofNullable(route);
}
Also used : CamelContext(org.apache.camel.CamelContext) ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) Connector(io.syndesis.common.model.connection.Connector) ComponentProxyComponent(io.syndesis.integration.component.proxy.ComponentProxyComponent) ComponentProxyCustomizer(io.syndesis.integration.component.proxy.ComponentProxyCustomizer) HashMap(java.util.HashMap) Connection(io.syndesis.common.model.connection.Connection) ArrayList(java.util.ArrayList) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ComponentProxyCustomizer

use of io.syndesis.integration.component.proxy.ComponentProxyCustomizer in project syndesis by syndesisio.

the class ConnectorStepHandler method resolveCustomizer.

private ComponentProxyCustomizer resolveCustomizer(CamelContext context, String customizerType) {
    Class<ComponentProxyCustomizer> type = context.getClassResolver().resolveClass(customizerType, ComponentProxyCustomizer.class);
    if (type == null) {
        throw new IllegalArgumentException("Unable to resolve a ComponentProxyCustomizer of type: " + customizerType);
    }
    final ComponentProxyCustomizer customizer = context.getInjector().newInstance(type);
    if (customizer == null) {
        throw new IllegalArgumentException("Unable to instantiate a ComponentProxyCustomizer of type: " + customizerType);
    }
    return customizer;
}
Also used : ComponentProxyCustomizer(io.syndesis.integration.component.proxy.ComponentProxyCustomizer)

Aggregations

ComponentProxyCustomizer (io.syndesis.integration.component.proxy.ComponentProxyCustomizer)2 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)1 ConnectorDescriptor (io.syndesis.common.model.action.ConnectorDescriptor)1 ConfigurationProperty (io.syndesis.common.model.connection.ConfigurationProperty)1 Connection (io.syndesis.common.model.connection.Connection)1 Connector (io.syndesis.common.model.connection.Connector)1 ComponentProxyComponent (io.syndesis.integration.component.proxy.ComponentProxyComponent)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CamelContext (org.apache.camel.CamelContext)1