diff options
author | k.kazak <k.kazak@samsung.com> | 2019-05-27 15:00:15 +0200 |
---|---|---|
committer | k.kazak <k.kazak@samsung.com> | 2019-05-27 15:00:15 +0200 |
commit | c1cd5ef428017bc26513395a3bfc00caf7209f8a (patch) | |
tree | 6001426422534e0d4cdf1e7ab0e2ddd2ecc1369e /adapters/mso-adapters-rest-interface/src/main/java/org | |
parent | a7160456335b2ce3710efd00658711d431eac0b4 (diff) |
Fix sonar for MapEntry
MapEntry bug: make entry private and provide accessors
MapEntry codesmell: move comment 'Required by JAXB' into empty constructor
MapElements codesmell: move explanatory comment inside empty constructor
MapElements codesmell: log error stacktrace
MapAdapter codesmell: use entry set instead of key set for iteration
JAXBMarshallingTest: add test cases to cover 100% of MapElements & other cases
Change-Id: If51f1f86b5ad44b3462424e4fd73cb0eff352124
Issue-ID: SO-1811
Signed-off-by: k.kazak <k.kazak@samsung.com>
Diffstat (limited to 'adapters/mso-adapters-rest-interface/src/main/java/org')
3 files changed, 28 insertions, 9 deletions
diff --git a/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/openstack/mappers/MapAdapter.java b/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/openstack/mappers/MapAdapter.java index ef5d4316d7..90b8024c18 100644 --- a/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/openstack/mappers/MapAdapter.java +++ b/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/openstack/mappers/MapAdapter.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * 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. * You may obtain a copy of the License at @@ -36,8 +38,8 @@ public class MapAdapter extends XmlAdapter<MapEntry, Map<String, Object>> { MapEntry map = new MapEntry(); - for (String key : v.keySet()) { - map.addEntry(key, v.get(key)); + for (Map.Entry<String, Object> entry : v.entrySet()) { + map.addEntry(entry.getKey(), entry.getValue()); } return map; @@ -49,9 +51,9 @@ public class MapAdapter extends XmlAdapter<MapEntry, Map<String, Object>> { return null; } - Map<String, Object> map = new HashMap<>(v.entry.size()); + Map<String, Object> map = new HashMap<>(v.getEntry().size()); - for (MapElements entry : v.entry) { + for (MapElements entry : v.getEntry()) { if (entry.value instanceof Element) { map.put(entry.key, ((Element) entry.value).getTextContent()); } else { diff --git a/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/openstack/mappers/MapElements.java b/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/openstack/mappers/MapElements.java index 0327fd67a3..3dd339dc68 100644 --- a/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/openstack/mappers/MapElements.java +++ b/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/openstack/mappers/MapElements.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * 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. * You may obtain a copy of the License at @@ -35,7 +37,9 @@ public class MapElements { @XmlElement public Object value; - public MapElements() {} // Required by JAXB + public MapElements() { + // Required by JAXB + } public MapElements(String key, Object value) { this.key = key; @@ -46,7 +50,7 @@ public class MapElements { try { this.value = new ObjectMapper().writeValueAsString(value); } catch (JsonProcessingException e) { - logger.warn("could not marshal value to json, calling toString"); + logger.warn("could not marshal value to json, calling toString", e); this.value = value.toString(); } } else { diff --git a/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/openstack/mappers/MapEntry.java b/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/openstack/mappers/MapEntry.java index 489e11e111..b6b121c820 100644 --- a/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/openstack/mappers/MapEntry.java +++ b/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/openstack/mappers/MapEntry.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * 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. * You may obtain a copy of the License at @@ -25,12 +27,23 @@ import java.util.List; public class MapEntry { - public List<MapElements> entry = new ArrayList<>(); + private List<MapElements> entry = new ArrayList<>(); - public MapEntry() {} // Required by JAXB + public MapEntry() { + // Required by JAXB + } - public void addEntry(String key, Object value) { + void addEntry(String key, Object value) { entry.add(new MapElements(key, value)); } + public List<MapElements> getEntry() { + // Required by JAXB + return entry; + } + + public void setEntry(List<MapElements> entry) { + // Required by JAXB + this.entry = entry; + } } |