From 10e959f6ccf947b1f6333a643ad215749e1c16dd Mon Sep 17 00:00:00 2001 From: ojasdubey Date: Wed, 27 Dec 2017 20:15:17 +0530 Subject: Fix Sonar violations - ConfigurationRepository 1. Fixed major sonar violations configuration management core - ConfigurationRepository Change-Id: Iab756af7ffae63fe9e644d733225908d121cbd9a Issue-ID: SDC-343 Signed-off-by: ojasdubey --- .../config/impl/ConfigurationRepository.java | 34 +++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'common/openecomp-common-configuration-management') diff --git a/common/openecomp-common-configuration-management/openecomp-configuration-management-core/src/main/java/org/openecomp/config/impl/ConfigurationRepository.java b/common/openecomp-common-configuration-management/openecomp-configuration-management-core/src/main/java/org/openecomp/config/impl/ConfigurationRepository.java index 103b43db05..d67c1af06c 100644 --- a/common/openecomp-common-configuration-management/openecomp-configuration-management-core/src/main/java/org/openecomp/config/impl/ConfigurationRepository.java +++ b/common/openecomp-common-configuration-management/openecomp-configuration-management-core/src/main/java/org/openecomp/config/impl/ConfigurationRepository.java @@ -46,6 +46,7 @@ public final class ConfigurationRepository { private Set namespaces = new HashSet<>(); private LinkedHashMap store = new LinkedHashMap(16, 0.75f, true) { + @Override protected boolean removeEldestEntry(Map.Entry eldest) { try { return size() > getConfigurationFor(Constants.DEFAULT_TENANT, Constants.DB_NAMESPACE) @@ -96,7 +97,7 @@ public final class ConfigurationRepository { private void populateTenantsNamespace(String key, boolean sourcedFromDb) { String[] array = key.split(Constants.KEY_ELEMENTS_DELEMETER); - if (!array[1].toUpperCase().equals(Constants.DB_NAMESPACE)) { + if (!array[1].equalsIgnoreCase(Constants.DB_NAMESPACE)) { if (!sourcedFromDb) { dbAccessible = false; } @@ -118,7 +119,7 @@ public final class ConfigurationRepository { populateTenantsNamespace(iterator.next(), true); } } catch (Exception exception) { - //exception.printStackTrace(); + //Log this later } } @@ -151,7 +152,7 @@ public final class ConfigurationRepository { * @throws Exception the exception */ public Configuration getConfigurationFor(String tenant, String namespace) throws Exception { - ConfigurationHolder config = null; + ConfigurationHolder config; String module = tenant + Constants.KEY_ELEMENTS_DELEMETER + namespace; config = store.get(module); if (config == null) { @@ -196,11 +197,11 @@ public final class ConfigurationRepository { ConfigurationHolder holder = store.get(key); if (holder == null) { if (dbAccessible) { - store.put(key, - holder = new ConfigurationHolder(ConfigurationUtils.getDbConfigurationBuilder(key))); + holder = new ConfigurationHolder(ConfigurationUtils.getDbConfigurationBuilder(key)); } else { - store.put(key, holder = new ConfigurationHolder(new CombinedConfiguration())); + holder = new ConfigurationHolder(new CombinedConfiguration()); } + store.put(key, holder); } holder.addOverrideConfiguration(file.getAbsolutePath(), ConfigurationUtils.getConfigurationBuilder(file, true)); @@ -349,14 +350,13 @@ public final class ConfigurationRepository { > getConfigurationFor(Constants.DEFAULT_TENANT, Constants.DB_NAMESPACE) .getInt("config.refresh.interval")) { Timestamp temp = getLastUpdateTimestampFor(namespace); - if (temp != null) { - if (lastConfigChangeTimestamp == null - || temp.getTime() > lastConfigChangeTimestamp.getTime()) { - builder.resetResult(); - config = builder.getConfiguration(); - lastConfigChangeTimestamp = temp; - getEffectiveConfiguration(config, overrideConfiguration.values()); - } + if ((temp != null) + && (lastConfigChangeTimestamp == null + || temp.getTime() > lastConfigChangeTimestamp.getTime())) { + builder.resetResult(); + config = builder.getConfiguration(); + lastConfigChangeTimestamp = temp; + getEffectiveConfiguration(config, overrideConfiguration.values()); } lastConfigurationBuildTime = new Timestamp(System.currentTimeMillis()); } @@ -374,9 +374,9 @@ public final class ConfigurationRepository { cc.addConfiguration(b.getConfiguration()); } cc.addConfiguration(configuration); - return composite = cc; + composite = cc; + return composite; } catch (Exception exception) { - exception.printStackTrace(); return null; } } @@ -398,7 +398,7 @@ public final class ConfigurationRepository { timestamp = new Timestamp(Long.valueOf(((ArrayList) collection).get(0).toString())); } } catch (Exception exception) { - exception.printStackTrace(); + //Log this later } return timestamp; -- cgit 1.2.3-korg