Fixed sonar issues in ConfigurationRepository
Fixing sonar issues in onap-configuration-management-core project
Issue-ID: SDC-2390
Signed-off-by: Piotr Borelowski <p.borelowski@partner.samsung.com>
Signed-off-by: Krystian Kedron <k.kedron@partner.samsung.com>
Change-Id: I2814b189eb53f53ab94295ff6bba76d118616800
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/pom.xml b/common/onap-common-configuration-management/onap-configuration-management-core/pom.xml
index 83b5ac7..2c7fd00 100755
--- a/common/onap-common-configuration-management/onap-configuration-management-core/pom.xml
+++ b/common/onap-common-configuration-management/onap-configuration-management-core/pom.xml
@@ -105,7 +105,14 @@
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.openecomp.sdc</groupId>
+ <artifactId>openecomp-sdc-logging-api</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
</dependencies>
+
<build>
<plugins>
<plugin>
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationRepository.java b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationRepository.java
index 63c3b75..7b2e267 100644
--- a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationRepository.java
+++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationRepository.java
@@ -1,5 +1,6 @@
/*
* Copyright © 2016-2018 European Support Limited
+ * Modifications Copyright (c) 2019 Samsung
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,9 +33,12 @@
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder;
import org.onap.config.ConfigurationUtils;
import org.onap.config.Constants;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
public final class ConfigurationRepository {
+ private static final Logger logger = LoggerFactory.getLogger(ConfigurationRepository.class);
private static final ConfigurationRepository REPO = new ConfigurationRepository();
private final Set<String> tenants = Collections.synchronizedSet(new HashSet<>());
@@ -49,14 +53,14 @@
protected boolean removeEldestEntry(Map.Entry eldest) {
try {
return size() > getConfigurationFor(Constants.DEFAULT_TENANT, Constants.DB_NAMESPACE)
- .getInt("config.size.max");
+ .getInt("config.size.max");
} catch (Exception exception) {
+ logger.info("ConfigurationException", exception);
return false;
}
}
});
-
private ConfigurationRepository() {
tenants.add(Constants.DEFAULT_TENANT);
namespaces.add(Constants.DEFAULT_NAMESPACE);
@@ -74,7 +78,6 @@
return namespaces;
}
-
public boolean isValidTenant(String tenant) {
return tenant != null && tenants.contains(tenant.toUpperCase());
}
@@ -86,7 +89,7 @@
public Configuration getConfigurationFor(String tenant, String namespace) throws Exception {
String module = tenant + Constants.KEY_ELEMENTS_DELIMITER + namespace;
ConfigurationHolder config = store.get(module);
- return config.getConfiguration(tenant + Constants.KEY_ELEMENTS_DELIMITER + namespace);
+ return config.getConfiguration();
}
public void populateConfiguration(String key, Configuration builder) {
@@ -138,7 +141,7 @@
}
private Configuration getEffectiveConfiguration(Configuration configuration,
- Collection<FileBasedConfigurationBuilder<FileBasedConfiguration>> list) {
+ Collection<FileBasedConfigurationBuilder<FileBasedConfiguration>> list) {
try {
CompositeConfiguration cc = new CompositeConfiguration();
for (FileBasedConfigurationBuilder<FileBasedConfiguration> b : list) {
@@ -148,19 +151,19 @@
composite = cc;
return composite;
} catch (Exception exception) {
+ logger.info("ConfigurationException", exception);
return null;
}
}
- public Configuration getConfiguration(String namespace) throws Exception {
-
+ public Configuration getConfiguration() throws Exception {
if (config == null) {
config = builder.getConfiguration();
lastConfigurationBuildTime = new Timestamp(System.currentTimeMillis());
} else if (lastConfigurationBuildTime != null
- && System.currentTimeMillis() - lastConfigurationBuildTime.getTime()
- > getConfigurationFor(Constants.DEFAULT_TENANT, Constants.DB_NAMESPACE)
- .getInt("config.refresh.interval")) {
+ && System.currentTimeMillis() - lastConfigurationBuildTime.getTime()
+ > getConfigurationFor(Constants.DEFAULT_TENANT, Constants.DB_NAMESPACE)
+ .getInt("config.refresh.interval")) {
lastConfigurationBuildTime = new Timestamp(System.currentTimeMillis());
}