private Connector migrateOldConnectorData(Connector existingConnector, Connector newConnector) { Map<String, String> propValues = new TreeMap<>(existingConnector.getConfiguredProperties()); propValues.keySet().retainAll(newConnector.getProperties().keySet()); if (!propValues.isEmpty()) { return new Connector.Builder() .createFrom(newConnector) .putAllConfiguredProperties(propValues) .build(); } return newConnector; }
@SuppressWarnings("unchecked") private io.syndesis.integration.model.steps.Step createConnector(StepVisitorContext visitorContext, Step step, Connection connection, Connector connector, ConnectorAction action) { final Map<String, String> properties = aggregate(connection.getConfiguredProperties(), step.getConfiguredProperties()); final String scheme = Optionals.first(action.getDescriptor().getComponentScheme(), connector.getComponentScheme()).get(); // if the option is marked as secret use property placeholder as the // value is added to the integration secret. if (visitorContext.getGeneratorContext().getGeneratorProperties().isSecretMaskingEnabled()) { properties.entrySet() .stream() .filter(Predicates.or(connector::isSecret, action::isSecret)) .forEach(e -> e.setValue(String.format("{{%s-%d.%s}}", scheme, visitorContext.getIndex(), e.getKey()))); } //Connector/Action properties have the precedence connector.getConfiguredProperties().forEach(properties::put); action.getDescriptor().getConfiguredProperties().forEach(properties::put); return new io.syndesis.camel.component.proxy.runtime.Connector( scheme + "-" + visitorContext.getIndex(), scheme, Map.class.cast(properties), Optionals.first(action.getDescriptor().getConnectorFactory(), connector.getConnectorFactory()).orElse(null), action.getDescriptor().getConnectorCustomizers() ); }
connector.getConfiguredProperties().forEach(properties::put); descriptor.getConfiguredProperties().forEach(properties::put);
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(); }
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(); }
@Test public void shouldIncorporateGivenConfiguredProperties() throws IOException { final String specification = resource("/swagger/reverb.swagger.yaml"); final ConnectorSettings connectorSettings = new ConnectorSettings.Builder()// .name("Reverb API")// .description("Invokes Reverb API")// .icon("fa-music")// .putConfiguredProperty("specification", specification)// .putConfiguredProperty("tokenEndpoint", "http://some.token.url").build(); final Connector connector = generator.generate(SWAGGER_TEMPLATE, connectorSettings); assertThat(connector.getConfiguredProperties()).containsEntry("tokenEndpoint", "http://some.token.url"); }
final Map<String, String> generatedConfiguredProperties = generated.getConfiguredProperties(); final String generatedSpecification = generatedConfiguredProperties.get("specification"); final Map<String, String> expectedConfiguredProperties = expected.getConfiguredProperties(); final String expectedSpecification = expectedConfiguredProperties.get("specification"); assertThat(reformatJson(generatedSpecification)).isEqualTo(reformatJson(expectedSpecification));