summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Dudycz <jakub.dudycz@nokia.com>2018-02-15 12:28:40 +0100
committerPatrick Brady <pb071s@att.com>2018-02-15 22:20:15 +0000
commit17116cc208810e274c30fc7cc985d55f36d21b23 (patch)
tree5d75b8791a0eee85c1f7a090e28dbd5527316929
parent7ce9a02a00e3cb589d6356696b58448327d4e610 (diff)
JSONTool sonar fixes
Change-Id: I457ac55fa17475a19a2e511a6e7813070ffd6d2e Issue-ID: APPC-634 Signed-off-by: Jakub Dudycz <jakub.dudycz@nokia.com>
-rw-r--r--appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/JSONTool.java76
1 files changed, 39 insertions, 37 deletions
diff --git a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/JSONTool.java b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/JSONTool.java
index a4731099d..faa9c6fb0 100644
--- a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/JSONTool.java
+++ b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/JSONTool.java
@@ -24,6 +24,8 @@
package org.onap.sdnc.config.generator.tool;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@@ -32,71 +34,71 @@ import java.util.Map;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-
public class JSONTool {
private static final EELFLogger log = EELFManager.getInstance().getLogger(JSONTool.class);
+ private JSONTool() {
+ }
+
public static Map<String, String> convertToProperties(String s) throws JSONException {
return convertToProperties(s, null);
}
public static Map<String, String> convertToProperties(String s, List<String> blockKeys)
- throws JSONException {
+ throws JSONException {
JSONObject json = new JSONObject(s);
- Map<String, String> mm = new HashMap<String, String>();
+ Map<String, String> mm = new HashMap<>();
+ Map<String, Object> wm = new HashMap<>();
- Map<String, Object> wm = new HashMap<String, Object>();
Iterator<String> ii = json.keys();
while (ii.hasNext()) {
String key1 = ii.next();
wm.put(key1, json.get(key1));
-
-
}
-
- while (!wm.isEmpty())
+ while (!wm.isEmpty()) {
for (String key : new ArrayList<>(wm.keySet())) {
Object o = wm.get(key);
wm.remove(key);
-
-
- if (blockKeys != null && blockKeys.contains(key) && o != null) {
- // log.info("Adding JSON Block Keys : " + key + "=" + o.toString());
- mm.put("block_" + key, o.toString());
- }
-
+ tryAddBlockKeys(blockKeys, mm, key, o);
if (o instanceof Boolean || o instanceof Number || o instanceof String) {
mm.put(key, o.toString());
- // log.info("Added property: " + key + ": " + o.toString());
+ log.info("Added property: " + key + ": " + o.toString());
+ } else if (o instanceof JSONObject) {
+ fill(wm, key, (JSONObject) o);
+ } else if (o instanceof JSONArray) {
+ fill(mm, wm, key, (JSONArray) o);
}
+ }
+ }
+ return mm;
+ }
- else if (o instanceof JSONObject) {
- JSONObject jo = (JSONObject) o;
- Iterator<String> i = jo.keys();
- while (i.hasNext()) {
- String key1 = i.next();
- wm.put(key + "." + key1, jo.get(key1));
- }
- }
+ private static void tryAddBlockKeys(List<String> blockKeys, Map<String, String> mm, String key, Object o) {
+ if (blockKeys != null && blockKeys.contains(key) && o != null) {
+ mm.put("block_" + key, o.toString());
+ log.info("Adding JSON Block Keys : " + key + "=" + o.toString());
+ }
+ }
- else if (o instanceof JSONArray) {
- JSONArray ja = (JSONArray) o;
- mm.put("size_" + key, String.valueOf(ja.length()));
+ private static void fill(Map<String, String> mm, Map<String, Object> wm, String key, JSONArray array)
+ throws JSONException {
+ mm.put("size_" + key, String.valueOf(array.length()));
+ log.info("Added property: " + key + "_length" + ": " + array.length());
- // log.info("Added property: " + key + "_length" + ": " +
- // String.valueOf(ja.length()));
+ for (int i = 0; i < array.length(); i++) {
+ wm.put(key + '[' + i + ']', array.get(i));
+ }
+ }
- for (int i = 0; i < ja.length(); i++)
- wm.put(key + '[' + i + ']', ja.get(i));
- }
- }
+ private static void fill(Map<String, Object> wm, String key, JSONObject object) throws JSONException {
- return mm;
+ Iterator<String> i = object.keys();
+ while (i.hasNext()) {
+ String key1 = i.next();
+ wm.put(key + "." + key1, object.get(key1));
+ }
}
-
}