use of io.syndesis.common.model.action.ConnectorAction in project syndesis by syndesisio.
the class ActiveMQConnectorTestSupport method newActiveMQEndpointStep.
// **************************
// Helpers
// **************************
protected Step newActiveMQEndpointStep(String actionId, Consumer<Step.Builder> consumer) {
final Connector connector = getResourceManager().mandatoryLoadConnector("activemq");
final ConnectorAction action = getResourceManager().mandatoryLookupAction(connector, actionId);
final Step.Builder builder = new Step.Builder().stepKind(StepKind.endpoint).action(action).connection(new io.syndesis.common.model.connection.Connection.Builder().connector(connector).putConfiguredProperty("brokerUrl", broker.getVmURL()).build());
consumer.accept(builder);
return builder.build();
}
use of io.syndesis.common.model.action.ConnectorAction in project syndesis by syndesisio.
the class DataShapeCustomizerTest method setUpComponent.
// ********************
//
// ********************
protected ComponentProxyComponent setUpComponent(String actionId) {
Connector connector = mandatoryLookupConnector();
ConnectorAction action = mandatoryLookupAction(connector, actionId);
ComponentProxyComponent component = new ComponentProxyComponent("salesforce-1", "salesforce");
component.setBeforeProducer(BEFORE_PROCESSOR);
component.setAfterProducer(AFTER_PROCESSOR);
DataShapeCustomizer customizer = new DataShapeCustomizer();
customizer.setCamelContext(context());
action.getDescriptor().getInputDataShape().ifPresent(customizer::setInputDataShape);
action.getDescriptor().getOutputDataShape().ifPresent(customizer::setOutputDataShape);
customizer.customize(component, Collections.emptyMap());
return component;
}
use of io.syndesis.common.model.action.ConnectorAction in project syndesis by syndesisio.
the class BaseSwaggerConnectorGenerator method configureConnector.
protected final Connector configureConnector(final ConnectorTemplate connectorTemplate, final Connector connector, final ConnectorSettings connectorSettings) {
final Connector.Builder builder = new Connector.Builder().createFrom(connector);
final SwaggerModelInfo info = parseSpecification(connectorSettings, false);
final Swagger swagger = info.getModel();
addGlobalParameters(builder, swagger);
final Map<String, Path> paths = swagger.getPaths();
final String connectorId = connector.getId().get();
final String connectorGav = connectorTemplate.getCamelConnectorGAV();
final String connectorScheme = connectorTemplate.getCamelConnectorPrefix();
final List<ConnectorAction> actions = new ArrayList<>();
int idx = 0;
for (final Entry<String, Path> pathEntry : paths.entrySet()) {
final Path path = pathEntry.getValue();
final Map<HttpMethod, Operation> operationMap = path.getOperationMap();
for (final Entry<HttpMethod, Operation> entry : operationMap.entrySet()) {
final Operation operation = entry.getValue();
if (operation.getOperationId() == null) {
operation.operationId("operation-" + idx++);
}
final ConnectorDescriptor descriptor = //
createDescriptor(info.getResolvedSpecification(), swagger, operation).camelConnectorGAV(//
connectorGav).camelConnectorPrefix(//
connectorScheme).connectorId(//
connectorId).build();
final OperationDescription description = SwaggerHelper.operationDescriptionOf(swagger, operation);
final ConnectorAction action = //
new ConnectorAction.Builder().id(//
createActionId(connectorId, connectorGav, operation)).name(//
description.name).description(//
description.description).pattern(//
Action.Pattern.To).descriptor(descriptor).tags(//
ofNullable(operation.getTags()).orElse(Collections.emptyList())).build();
actions.add(action);
}
}
actions.sort(ActionComparator.INSTANCE);
builder.addAllActions(actions);
builder.putConfiguredProperty("specification", SwaggerHelper.serialize(swagger));
return builder.build();
}
use of io.syndesis.common.model.action.ConnectorAction 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);
}
use of io.syndesis.common.model.action.ConnectorAction in project syndesis by syndesisio.
the class SimpleEndpointStepHandler method handle.
@SuppressWarnings({ "unchecked", "PMD" })
@Override
public Optional<ProcessorDefinition> handle(Step step, ProcessorDefinition route, IntegrationRouteBuilder builder, final String index) {
// Model
final ConnectorAction action = step.getActionAs(ConnectorAction.class).get();
final ConnectorDescriptor descriptor = action.getDescriptor();
// Camel
final String componentScheme = action.getDescriptor().getComponentScheme().get();
final Map<String, String> configuredProperties = step.getConfiguredProperties();
final Map<String, String> properties = action.filterEndpointProperties(configuredProperties);
properties.entrySet().stream().filter(action::isEndpointProperty).filter(action::isSecret).forEach(e -> e.setValue(String.format("{{%s-%s.%s}}", componentScheme, index, e.getKey())));
// raw values.
properties.entrySet().stream().filter(action::isRaw).forEach(e -> e.setValue(String.format("RAW(%s)", e.getValue())));
// any configuredProperties on action descriptor are considered
properties.putAll(descriptor.getConfiguredProperties());
try {
final RuntimeCamelCatalog catalog = builder.getContext().getRuntimeCamelCatalog();
final String uri = catalog.asEndpointUri(componentScheme, Map.class.cast(properties), false);
if (route == null) {
route = builder.from(uri);
} else {
route = route.to(uri);
}
} catch (URISyntaxException e) {
throw ObjectHelper.wrapRuntimeCamelException(e);
}
return Optional.ofNullable(route);
}
Aggregations