use of io.syndesis.common.model.connection.ConfigurationProperty in project syndesis by syndesisio.
the class BaseSwaggerConnectorGenerator method basicConnector.
protected final Connector basicConnector(final ConnectorTemplate connectorTemplate, final ConnectorSettings connectorSettings) {
final Swagger swagger = parseSpecification(connectorSettings, false).getModel();
// could be either JSON of the Swagger specification or a URL to one
final String specification = requiredSpecification(connectorSettings);
if (specification.startsWith("http")) {
swagger.vendorExtension(URL_EXTENSION, URI.create(specification));
}
final Connector baseConnector = baseConnectorFrom(connectorTemplate, connectorSettings);
final Connector.Builder builder = new Connector.Builder().createFrom(baseConnector);
final Map<String, String> alreadyConfiguredProperties = builder.build().getConfiguredProperties();
connectorTemplate.getConnectorProperties().forEach((propertyName, template) -> {
final Optional<ConfigurationProperty> maybeProperty = PropertyGenerators.createProperty(propertyName, swagger, template);
maybeProperty.ifPresent(property -> {
builder.putProperty(propertyName, property);
if (!alreadyConfiguredProperties.containsKey(propertyName)) {
final String defaultValue = property.getDefaultValue();
if (defaultValue != null) {
builder.putConfiguredProperty(propertyName, defaultValue);
}
}
});
});
return builder.build();
}
use of io.syndesis.common.model.connection.ConfigurationProperty 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.connection.ConfigurationProperty in project syndesis by syndesisio.
the class BaseSwaggerConnectorGeneratorTest method shouldCreatePropertyParametersFromPetstoreSwagger.
@Test
public void shouldCreatePropertyParametersFromPetstoreSwagger() throws IOException {
final String specification = resource("/swagger/petstore.swagger.json");
final Swagger swagger = new SwaggerParser().parse(specification);
final Parameter petIdPathParameter = swagger.getPath("/pet/{petId}").getGet().getParameters().get(0);
final Optional<ConfigurationProperty> maybeConfigurationProperty = BaseSwaggerConnectorGenerator.createPropertyFromParameter(petIdPathParameter);
final ConfigurationProperty expected = //
new ConfigurationProperty.Builder().componentProperty(//
false).deprecated(//
false).description(//
"ID of pet to return").displayName(//
"petId").group(//
"producer").javaType(//
Long.class.getName()).kind(//
"property").required(//
true).secret(//
false).type(//
"integer").build();
assertThat(maybeConfigurationProperty).hasValue(expected);
}
use of io.syndesis.common.model.connection.ConfigurationProperty in project syndesis by syndesisio.
the class ConnectionHandler method update.
@Override
public void update(final String id, @ConvertGroup(from = Default.class, to = AllValidations.class) final Connection connection) {
// Lets make sure we store encrypt secrets.
Map<String, String> configuredProperties = connection.getConfiguredProperties();
Map<String, ConfigurationProperty> connectorProperties = getConnectorProperties(connection.getConnectorId());
configuredProperties = encryptionComponent.encryptPropertyValues(configuredProperties, connectorProperties);
final Connection updatedConnection = new Connection.Builder().createFrom(connection).configuredProperties(configuredProperties).lastUpdated(new Date()).build();
Updater.super.update(id, updatedConnection);
}
use of io.syndesis.common.model.connection.ConfigurationProperty in project syndesis by syndesisio.
the class DynamicActionSqlStoredITCase method shouldOfferDynamicActionPropertySuggestions.
@Test
public void shouldOfferDynamicActionPropertySuggestions() {
final HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
final ResponseEntity<ConnectorDescriptor> firstResponse = http(HttpMethod.POST, "/api/v1/connections/" + connectionId + "/actions/sql-stored-connector", null, ConnectorDescriptor.class, tokenRule.validToken(), headers, HttpStatus.OK);
ConfigurationProperty procedureNames = firstResponse.getBody().getPropertyDefinitionSteps().iterator().next().getProperties().get("procedureName");
assertThat(procedureNames.getEnum()).hasSize(2);
assertThat(procedureNames.getEnum().iterator().next().getLabel()).startsWith("DEMO_ADD");
final ResponseEntity<ConnectorDescriptor> secondResponse = http(HttpMethod.POST, "/api/v1/connections/" + connectionId + "/actions/sql-stored-connector", Collections.singletonMap("procedureName", "DEMO_ADD"), ConnectorDescriptor.class, tokenRule.validToken(), headers, HttpStatus.OK);
final Map<String, ConfigurationProperty> secondRequestProperties = secondResponse.getBody().getPropertyDefinitionSteps().get(0).getProperties();
assertThat(secondRequestProperties.get("template").getDefaultValue()).isEqualTo("DEMO_ADD(INTEGER ${body[A]}, INTEGER ${body[B]}, INTEGER ${body[C]})");
}
Aggregations