summaryrefslogtreecommitdiffstats
path: root/cps-service/src/main/java/org
diff options
context:
space:
mode:
authorRudrangi Anupriya <ra00745022@techmahindra.com>2024-11-06 22:20:11 +0530
committerRudrangi Anupriya <ra00745022@techmahindra.com>2024-11-17 17:09:51 +0000
commit5baf570979a06ec52e40dfaf613bb74665a8d9ff (patch)
treef3626a781fa367764de2607b2eaf5ea54c557617 /cps-service/src/main/java/org
parent37962e3faca4f2306546c4f70d480b0c323d2c68 (diff)
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 <ra00745022@techmahindra.com>
Diffstat (limited to 'cps-service/src/main/java/org')
-rw-r--r--cps-service/src/main/java/org/onap/cps/utils/XmlFileUtils.java46
1 files changed, 25 insertions, 21 deletions
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<String, Object> dataMap) {
- for (final Map.Entry<String, Object> 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<String, Object> 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<String, Object> mapEntry) {
- final List<Object> list = (List<Object>) mapEntry.getValue();
- if (list.isEmpty()) {
- final Element listElement = document.createElement(mapEntry.getKey());
+ final Map.Entry<String, Object> dataNodeMapEntry) {
+ final List<Object> dataNodeMaps = (List<Object>) 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<String, Object>) 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<String, Object>) 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<String, Object> mapEntry) {
- final Element childElement = document.createElement(mapEntry.getKey());
- createXmlElements(document, childElement, (Map<String, Object>) mapEntry.getValue());
+ final Map.Entry<String, Object> dataNodeMapEntry) {
+ final Element childElement = document.createElement(dataNodeMapEntry.getKey());
+ createXmlElements(document, childElement, (Map<String, Object>) dataNodeMapEntry.getValue());
parentNode.appendChild(childElement);
}
private static void appendObject(final Document document, final Node parentNode,
- final Map.Entry<String, Object> mapEntry) {
- final Element element = document.createElement(mapEntry.getKey());
- element.appendChild(document.createTextNode(mapEntry.getValue().toString()));
+ final Map.Entry<String, Object> dataNodeMapEntry) {
+ final Element element = document.createElement(dataNodeMapEntry.getKey());
+ if (dataNodeMapEntry.getValue() != null) {
+ element.appendChild(document.createTextNode(dataNodeMapEntry.getValue().toString()));
+ }
parentNode.appendChild(element);
}