From dfcc95236daf7d45687fa42446a7d236ac12637e Mon Sep 17 00:00:00 2001 From: Rudrangi Anupriya Date: Wed, 27 Nov 2024 23:49:42 +0530 Subject: XML content support on Replace list content Here to bring Support for XML Response Entity in Replace List content - Add ContentTypeInheadr in cpsData.yml to support application/xml - Add contentTypeInHeader parameter to accept xml in DataRestController.java - Modify the code return xml Data - written testcase for above changes made Issue-ID: CPS-2411 Change-Id: Ibb7ffb66ccdd03703266123c6d5c2eade0e7cb4a Signed-off-by: Rudrangi Anupriya --- .../java/org/onap/cps/rest/controller/DataRestController.java | 10 ++++++---- .../java/org/onap/cps/rest/controller/QueryRestController.java | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'cps-rest/src/main') diff --git a/cps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java b/cps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java index dda88e019c..3efb6b421c 100755 --- a/cps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java +++ b/cps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java @@ -173,9 +173,11 @@ public class DataRestController implements CpsDataApi { @Override public ResponseEntity replaceListContent(final String apiVersion, final String dataspaceName, final String anchorName, final String parentNodeXpath, - final Object jsonData, final String observedTimestamp) { + final String nodeData, final String observedTimestamp, + final String contentTypeInHeader) { + final ContentType contentType = ContentType.fromString(contentTypeInHeader); cpsDataService.replaceListContent(dataspaceName, anchorName, parentNodeXpath, - jsonObjectMapper.asJsonString(jsonData), toOffsetDateTime(observedTimestamp)); + nodeData, toOffsetDateTime(observedTimestamp), contentType); return new ResponseEntity<>(HttpStatus.OK); } @@ -225,10 +227,10 @@ public class DataRestController implements CpsDataApi { return new ResponseEntity<>(jsonObjectMapper.asJsonString(deltaBetweenAnchors), HttpStatus.OK); } - ResponseEntity buildResponseEntity(final List> dataMaps, + private ResponseEntity buildResponseEntity(final List> dataMaps, final ContentType contentType) { final String responseData; - if (contentType == ContentType.XML) { + if (ContentType.XML.equals(contentType)) { responseData = XmlFileUtils.convertDataMapsToXml(dataMaps); } else { responseData = jsonObjectMapper.asJsonString(dataMaps); diff --git a/cps-rest/src/main/java/org/onap/cps/rest/controller/QueryRestController.java b/cps-rest/src/main/java/org/onap/cps/rest/controller/QueryRestController.java index b425333f9e..c419a81245 100644 --- a/cps-rest/src/main/java/org/onap/cps/rest/controller/QueryRestController.java +++ b/cps-rest/src/main/java/org/onap/cps/rest/controller/QueryRestController.java @@ -160,7 +160,7 @@ public class QueryRestController implements CpsQueryApi { private ResponseEntity buildResponseEntity(final List> dataNodesAsListOfMaps, final ContentType contentType) { final String responseData; - if (contentType == ContentType.XML) { + if (ContentType.XML.equals(contentType)) { responseData = XmlFileUtils.convertDataMapsToXml(dataNodesAsListOfMaps); } else { responseData = jsonObjectMapper.asJsonString(dataNodesAsListOfMaps); -- cgit 1.2.3-korg