summaryrefslogtreecommitdiffstats
path: root/cps-rest/src/main/java/org
diff options
context:
space:
mode:
authorrajesh.kumar <rk00747546@techmahindra.com>2022-12-14 08:13:29 +0000
committerrajesh.kumar <rk00747546@techmahindra.com>2022-12-16 16:30:34 +0000
commit897686f96f49dc4405eb3e29f2a6218dc8040c97 (patch)
tree5912aec524fbe010bbf94bfb192caf1f079b7887 /cps-rest/src/main/java/org
parent377af14ab2664d8a15673e51cba82f1254379e14 (diff)
API versioning supported and added different versions for POST APIs
Issue-ID: CPS-1189 Change-ID: I73f97f986a817d423f92f8d922dcd9647b1214aa Signed-off-by: rajesh.kumar <rk00747546@techmahindra.com>
Diffstat (limited to 'cps-rest/src/main/java/org')
-rwxr-xr-xcps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java71
-rwxr-xr-xcps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java20
-rw-r--r--cps-rest/src/main/java/org/onap/cps/rest/controller/QueryRestController.java5
3 files changed, 77 insertions, 19 deletions
diff --git a/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java b/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java
index 285a15c6a3..b8ba08915c 100755
--- a/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java
+++ b/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java
@@ -69,13 +69,25 @@ public class AdminRestController implements CpsAdminApi {
}
/**
+ * Create a dataspace without returning any response body.
+ *
+ * @param dataspaceName dataspace name
+ * @return a {@Link ResponseEntity} of created dataspace name & {@link HttpStatus} CREATED
+ */
+ @Override
+ public ResponseEntity<Void> createDataspaceV2(@NotNull @Valid final String dataspaceName) {
+ cpsAdminService.createDataspace(dataspaceName);
+ return new ResponseEntity<>(HttpStatus.CREATED);
+ }
+
+ /**
* Delete a dataspace.
*
* @param dataspaceName name of dataspace to be deleted
* @return a {@Link ResponseEntity} of {@link HttpStatus} NO_CONTENT
*/
@Override
- public ResponseEntity<Void> deleteDataspace(final String dataspaceName) {
+ public ResponseEntity<Void> deleteDataspace(final String apiVersion, final String dataspaceName) {
cpsAdminService.deleteDataspace(dataspaceName);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@@ -96,14 +108,31 @@ public class AdminRestController implements CpsAdminApi {
}
/**
+ * Create a {@link SchemaSet}.
+ *
+ * @param multipartFile multipart file
+ * @param schemaSetName schemaset name
+ * @param dataspaceName dataspace name
+ * @return a {@Link ResponseEntity} of created schema set without any response body & {@link HttpStatus} CREATED
+ */
+ @Override
+ public ResponseEntity<Void> createSchemaSetV2(@NotNull @Valid final String schemaSetName,
+ final String dataspaceName, @Valid final MultipartFile multipartFile) {
+ cpsModuleService.createSchemaSet(dataspaceName, schemaSetName, extractYangResourcesMap(multipartFile));
+ return new ResponseEntity<>(HttpStatus.CREATED);
+ }
+
+ /**
* Get {@link SchemaSetDetails} based on dataspace name & {@link SchemaSet} name.
*
+ * @param apiVersion api version
* @param dataspaceName dataspace name
* @param schemaSetName schemaset name
* @return a {@Link ResponseEntity} of {@Link SchemaSetDetails} & {@link HttpStatus} OK
*/
@Override
- public ResponseEntity<SchemaSetDetails> getSchemaSet(final String dataspaceName, final String schemaSetName) {
+ public ResponseEntity<SchemaSetDetails> getSchemaSet(final String apiVersion,
+ final String dataspaceName, final String schemaSetName) {
final var schemaSet = cpsModuleService.getSchemaSet(dataspaceName, schemaSetName);
final var schemaSetDetails = cpsRestInputMapper.toSchemaSetDetails(schemaSet);
return new ResponseEntity<>(schemaSetDetails, HttpStatus.OK);
@@ -112,11 +141,12 @@ public class AdminRestController implements CpsAdminApi {
/**
* Get list of schema sets for a given dataspace name.
*
+ * @param apiVersion api version
* @param dataspaceName dataspace name
* @return a {@Link ResponseEntity} of schema sets & {@link HttpStatus} OK
*/
@Override
- public ResponseEntity<List<SchemaSetDetails>> getSchemaSets(final String dataspaceName) {
+ public ResponseEntity<List<SchemaSetDetails>> getSchemaSets(final String apiVersion, final String dataspaceName) {
final Collection<SchemaSet> schemaSets = cpsModuleService.getSchemaSets(dataspaceName);
final List<SchemaSetDetails> schemaSetDetails = schemaSets.stream().map(cpsRestInputMapper::toSchemaSetDetails)
.collect(Collectors.toList());
@@ -126,12 +156,14 @@ public class AdminRestController implements CpsAdminApi {
/**
* Delete a {@link SchemaSet} based on given dataspace name & schemaset name.
*
+ * @param apiVersion api version
* @param dataspaceName dataspace name
* @param schemaSetName schemaset name
* @return a {@Link ResponseEntity} of {@link HttpStatus} NO_CONTENT
*/
@Override
- public ResponseEntity<Void> deleteSchemaSet(final String dataspaceName, final String schemaSetName) {
+ public ResponseEntity<Void> deleteSchemaSet(final String apiVersion,
+ final String dataspaceName, final String schemaSetName) {
cpsModuleService.deleteSchemaSet(dataspaceName, schemaSetName, CASCADE_DELETE_PROHIBITED);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@@ -152,14 +184,31 @@ public class AdminRestController implements CpsAdminApi {
}
/**
+ * Create an anchor.
+ *
+ * @param dataspaceName dataspace name
+ * @param schemaSetName schema set name
+ * @param anchorName anchorName
+ * @return a ResponseEntity without response body & {@link HttpStatus} CREATED
+ */
+ @Override
+ public ResponseEntity<Void> createAnchorV2(final String dataspaceName, @NotNull @Valid final String schemaSetName,
+ @NotNull @Valid final String anchorName) {
+ cpsAdminService.createAnchor(dataspaceName, schemaSetName, anchorName);
+ return new ResponseEntity<>(HttpStatus.CREATED);
+ }
+
+ /**
* Delete an {@link Anchor} based on given dataspace name & anchor name.
*
+ * @param apiVersion api version
* @param dataspaceName dataspace name
* @param anchorName anchor name
* @return a {@Link ResponseEntity} of {@link HttpStatus} NO_CONTENT
*/
@Override
- public ResponseEntity<Void> deleteAnchor(final String dataspaceName, final String anchorName) {
+ public ResponseEntity<Void> deleteAnchor(final String apiVersion,
+ final String dataspaceName, final String anchorName) {
cpsAdminService.deleteAnchor(dataspaceName, anchorName);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@@ -167,12 +216,14 @@ public class AdminRestController implements CpsAdminApi {
/**
* Get an {@link Anchor} based on given dataspace name & anchor name.
*
+ * @param apiVersion api version
* @param dataspaceName dataspace name
* @param anchorName anchor name
* @return a {@Link ResponseEntity} of an {@Link AnchorDetails} & {@link HttpStatus} OK
*/
@Override
- public ResponseEntity<AnchorDetails> getAnchor(final String dataspaceName, final String anchorName) {
+ public ResponseEntity<AnchorDetails> getAnchor(final String apiVersion,
+ final String dataspaceName, final String anchorName) {
final var anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
final var anchorDetails = cpsRestInputMapper.toAnchorDetails(anchor);
return new ResponseEntity<>(anchorDetails, HttpStatus.OK);
@@ -181,11 +232,13 @@ public class AdminRestController implements CpsAdminApi {
/**
* Get all {@link Anchor} based on given dataspace name.
*
+ * @param apiVersion api version
* @param dataspaceName dataspace name
* @return a {@Link ResponseEntity} of all {@Link AnchorDetails} & {@link HttpStatus} OK
*/
@Override
- public ResponseEntity<List<AnchorDetails>> getAnchors(final String dataspaceName) {
+ public ResponseEntity<List<AnchorDetails>> getAnchors(final String apiVersion,
+ final String dataspaceName) {
final Collection<Anchor> anchors = cpsAdminService.getAnchors(dataspaceName);
final List<AnchorDetails> anchorDetails = anchors.stream().map(cpsRestInputMapper::toAnchorDetails)
.collect(Collectors.toList());
@@ -193,7 +246,7 @@ public class AdminRestController implements CpsAdminApi {
}
@Override
- public ResponseEntity<List<DataspaceDetails>> getAllDataspaces() {
+ public ResponseEntity<List<DataspaceDetails>> getAllDataspaces(final String apiVersion) {
final Collection<Dataspace> dataspaces = cpsAdminService.getAllDataspaces();
final List<DataspaceDetails> dataspaceDetails = dataspaces.stream().map(cpsRestInputMapper::toDataspaceDetails)
.collect(Collectors.toList());
@@ -201,7 +254,7 @@ public class AdminRestController implements CpsAdminApi {
}
@Override
- public ResponseEntity<DataspaceDetails> getDataspace(final String dataspaceName) {
+ public ResponseEntity<DataspaceDetails> getDataspace(final String apiVersion, final String dataspaceName) {
final Dataspace dataspace = cpsAdminService.getDataspace(dataspaceName);
final DataspaceDetails dataspaceDetails = cpsRestInputMapper.toDataspaceDetails(dataspace);
return new ResponseEntity<>(dataspaceDetails, HttpStatus.OK);
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 fdce9bee6b..c7d44b67b3 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
@@ -3,6 +3,7 @@
* Copyright (C) 2020-2022 Bell Canada.
* Modifications Copyright (C) 2021 Pantheon.tech
* Modifications Copyright (C) 2021-2022 Nordix Foundation
+ * Modifications Copyright (C) 2022 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -53,7 +54,8 @@ public class DataRestController implements CpsDataApi {
private final PrefixResolver prefixResolver;
@Override
- public ResponseEntity<String> createNode(final String dataspaceName, final String anchorName,
+ public ResponseEntity<String> createNode(final String apiVersion,
+ final String dataspaceName, final String anchorName,
final Object jsonData, final String parentNodeXpath, final String observedTimestamp) {
final String jsonDataAsString = jsonObjectMapper.asJsonString(jsonData);
if (isRootXpath(parentNodeXpath)) {
@@ -67,7 +69,8 @@ public class DataRestController implements CpsDataApi {
}
@Override
- public ResponseEntity<Void> deleteDataNode(final String dataspaceName, final String anchorName,
+ 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));
@@ -75,7 +78,7 @@ public class DataRestController implements CpsDataApi {
}
@Override
- public ResponseEntity<String> addListElements(final String parentNodeXpath,
+ public ResponseEntity<String> addListElements(final String parentNodeXpath, final String apiVersion,
final String dataspaceName, final String anchorName, final Object jsonData, final String observedTimestamp) {
cpsDataService.saveListElements(dataspaceName, anchorName, parentNodeXpath,
jsonObjectMapper.asJsonString(jsonData), toOffsetDateTime(observedTimestamp));
@@ -83,8 +86,8 @@ public class DataRestController implements CpsDataApi {
}
@Override
- public ResponseEntity<Object> getNodeByDataspaceAndAnchor(final String dataspaceName, final String anchorName,
- final String xpath, final Boolean includeDescendants) {
+ public ResponseEntity<Object> getNodeByDataspaceAndAnchor(final String apiVersion,
+ final String dataspaceName, 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.getDataNode(dataspaceName, anchorName, xpath,
@@ -94,7 +97,7 @@ public class DataRestController implements CpsDataApi {
}
@Override
- public ResponseEntity<Object> updateNodeLeaves(final String dataspaceName,
+ public ResponseEntity<Object> updateNodeLeaves(final String apiVersion, final String dataspaceName,
final String anchorName, final Object jsonData, final String parentNodeXpath, final String observedTimestamp) {
cpsDataService.updateNodeLeaves(dataspaceName, anchorName, parentNodeXpath,
jsonObjectMapper.asJsonString(jsonData), toOffsetDateTime(observedTimestamp));
@@ -102,7 +105,8 @@ public class DataRestController implements CpsDataApi {
}
@Override
- public ResponseEntity<Object> replaceNode(final String dataspaceName, final String anchorName,
+ 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,
@@ -112,7 +116,7 @@ public class DataRestController implements CpsDataApi {
@Override
public ResponseEntity<Object> replaceListContent(final String parentNodeXpath,
- final String dataspaceName, final String anchorName, final Object jsonData,
+ final String apiVersion, final String dataspaceName, final String anchorName, final Object jsonData,
final String observedTimestamp) {
cpsDataService.replaceListContent(dataspaceName, anchorName, parentNodeXpath,
jsonObjectMapper.asJsonString(jsonData), toOffsetDateTime(observedTimestamp));
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 577ad9c262..3e162ae683 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
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2021-2022 Nordix Foundation
* Modifications Copyright (C) 2022 Bell Canada.
+ * Modifications Copyright (C) 2022 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,8 +49,8 @@ public class QueryRestController implements CpsQueryApi {
private final PrefixResolver prefixResolver;
@Override
- public ResponseEntity<Object> getNodesByDataspaceAndAnchorAndCpsPath(final String dataspaceName,
- final String anchorName, final String cpsPath, final Boolean includeDescendants) {
+ public ResponseEntity<Object> getNodesByDataspaceAndAnchorAndCpsPath(final String apiVersion,
+ final String dataspaceName, final String anchorName, final String cpsPath, final Boolean includeDescendants) {
final FetchDescendantsOption fetchDescendantsOption = Boolean.TRUE.equals(includeDescendants)
? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS : FetchDescendantsOption.OMIT_DESCENDANTS;
final Collection<DataNode> dataNodes =