summaryrefslogtreecommitdiffstats
path: root/cps-rest/src/main/java/org
diff options
context:
space:
mode:
authordanielhanrahan <daniel.hanrahan@est.tech>2024-11-22 09:20:03 +0000
committerdanielhanrahan <daniel.hanrahan@est.tech>2024-11-22 10:19:20 +0000
commitd378e7b4321bf940424079440461eb0b874ad096 (patch)
tree7d208329ce03aeb339bdd89644b6cdb72e29a035 /cps-rest/src/main/java/org
parent225626a21199cbb8fbab976169785313b3aeceb7 (diff)
Make Content-Type header default to JSON for CPS APIs
Recent changes for XML support have made Content-Type header mandatory, where before it was not. This change makes CPS default to JSON if Content-Type is not specified. Issue-ID: CPS-2517 Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech> Change-Id: Ic3718bfe7aedd6fe9dbd978f520179b184c9c932
Diffstat (limited to 'cps-rest/src/main/java/org')
-rwxr-xr-xcps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java55
-rw-r--r--cps-rest/src/main/java/org/onap/cps/rest/controller/QueryRestController.java18
2 files changed, 40 insertions, 33 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 6d22581845..dda88e019c 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
@@ -72,9 +72,9 @@ public class DataRestController implements CpsDataApi {
@Override
public ResponseEntity<String> createNode(final String apiVersion,
final String dataspaceName, final String anchorName,
- final String contentTypeInHeader,
final String nodeData, final String parentNodeXpath,
- final Boolean dryRunEnabled, final String observedTimestamp) {
+ final Boolean dryRunEnabled, final String observedTimestamp,
+ final String contentTypeInHeader) {
final ContentType contentType = ContentType.fromString(contentTypeInHeader);
if (Boolean.TRUE.equals(dryRunEnabled)) {
cpsDataService.validateData(dataspaceName, anchorName, parentNodeXpath, nodeData, contentType);
@@ -92,19 +92,18 @@ public class DataRestController implements CpsDataApi {
}
@Override
- public ResponseEntity<Void> deleteDataNode(final String apiVersion,
- final String dataspaceName, final String anchorName,
- final String xpath, final String observedTimestamp) {
- cpsDataService.deleteDataNode(dataspaceName, anchorName, xpath,
- toOffsetDateTime(observedTimestamp));
+ public ResponseEntity<Void> deleteDataNode(final String apiVersion, final String dataspaceName,
+ final String anchorName, final String xpath,
+ final String observedTimestamp) {
+ cpsDataService.deleteDataNode(dataspaceName, anchorName, xpath, toOffsetDateTime(observedTimestamp));
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@Override
public ResponseEntity<String> addListElements(final String apiVersion, final String dataspaceName,
final String anchorName, final String parentNodeXpath,
- final String contentTypeInHeader, final String nodeData,
- final String observedTimestamp) {
+ final String nodeData, final String observedTimestamp,
+ final String contentTypeInHeader) {
final ContentType contentType = ContentType.fromString(contentTypeInHeader);
cpsDataService.saveListElements(dataspaceName, anchorName, parentNodeXpath,
nodeData, toOffsetDateTime(observedTimestamp), contentType);
@@ -115,7 +114,9 @@ public class DataRestController implements CpsDataApi {
@Timed(value = "cps.data.controller.datanode.get.v1",
description = "Time taken to get data node")
public ResponseEntity<Object> getNodeByDataspaceAndAnchor(final String dataspaceName,
- final String anchorName, final String xpath, final Boolean includeDescendants) {
+ final String anchorName,
+ final String xpath,
+ final Boolean includeDescendants) {
final FetchDescendantsOption fetchDescendantsOption = Boolean.TRUE.equals(includeDescendants)
? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS : FetchDescendantsOption.OMIT_DESCENDANTS;
final DataNode dataNode = cpsDataService.getDataNodes(dataspaceName, anchorName, xpath,
@@ -129,8 +130,9 @@ public class DataRestController implements CpsDataApi {
@Timed(value = "cps.data.controller.datanode.get.v2",
description = "Time taken to get data node")
public ResponseEntity<Object> getNodeByDataspaceAndAnchorV2(final String dataspaceName, final String anchorName,
- final String contentTypeInHeader, final String xpath,
- final String fetchDescendantsOptionAsString) {
+ final String xpath,
+ final String fetchDescendantsOptionAsString,
+ final String contentTypeInHeader) {
final ContentType contentType = ContentType.fromString(contentTypeInHeader);
final FetchDescendantsOption fetchDescendantsOption =
FetchDescendantsOption.getFetchDescendantsOption(fetchDescendantsOptionAsString);
@@ -148,9 +150,9 @@ public class DataRestController implements CpsDataApi {
@Override
public ResponseEntity<Object> updateNodeLeaves(final String apiVersion, final String dataspaceName,
- final String anchorName, final String contentTypeInHeader,
- final String nodeData, final String parentNodeXpath,
- final String observedTimestamp) {
+ final String anchorName, final String nodeData,
+ final String parentNodeXpath, final String observedTimestamp,
+ final String contentTypeInHeader) {
final ContentType contentType = ContentType.fromString(contentTypeInHeader);
cpsDataService.updateNodeLeaves(dataspaceName, anchorName, parentNodeXpath,
nodeData, toOffsetDateTime(observedTimestamp), contentType);
@@ -159,9 +161,9 @@ public class DataRestController implements CpsDataApi {
@Override
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 String anchorName, final String nodeData,
+ final String parentNodeXpath, final String observedTimestamp,
+ final String contentTypeInHeader) {
final ContentType contentType = ContentType.fromString(contentTypeInHeader);
cpsDataService.updateDataNodeAndDescendants(dataspaceName, anchorName, parentNodeXpath,
nodeData, toOffsetDateTime(observedTimestamp), contentType);
@@ -169,10 +171,9 @@ public class DataRestController implements CpsDataApi {
}
@Override
- public ResponseEntity<Object> replaceListContent(final String apiVersion,
- final String dataspaceName, final String anchorName,
- final String parentNodeXpath, final Object jsonData,
- final String observedTimestamp) {
+ public ResponseEntity<Object> replaceListContent(final String apiVersion, final String dataspaceName,
+ final String anchorName, final String parentNodeXpath,
+ final Object jsonData, final String observedTimestamp) {
cpsDataService.replaceListContent(dataspaceName, anchorName, parentNodeXpath,
jsonObjectMapper.asJsonString(jsonData), toOffsetDateTime(observedTimestamp));
return new ResponseEntity<>(HttpStatus.OK);
@@ -180,7 +181,7 @@ public class DataRestController implements CpsDataApi {
@Override
public ResponseEntity<Void> deleteListOrListElement(final String dataspaceName, final String anchorName,
- final String listElementXpath, final String observedTimestamp) {
+ final String listElementXpath, final String observedTimestamp) {
cpsDataService
.deleteListOrListElement(dataspaceName, anchorName, listElementXpath, toOffsetDateTime(observedTimestamp));
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
@@ -211,10 +212,10 @@ public class DataRestController implements CpsDataApi {
@Timed(value = "cps.data.controller.get.delta",
description = "Time taken to get delta between anchors")
public ResponseEntity<Object> getDeltaByDataspaceAndAnchors(final String dataspaceName,
- final String sourceAnchorName,
- final String targetAnchorName,
- final String xpath,
- final String descendants) {
+ final String sourceAnchorName,
+ final String targetAnchorName,
+ final String xpath,
+ final String descendants) {
final FetchDescendantsOption fetchDescendantsOption =
FetchDescendantsOption.getFetchDescendantsOption(descendants);
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 6823f6b03e..b425333f9e 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
@@ -60,7 +60,9 @@ public class QueryRestController implements CpsQueryApi {
@Timed(value = "cps.data.controller.datanode.query.v1",
description = "Time taken to query data nodes")
public ResponseEntity<Object> getNodesByDataspaceAndAnchorAndCpsPath(final String dataspaceName,
- final String anchorName, final String cpsPath, final Boolean includeDescendants) {
+ final String anchorName,
+ final String cpsPath,
+ final Boolean includeDescendants) {
final FetchDescendantsOption fetchDescendantsOption = Boolean.TRUE.equals(includeDescendants)
? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS : FetchDescendantsOption.OMIT_DESCENDANTS;
return executeNodesByDataspaceQueryAndCreateResponse(dataspaceName, anchorName, cpsPath,
@@ -71,8 +73,10 @@ public class QueryRestController implements CpsQueryApi {
@Timed(value = "cps.data.controller.datanode.query.v2",
description = "Time taken to query data nodes")
public ResponseEntity<Object> getNodesByDataspaceAndAnchorAndCpsPathV2(final String dataspaceName,
- final String anchorName, final String contentTypeInHeader, final String cpsPath,
- final String fetchDescendantsOptionAsString) {
+ final String anchorName,
+ final String cpsPath,
+ final String fetchDescendantsOptionAsString,
+ final String contentTypeInHeader) {
final ContentType contentType = ContentType.fromString(contentTypeInHeader);
final FetchDescendantsOption fetchDescendantsOption =
FetchDescendantsOption.getFetchDescendantsOption(fetchDescendantsOptionAsString);
@@ -83,9 +87,11 @@ public class QueryRestController implements CpsQueryApi {
@Override
@Timed(value = "cps.data.controller.datanode.query.across.anchors",
description = "Time taken to query data nodes across anchors")
- public ResponseEntity<Object> getNodesByDataspaceAndCpsPath(final String dataspaceName, final String cpsPath,
+ public ResponseEntity<Object> getNodesByDataspaceAndCpsPath(final String dataspaceName,
+ final String cpsPath,
final String fetchDescendantsOptionAsString,
- final Integer pageIndex, final Integer pageSize) {
+ final Integer pageIndex,
+ final Integer pageSize) {
final FetchDescendantsOption fetchDescendantsOption =
FetchDescendantsOption.getFetchDescendantsOption(fetchDescendantsOptionAsString);
final PaginationOption paginationOption = (pageIndex == null || pageSize == null)
@@ -111,7 +117,7 @@ public class QueryRestController implements CpsQueryApi {
}
private Integer getTotalPages(final String dataspaceName, final String cpsPath,
- final PaginationOption paginationOption) {
+ final PaginationOption paginationOption) {
if (paginationOption == PaginationOption.NO_PAGINATION) {
return 1;
}