summaryrefslogtreecommitdiffstats
path: root/cps-rest/src/main/java/org/onap
diff options
context:
space:
mode:
authorRudrangi Anupriya <ra00745022@techmahindra.com>2024-07-11 21:56:24 +0530
committerRudrangi Anupriya <ra00745022@techmahindra.com>2024-07-16 11:00:11 +0000
commit760dd950e6f6fcb6f49c6f9d92a33f538adffd24 (patch)
treecccab533a2837a60e527ff1e75d6dbcd01197d6a /cps-rest/src/main/java/org/onap
parentac58e919008c4449b389d3681a6f8aa216cb5f8f (diff)
XML content support on replace a node with descendants
Issue-ID: CPS-2282 Change-Id: Ibb7ffb65ccbb03703266712c6d5c2eade0e7ab4b Signed-off-by: Rudrangi Anupriya <ra00745022@techmahindra.com>
Diffstat (limited to 'cps-rest/src/main/java/org/onap')
-rwxr-xr-xcps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java28
1 files changed, 15 insertions, 13 deletions
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 f579c82d25..6100b7edd9 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
@@ -49,7 +49,6 @@ import org.onap.cps.utils.PrefixResolver;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
@@ -70,11 +69,10 @@ public class DataRestController implements CpsDataApi {
@Override
public ResponseEntity<String> createNode(final String apiVersion,
final String dataspaceName, final String anchorName,
- @RequestHeader(value = "Content-Type") final String contentTypeHeader,
+ final String contentTypeInHeader,
final String nodeData, final String parentNodeXpath,
final String observedTimestamp) {
- final ContentType contentType = contentTypeHeader.contains(MediaType.APPLICATION_XML_VALUE) ? ContentType.XML
- : ContentType.JSON;
+ final ContentType contentType = getContentTypeFromHeader(contentTypeInHeader);
if (isRootXpath(parentNodeXpath)) {
cpsDataService.saveData(dataspaceName, anchorName, nodeData,
toOffsetDateTime(observedTimestamp), contentType);
@@ -137,23 +135,23 @@ public class DataRestController implements CpsDataApi {
@Override
public ResponseEntity<Object> updateNodeLeaves(final String apiVersion, final String dataspaceName,
- final String anchorName, final String contentTypeHeader,
+ final String anchorName, final String contentTypeInHeader,
final String nodeData, final String parentNodeXpath,
final String observedTimestamp) {
- final ContentType contentType = contentTypeHeader.contains(MediaType.APPLICATION_XML_VALUE) ? ContentType.XML
- : ContentType.JSON;
+ final ContentType contentType = getContentTypeFromHeader(contentTypeInHeader);
cpsDataService.updateNodeLeaves(dataspaceName, anchorName, parentNodeXpath,
nodeData, toOffsetDateTime(observedTimestamp), contentType);
return new ResponseEntity<>(HttpStatus.OK);
}
@Override
- public ResponseEntity<Object> replaceNode(final String apiVersion,
- final String dataspaceName, final String anchorName,
- final Object jsonData, final String parentNodeXpath, final String observedTimestamp) {
- cpsDataService
- .updateDataNodeAndDescendants(dataspaceName, anchorName, parentNodeXpath,
- jsonObjectMapper.asJsonString(jsonData), toOffsetDateTime(observedTimestamp));
+ public ResponseEntity<Object> replaceNode(final String apiVersion, final String dataspaceName,
+ final String anchorName, final String contentTypeInHeader,
+ final String nodeData, final String parentNodeXpath,
+ final String observedTimestamp) {
+ final ContentType contentType = getContentTypeFromHeader(contentTypeInHeader);
+ cpsDataService.updateDataNodeAndDescendants(dataspaceName, anchorName, parentNodeXpath,
+ nodeData, toOffsetDateTime(observedTimestamp), contentType);
return new ResponseEntity<>(HttpStatus.OK);
}
@@ -213,6 +211,10 @@ public class DataRestController implements CpsDataApi {
return new ResponseEntity<>(jsonObjectMapper.asJsonString(deltaBetweenAnchors), HttpStatus.OK);
}
+ private static ContentType getContentTypeFromHeader(final String contentTypeInHeader) {
+ return contentTypeInHeader.contains(MediaType.APPLICATION_XML_VALUE) ? ContentType.XML : ContentType.JSON;
+ }
+
private static boolean isRootXpath(final String xpath) {
return ROOT_XPATH.equals(xpath);
}