Search in sources :

Example 1 with TestConnectionGlobalElementModelProperty

use of org.mule.runtime.config.internal.dsl.model.extension.xml.property.TestConnectionGlobalElementModelProperty in project mule by mulesoft.

the class XmlExtensionLoaderDelegate method addConnectionProvider.

/**
 * Adds a connection provider if (a) there's at least one global element that has test connection or (b) there's at least one
 * <property/> that has been placed within a <connection/> wrapper in the <module/> element.
 *
 * @param configurationDeclarer declarer to add the {@link ConnectionProviderDeclarer} if applies.
 * @param connectionProperties collection of <property/>s that should be added to the {@link ConnectionProviderDeclarer}.
 * @param globalElementsComponentModel collection of global elements where through {@link #getTestConnectionGlobalElement(List, Set)}
 *                                     will look for one that supports test connectivity.
 * @param extensions used also in {@link #getTestConnectionGlobalElement(List, Set)}, through the {@link #findTestConnectionGlobalElementFrom},
 *                   as the XML of the extensions might change of the values that the {@link ExtensionModel} has (heavily relies
 *                   on {@link DslSyntaxResolver#resolve(NamedObject)}).
 */
private void addConnectionProvider(ConfigurationDeclarer configurationDeclarer, List<ComponentModel> connectionProperties, List<ComponentModel> globalElementsComponentModel, Set<ExtensionModel> extensions) {
    final Optional<ComponentModel> testConnectionGlobalElementOptional = getTestConnectionGlobalElement(globalElementsComponentModel, extensions);
    if (testConnectionGlobalElementOptional.isPresent() || !connectionProperties.isEmpty()) {
        final ConnectionProviderDeclarer connectionProviderDeclarer = configurationDeclarer.withConnectionProvider(MODULE_CONNECTION_GLOBAL_ELEMENT_NAME);
        connectionProviderDeclarer.withConnectionManagementType(ConnectionManagementType.NONE);
        connectionProperties.stream().forEach(param -> extractProperty(connectionProviderDeclarer, param));
        testConnectionGlobalElementOptional.ifPresent(testConnectionGlobalElement -> {
            final String testConnectionGlobalElementName = testConnectionGlobalElement.getParameters().get(GLOBAL_ELEMENT_NAME_ATTRIBUTE);
            connectionProviderDeclarer.withModelProperty(new TestConnectionGlobalElementModelProperty(testConnectionGlobalElementName));
        });
        // TODO until MULE-12734, all test connection must be shut down in smart connectors
        connectionProviderDeclarer.supportsConnectivityTesting(false);
    }
}
Also used : TestConnectionGlobalElementModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.TestConnectionGlobalElementModelProperty) ConnectionProviderDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConnectionProviderDeclarer) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel)

Aggregations

ConnectionProviderDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.ConnectionProviderDeclarer)1 TestConnectionGlobalElementModelProperty (org.mule.runtime.config.internal.dsl.model.extension.xml.property.TestConnectionGlobalElementModelProperty)1 ComponentModel (org.mule.runtime.config.internal.model.ComponentModel)1