use of io.syndesis.common.model.WithConfiguredProperties in project syndesis by syndesisio.
the class ProjectGenerator method generateApplicationProperties.
@SuppressWarnings("PMD")
@Override
public Properties generateApplicationProperties(final Integration integrationDefinition) {
final Integration integration = sanitize(integrationDefinition, resourceManager);
final Properties properties = new Properties();
final List<? extends Step> steps = integration.getSteps();
for (int i = 0; i < steps.size(); i++) {
final Step step = steps.get(i);
// Check if a step is of supported type.
if (StepKind.endpoint != step.getStepKind()) {
continue;
}
// Check if a step has the required options
if (step.getAction().filter(ConnectorAction.class::isInstance).isPresent() && step.getConnection().isPresent()) {
final String index = Integer.toString(i + 1);
final Connection connection = step.getConnection().get();
final ConnectorAction action = ConnectorAction.class.cast(step.getAction().get());
final ConnectorDescriptor descriptor = action.getDescriptor();
final Connector connector = resourceManager.loadConnector(connection).orElseThrow(() -> new IllegalArgumentException("No connector with id: " + connection.getConnectorId()));
if (connector.getComponentScheme().isPresent() || descriptor.getComponentScheme().isPresent()) {
// Grab the component scheme from the component descriptor or
// from the connector
final String componentScheme = Optionals.first(descriptor.getComponentScheme(), connector.getComponentScheme()).get();
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 (entry.getValue() != null && entry.getValue().getDefaultValue() != null && !entry.getValue().getDefaultValue().isEmpty()) {
if (connector.isSecret(entry.getKey()) || action.isSecret(entry.getKey())) {
addDecryptedKeyProperty(properties, index, componentScheme, entry.getKey(), entry.getValue().getDefaultValue());
}
}
}
for (Map.Entry<String, String> entry : connection.getConfiguredProperties().entrySet()) {
if (connector.isSecret(entry) || action.isSecret(entry)) {
addDecryptedKeyProperty(properties, index, componentScheme, entry.getKey(), entry.getValue());
}
}
for (Map.Entry<String, String> entry : step.getConfiguredProperties().entrySet()) {
if (connector.isSecret(entry) || action.isSecret(entry)) {
addDecryptedKeyProperty(properties, index, componentScheme, entry.getKey(), entry.getValue());
}
}
} else {
// The component scheme is defined as camel connector prefix
// for 'old' style connectors.
final String componentScheme = descriptor.getCamelConnectorPrefix();
// endpoint secrets
Stream.of(connector, connection, step).filter(WithConfiguredProperties.class::isInstance).map(WithConfiguredProperties.class::cast).map(WithConfiguredProperties::getConfiguredProperties).flatMap(map -> map.entrySet().stream()).filter(Predicates.or(connector::isEndpointProperty, action::isEndpointProperty)).filter(Predicates.or(connector::isSecret, action::isSecret)).forEach(e -> {
addDecryptedKeyProperty(properties, index, componentScheme, e.getKey(), e.getValue());
});
// Component properties triggers connectors aliasing so we
// can have multiple instances of the same connectors
Stream.of(connector, connection, step).filter(WithConfiguredProperties.class::isInstance).map(WithConfiguredProperties.class::cast).map(WithConfiguredProperties::getConfiguredProperties).flatMap(map -> map.entrySet().stream()).filter(Predicates.or(connector::isComponentProperty, action::isComponentProperty)).forEach(e -> {
String propKeyPrefix = String.format("%s.configurations.%s", componentScheme, componentScheme);
addDecryptedKeyProperty(properties, index, propKeyPrefix, e.getKey(), e.getValue());
});
}
}
}
return properties;
}
Aggregations