Search in sources :

Example 1 with ConfigurationProperty

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();
}
Also used : ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) Connector(io.syndesis.common.model.connection.Connector) Swagger(io.swagger.models.Swagger)

Example 2 with ConfigurationProperty

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);
}
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 3 with ConfigurationProperty

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);
}
Also used : SwaggerParser(io.swagger.parser.SwaggerParser) ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) Swagger(io.swagger.models.Swagger) Parameter(io.swagger.models.parameters.Parameter) Test(org.junit.Test)

Example 4 with ConfigurationProperty

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);
}
Also used : ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) Connection(io.syndesis.common.model.connection.Connection) Date(java.util.Date)

Example 5 with ConfigurationProperty

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]})");
}
Also used : ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) HttpHeaders(org.springframework.http.HttpHeaders) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) Test(org.junit.Test)

Aggregations

ConfigurationProperty (io.syndesis.common.model.connection.ConfigurationProperty)10 Connection (io.syndesis.common.model.connection.Connection)4 Connector (io.syndesis.common.model.connection.Connector)4 Map (java.util.Map)4 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)3 ConnectorDescriptor (io.syndesis.common.model.action.ConnectorDescriptor)3 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 Swagger (io.swagger.models.Swagger)2 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 DefaultMustacheFactory (com.github.mustachejava.DefaultMustacheFactory)1 Mustache (com.github.mustachejava.Mustache)1 MustacheFactory (com.github.mustachejava.MustacheFactory)1 MapDifference (com.google.common.collect.MapDifference)1 Parameter (io.swagger.models.parameters.Parameter)1 SwaggerParser (io.swagger.parser.SwaggerParser)1 Dependency (io.syndesis.common.model.Dependency)1 WithConfiguredProperties (io.syndesis.common.model.WithConfiguredProperties)1 LeveledMessage (io.syndesis.common.model.bulletin.LeveledMessage)1 ConnectorGroup (io.syndesis.common.model.connection.ConnectorGroup)1