From 5baf570979a06ec52e40dfaf613bb74665a8d9ff Mon Sep 17 00:00:00 2001 From: Rudrangi Anupriya Date: Wed, 6 Nov 2024 22:20:11 +0530 Subject: XML content support for only cps Query v2 Here to bring Support for XML Response Entity in query data nodes - Add ContentTypeInheadr in cpsQueryV2.yml to support application/xml - Add contentTypeInHeader parameter to accept xml in QueryRestController.java - Implement logic to convert data to xml - written testcase for above changes made Issue-ID: CPS-2359 Change-Id: Ieb7eeb66ccbb03703626132c6d5c2eade0e7cb4b Signed-off-by: Rudrangi Anupriya --- .../main/java/org/onap/cps/utils/XmlFileUtils.java | 46 ++++++++++++---------- 1 file changed, 25 insertions(+), 21 deletions(-) (limited to 'cps-service/src/main/java') diff --git a/cps-service/src/main/java/org/onap/cps/utils/XmlFileUtils.java b/cps-service/src/main/java/org/onap/cps/utils/XmlFileUtils.java index 94b97bd88f..bbfb7f4d2e 100644 --- a/cps-service/src/main/java/org/onap/cps/utils/XmlFileUtils.java +++ b/cps-service/src/main/java/org/onap/cps/utils/XmlFileUtils.java @@ -189,30 +189,32 @@ public class XmlFileUtils { private static void createXmlElements(final Document document, final Node parentNode, final Map dataMap) { - for (final Map.Entry mapEntry : dataMap.entrySet()) { - if (mapEntry.getValue() instanceof List) { - appendList(document, parentNode, mapEntry); - } else if (mapEntry.getValue() instanceof Map) { - appendMap(document, parentNode, mapEntry); + for (final Map.Entry dataNodeMapEntry : dataMap.entrySet()) { + if (dataNodeMapEntry.getValue() instanceof List) { + appendList(document, parentNode, dataNodeMapEntry); + } else if (dataNodeMapEntry.getValue() instanceof Map) { + appendMap(document, parentNode, dataNodeMapEntry); } else { - appendObject(document, parentNode, mapEntry); + appendObject(document, parentNode, dataNodeMapEntry); } } } private static void appendList(final Document document, final Node parentNode, - final Map.Entry mapEntry) { - final List list = (List) mapEntry.getValue(); - if (list.isEmpty()) { - final Element listElement = document.createElement(mapEntry.getKey()); + final Map.Entry dataNodeMapEntry) { + final List dataNodeMaps = (List) dataNodeMapEntry.getValue(); + if (dataNodeMaps.isEmpty()) { + final Element listElement = document.createElement(dataNodeMapEntry.getKey()); parentNode.appendChild(listElement); } else { - for (final Object element : list) { - final Element listElement = document.createElement(mapEntry.getKey()); - if (element instanceof Map) { - createXmlElements(document, listElement, (Map) element); + for (final Object dataNodeMap : dataNodeMaps) { + final Element listElement = document.createElement(dataNodeMapEntry.getKey()); + if (dataNodeMap == null) { + parentNode.appendChild(listElement); + } else if (dataNodeMap instanceof Map) { + createXmlElements(document, listElement, (Map) dataNodeMap); } else { - listElement.appendChild(document.createTextNode(element.toString())); + listElement.appendChild(document.createTextNode(dataNodeMap.toString())); } parentNode.appendChild(listElement); } @@ -220,16 +222,18 @@ public class XmlFileUtils { } private static void appendMap(final Document document, final Node parentNode, - final Map.Entry mapEntry) { - final Element childElement = document.createElement(mapEntry.getKey()); - createXmlElements(document, childElement, (Map) mapEntry.getValue()); + final Map.Entry dataNodeMapEntry) { + final Element childElement = document.createElement(dataNodeMapEntry.getKey()); + createXmlElements(document, childElement, (Map) dataNodeMapEntry.getValue()); parentNode.appendChild(childElement); } private static void appendObject(final Document document, final Node parentNode, - final Map.Entry mapEntry) { - final Element element = document.createElement(mapEntry.getKey()); - element.appendChild(document.createTextNode(mapEntry.getValue().toString())); + final Map.Entry dataNodeMapEntry) { + final Element element = document.createElement(dataNodeMapEntry.getKey()); + if (dataNodeMapEntry.getValue() != null) { + element.appendChild(document.createTextNode(dataNodeMapEntry.getValue().toString())); + } parentNode.appendChild(element); } -- cgit 1.2.3-korg