All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.azure.spring.messaging.eventhubs.implementation.properties.merger.ProducerPropertiesParentMerger Maven / Gradle / Ivy

There is a newer version: 6.0.0-beta.4
Show newest version
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.spring.messaging.eventhubs.implementation.properties.merger;

import com.azure.spring.cloud.core.implementation.util.AzurePropertiesUtils;
import com.azure.spring.cloud.core.implementation.properties.PropertyMapper;
import com.azure.spring.messaging.eventhubs.core.properties.NamespaceProperties;
import com.azure.spring.messaging.eventhubs.core.properties.ProducerProperties;
import com.azure.spring.cloud.service.implementation.core.PropertiesMerger;

/**
 * A merger used to merge a {@link ProducerProperties} with its parent {@link NamespaceProperties}. When a property is
 *  * set in the child, it will be kept. For those properties not set in the child, it will use the value in the
 *  parent.
 */
public class ProducerPropertiesParentMerger implements PropertiesMerger {

    @Override
    public ProducerProperties merge(ProducerProperties child, NamespaceProperties parent) {
        ProducerProperties properties = new ProducerProperties();
        if (child == null && parent == null) {
            return properties;
        }
        if (child == null) {
            child = new ProducerProperties();
        }
        if (parent == null) {
            parent = new NamespaceProperties();
        }

        PropertyMapper propertyMapper = new PropertyMapper();

        AzurePropertiesUtils.mergeAzureCommonProperties(parent, child, properties);

        propertyMapper.from(parent.getDomainName()).to(properties::setDomainName);
        propertyMapper.from(parent.getNamespace()).to(properties::setNamespace);
        propertyMapper.from(parent.getEventHubName()).to(properties::setEventHubName);
        propertyMapper.from(parent.getConnectionString()).to(properties::setConnectionString);
        propertyMapper.from(parent.getCustomEndpointAddress()).to(properties::setCustomEndpointAddress);

        propertyMapper.from(child.getDomainName()).to(properties::setDomainName);
        propertyMapper.from(child.getNamespace()).to(properties::setNamespace);
        propertyMapper.from(child.getEventHubName()).to(properties::setEventHubName);
        propertyMapper.from(child.getConnectionString()).to(properties::setConnectionString);
        propertyMapper.from(child.getCustomEndpointAddress()).to(properties::setCustomEndpointAddress);

        return properties;

    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy