diff options
Diffstat (limited to 'common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config')
-rw-r--r-- | common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/ConfigurationUtils.java | 81 |
1 files changed, 38 insertions, 43 deletions
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/ConfigurationUtils.java b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/ConfigurationUtils.java index e7a4c458dc..df382143c6 100644 --- a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/ConfigurationUtils.java +++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/ConfigurationUtils.java @@ -19,12 +19,30 @@ package org.onap.config; -import static java.util.Optional.ofNullable; -import static org.onap.config.api.Hint.EXTERNAL_LOOKUP; -import static org.onap.config.api.Hint.LATEST_LOOKUP; -import static org.onap.config.api.Hint.NODE_SPECIFIC; - import com.virtlink.commons.configuration2.jackson.JsonConfiguration; +import net.sf.corn.cps.CPScanner; +import net.sf.corn.cps.ResourceFilter; +import org.apache.commons.configuration2.Configuration; +import org.apache.commons.configuration2.CompositeConfiguration; +import org.apache.commons.configuration2.FileBasedConfiguration; +import org.apache.commons.configuration2.PropertiesConfiguration; +import org.apache.commons.configuration2.XMLConfiguration; +import org.apache.commons.configuration2.builder.BasicConfigurationBuilder; +import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder; +import org.apache.commons.configuration2.builder.ReloadingFileBasedConfigurationBuilder; +import org.apache.commons.configuration2.builder.fluent.Configurations; +import org.apache.commons.configuration2.builder.fluent.Parameters; +import org.apache.commons.configuration2.convert.DefaultListDelimiterHandler; +import org.apache.commons.configuration2.ex.ConfigurationException; +import org.apache.commons.io.IOUtils; +import org.onap.config.api.Config; +import org.onap.config.api.ConfigurationManager; +import org.onap.config.impl.YamlConfiguration; +import org.onap.config.type.ConfigurationMode; +import org.onap.config.type.ConfigurationType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.File; import java.lang.reflect.Field; import java.lang.reflect.ParameterizedType; @@ -58,28 +76,11 @@ import java.util.concurrent.TransferQueue; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; -import net.sf.corn.cps.CPScanner; -import net.sf.corn.cps.ResourceFilter; -import org.apache.commons.configuration2.CompositeConfiguration; -import org.apache.commons.configuration2.Configuration; -import org.apache.commons.configuration2.FileBasedConfiguration; -import org.apache.commons.configuration2.PropertiesConfiguration; -import org.apache.commons.configuration2.XMLConfiguration; -import org.apache.commons.configuration2.builder.BasicConfigurationBuilder; -import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder; -import org.apache.commons.configuration2.builder.ReloadingFileBasedConfigurationBuilder; -import org.apache.commons.configuration2.builder.fluent.Configurations; -import org.apache.commons.configuration2.builder.fluent.Parameters; -import org.apache.commons.configuration2.convert.DefaultListDelimiterHandler; -import org.apache.commons.configuration2.ex.ConfigurationException; -import org.apache.commons.io.IOUtils; -import org.onap.config.api.Config; -import org.onap.config.api.ConfigurationManager; -import org.onap.config.impl.YamlConfiguration; -import org.onap.config.type.ConfigurationMode; -import org.onap.config.type.ConfigurationType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import static java.util.Optional.ofNullable; +import static org.onap.config.api.Hint.EXTERNAL_LOOKUP; +import static org.onap.config.api.Hint.LATEST_LOOKUP; +import static org.onap.config.api.Hint.NODE_SPECIFIC; public class ConfigurationUtils { @@ -141,7 +142,7 @@ public class ConfigurationUtils { } return list.stream().filter(o -> o != null && !o.toString().trim().isEmpty()) - .map(o -> o.toString().trim()).collect(Collectors.joining(",")); + .map(o -> o.toString().trim()).collect(Collectors.joining(",")); } public static boolean isConfig(URL url) { @@ -179,12 +180,12 @@ public class ConfigurationUtils { private static Optional<String> readNamespace(Configuration config) { return ofNullable(config).flatMap(configuration -> ofNullable(configuration.getString(Constants.NAMESPACE_KEY))) - .map(String::toUpperCase); + .map(String::toUpperCase); } private static Optional<String> readMergeStrategy(Configuration config) { return ofNullable(config).flatMap(configuration -> ofNullable(configuration.getString(Constants.MODE_KEY))) - .map(String::toUpperCase); + .map(String::toUpperCase); } public static ConfigurationMode getMergeStrategy(File file) { @@ -313,7 +314,7 @@ public class ConfigurationUtils { public static boolean isWrapperClass(Class clazz) { return clazz == String.class || clazz == Boolean.class || clazz == Character.class - || Number.class.isAssignableFrom(clazz); + || Number.class.isAssignableFrom(clazz); } public static Class getArrayClass(Class clazz) { @@ -329,7 +330,7 @@ public class ConfigurationUtils { ConfigurationType configType = ConfigurationUtils.getConfigType(file); builder = getFileBasedConfigurationBuilder(configType); builder.configure(new Parameters().fileBased().setFile(file) - .setListDelimiterHandler(new DefaultListDelimiterHandler(','))); + .setListDelimiterHandler(new DefaultListDelimiterHandler(','))); return builder; } @@ -573,7 +574,7 @@ public class ConfigurationUtils { String moduleName = matcher.group(1).substring(1); return moduleName.equalsIgnoreCase(ConfigurationMode.OVERRIDE.name()) || moduleName.equalsIgnoreCase( ConfigurationMode.UNION.name()) || moduleName.equalsIgnoreCase(ConfigurationMode.MERGE.name()) - ? Constants.DEFAULT_NAMESPACE : moduleName; + ? Constants.DEFAULT_NAMESPACE : moduleName; } else { return Constants.DEFAULT_NAMESPACE; } @@ -593,21 +594,15 @@ public class ConfigurationUtils { } public static Object getProperty(Configuration config, String key, int processingHints) { - - if (!isDirectLookup(processingHints) && (config instanceof CompositeConfiguration)) { - + if (!isDirectLookup(processingHints) && isNodeSpecific(processingHints) && (config instanceof CompositeConfiguration)) { CompositeConfiguration conf = (CompositeConfiguration) config; for (int i = 0; i < conf.getNumberOfConfigurations(); i++) { - - if (isNodeSpecific(processingHints)) { - Object obj = conf.getConfiguration(i).getProperty(key); - if (obj != null) { - return obj; - } + Object obj = conf.getConfiguration(i).getProperty(key); + if (obj != null) { + return obj; } } } - return config.getProperty(key); } |