From 3e82776f38b8254de5b8b342ec04fb02c9052556 Mon Sep 17 00:00:00 2001 From: ezhil Date: Thu, 15 Nov 2018 13:47:17 +0530 Subject: Sonar fixes in PolicyReader.Java Replaced duplicate literals with constants Issue-ID: CCSDK-686 Change-Id: I389b4785a16dac8e7e20e7ccaeb05ab3de0256d8 Signed-off-by: ezhil --- .../apps/ms/neng/core/policy/PolicyReader.java | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'ms/neng/src/main') diff --git a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/policy/PolicyReader.java b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/policy/PolicyReader.java index 73f46c95..09a6e49b 100644 --- a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/policy/PolicyReader.java +++ b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/policy/PolicyReader.java @@ -37,19 +37,23 @@ public abstract class PolicyReader implements PolicyFinder { * @param policy the policy * @return the list of naming-models found in the policy */ + private static final String NAMING_MODELS = "naming-models"; + private static final String NAMING_TYPE = "naming-type"; + public static List> namingModels(Map policy) { + Set keys = policy.keySet(); // TODO : retrieve naming-models at any level if (keys.contains("config")) { @SuppressWarnings("unchecked") Map config = (Map) policy.get("config"); - List> namingModels = list(map(config, "content"), "naming-models"); + List> namingModels = list(map(config, "content"), NAMING_MODELS); if (namingModels == null) { - namingModels = list(config, "naming-models"); + namingModels = list(config, NAMING_MODELS); } return namingModels; } else { - return list(map(map(policy, "input"), "naming-model"), "naming-models"); + return list(map(map(policy, "input"), "naming-model"), NAMING_MODELS); } } @@ -65,7 +69,7 @@ public abstract class PolicyReader implements PolicyFinder { Map theModel = null; if (namingModels != null) { for (Map model : namingModels) { - Object val = model.get("naming-type"); + Object val = model.get(NAMING_TYPE); if (namingType.equals(val)) { theModel = model; break; @@ -120,8 +124,9 @@ public abstract class PolicyReader implements PolicyFinder { * Finds the naming-operation from the given naming-model. */ public static String namingOperation(Map namimgModel) { - String propValue = value(namimgModel, "name-operation"); - return propValue; + //String propValue = value(namimgModel, "name-operation"); + //return propValue; + return value(namimgModel, "name-operation"); } /** @@ -294,8 +299,8 @@ public abstract class PolicyReader implements PolicyFinder { Map getPolicy(String jsonString) throws Exception { ObjectMapper mapper = new ObjectMapper(); - Map jsonObject = mapper.readValue(jsonString, new TypeReference>() {}); - return jsonObject; + // Map jsonObject = mapper.readValue(jsonString, new TypeReference>() {}); + return mapper.readValue(jsonString, new TypeReference>() {}); } static List> list(Map policy, String name) { -- cgit 1.2.3-korg