From 0b5efe797d39ccce1bb2feeca65197b33423d6c4 Mon Sep 17 00:00:00 2001
From: Piotr Borelowski
Date: Tue, 25 Jun 2019 17:17:41 +0200
Subject: Fixed sonar issues in ConfigurationRepository
Fixing sonar issues in onap-configuration-management-core project
Issue-ID: SDC-2390
Signed-off-by: Piotr Borelowski
Signed-off-by: Krystian Kedron
Change-Id: I2814b189eb53f53ab94295ff6bba76d118616800
---
.../onap-configuration-management-core/pom.xml | 7 +++++++
.../onap/config/impl/ConfigurationRepository.java | 23 ++++++++++++----------
2 files changed, 20 insertions(+), 10 deletions(-)
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 83b5ac7035..2c7fd006d5 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 @@
logback-classic
test
+
+ org.openecomp.sdc
+ openecomp-sdc-logging-api
+ ${project.version}
+ compile
+
+
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 63c3b7563f..7b2e267a14 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.BasicConfigurationBuilder;
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 tenants = Collections.synchronizedSet(new HashSet<>());
@@ -49,14 +53,14 @@ public final class ConfigurationRepository {
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 @@ public final class ConfigurationRepository {
return namespaces;
}
-
public boolean isValidTenant(String tenant) {
return tenant != null && tenants.contains(tenant.toUpperCase());
}
@@ -86,7 +89,7 @@ public final class ConfigurationRepository {
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 @@ public final class ConfigurationRepository {
}
private Configuration getEffectiveConfiguration(Configuration configuration,
- Collection> list) {
+ Collection> list) {
try {
CompositeConfiguration cc = new CompositeConfiguration();
for (FileBasedConfigurationBuilder b : list) {
@@ -148,19 +151,19 @@ public final class ConfigurationRepository {
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());
}
--
cgit 1.2.3-korg