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

com.icthh.xm.commons.config.client.api.refreshable.MapRefreshableConfiguration Maven / Gradle / Ivy

There is a newer version: 4.0.18
Show newest version
package com.icthh.xm.commons.config.client.api.refreshable;

import com.icthh.xm.commons.tenant.TenantContextHolder;
import org.springframework.beans.factory.annotation.Value;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.icthh.xm.commons.config.client.utils.Utils.nullSafeList;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.toMap;

public abstract class MapRefreshableConfiguration
    extends SimpleConfigItemClassRefreshableConfiguration, CONFIG_FILE> {

    public MapRefreshableConfiguration(@Value("${spring.application.name}") String appName,
                                       TenantContextHolder tenantContextHolder) {
        super(appName, tenantContextHolder);
    }

    @Override
    public final Map joinTenantConfiguration(List files) {
        Map map = new HashMap<>();
        files.stream().map(this::toConfigItems)
            .map(nullSafeList())
            .flatMap(List::stream)
            .forEach(it -> map.put(it.getKey(), it)); //collect throw exception on key duplication
        return map;
    }

    @Override
    protected Map getConfiguration(String tenantKey) {
        Map configuration = super.getConfiguration(tenantKey);
        return configuration == null ? Map.of() : configuration;
    }

    protected abstract List toConfigItems(CONFIG_FILE config);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy