aboutsummaryrefslogtreecommitdiffstats
path: root/cps-rest
diff options
context:
space:
mode:
authorRuslan Kashapov <ruslan.kashapov@pantheon.tech>2021-05-05 13:11:50 +0300
committerRuslan Kashapov <ruslan.kashapov@pantheon.tech>2021-05-11 10:20:48 +0300
commit0905ac124ea1d8ab5067b4b00ece0469961cfa36 (patch)
treed7167be17e4b59d98cedffce2da756a5e50aff63 /cps-rest
parent25e3306737b7284b051dfeaedb39ef83323504d9 (diff)
Create list-node elements (part2): CPS REST layer
Issue-ID: CPS-360 Change-Id: Iaca8baff085e1659453c06ce0dee0203aa007b4a Signed-off-by: Ruslan Kashapov <ruslan.kashapov@pantheon.tech>
Diffstat (limited to 'cps-rest')
-rwxr-xr-xcps-rest/docs/api/swagger/components.yml7
-rwxr-xr-xcps-rest/docs/api/swagger/cpsData.yml27
-rwxr-xr-xcps-rest/docs/api/swagger/openapi.yml3
-rwxr-xr-xcps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java9
-rwxr-xr-xcps-rest/src/test/groovy/org/onap/cps/rest/controller/DataRestControllerSpec.groovy22
5 files changed, 63 insertions, 5 deletions
diff --git a/cps-rest/docs/api/swagger/components.yml b/cps-rest/docs/api/swagger/components.yml
index bb1f120022..5a21a730ef 100755
--- a/cps-rest/docs/api/swagger/components.yml
+++ b/cps-rest/docs/api/swagger/components.yml
@@ -75,6 +75,13 @@ components:
schema:
type: string
default: /
+ requiredXpathInQuery:
+ name: xpath
+ in: query
+ description: xpath
+ required: true
+ schema:
+ type: string
cpsPathInQuery:
name: cps-path
in: query
diff --git a/cps-rest/docs/api/swagger/cpsData.yml b/cps-rest/docs/api/swagger/cpsData.yml
index 54c89661b9..c0cd85b28d 100755
--- a/cps-rest/docs/api/swagger/cpsData.yml
+++ b/cps-rest/docs/api/swagger/cpsData.yml
@@ -23,6 +23,33 @@ nodeByDataspaceAndAnchor:
$ref: 'components.yml#/components/responses/NotFound'
x-codegen-request-body-name: xpath
+listNodeByDataspaceAndAnchor:
+ post:
+ description: Add list-node child elements to existing node for a given anchor and dataspace
+ tags:
+ - cps-data
+ summary: Add list-node child element(s) under existing parent node
+ operationId: addListNodeElements
+ parameters:
+ - $ref: 'components.yml#/components/parameters/dataspaceNameInPath'
+ - $ref: 'components.yml#/components/parameters/anchorNameInPath'
+ - $ref: 'components.yml#/components/parameters/requiredXpathInQuery'
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: string
+ responses:
+ '201':
+ $ref: 'components.yml#/components/responses/Created'
+ '400':
+ $ref: 'components.yml#/components/responses/BadRequest'
+ '401':
+ $ref: 'components.yml#/components/responses/Unauthorized'
+ '403':
+ $ref: 'components.yml#/components/responses/Forbidden'
+
nodesByDataspaceAndAnchor:
post:
description: Create a node for a given anchor and dataspace
diff --git a/cps-rest/docs/api/swagger/openapi.yml b/cps-rest/docs/api/swagger/openapi.yml
index 38fbebe67b..3c0cc09e59 100755
--- a/cps-rest/docs/api/swagger/openapi.yml
+++ b/cps-rest/docs/api/swagger/openapi.yml
@@ -48,6 +48,9 @@ paths:
/v1/dataspaces/{dataspace-name}/anchors/{anchor-name}/nodes:
$ref: 'cpsData.yml#/nodesByDataspaceAndAnchor'
+ /v1/dataspaces/{dataspace-name}/anchors/{anchor-name}/list-node:
+ $ref: 'cpsData.yml#/listNodeByDataspaceAndAnchor'
+
/v1/dataspaces/{dataspace-name}/nodes:
$ref: 'cpsData.yml#/nodesByDataspace'
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 c8b7412593..3d16539b3e 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
@@ -52,6 +52,13 @@ public class DataRestController implements CpsDataApi {
}
@Override
+ public ResponseEntity<String> addListNodeElements(final String jsonData, final String parentNodeXpath,
+ final String dataspaceName, final String anchorName) {
+ cpsDataService.saveListNodeData(dataspaceName, anchorName, parentNodeXpath, jsonData);
+ return new ResponseEntity<>(HttpStatus.CREATED);
+ }
+
+ @Override
public ResponseEntity<Object> getNodesByDataspace(final String dataspaceName) {
return null;
}
@@ -62,7 +69,7 @@ public class DataRestController implements CpsDataApi {
final FetchDescendantsOption fetchDescendantsOption = Boolean.TRUE.equals(includeDescendants)
? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS : FetchDescendantsOption.OMIT_DESCENDANTS;
final var dataNode = cpsDataService.getDataNode(dataspaceName, anchorName, xpath,
- fetchDescendantsOption);
+ fetchDescendantsOption);
return new ResponseEntity<>(DataMapUtils.toDataMap(dataNode), HttpStatus.OK);
}
diff --git a/cps-rest/src/test/groovy/org/onap/cps/rest/controller/DataRestControllerSpec.groovy b/cps-rest/src/test/groovy/org/onap/cps/rest/controller/DataRestControllerSpec.groovy
index b64b56178a..18d20a8e20 100755
--- a/cps-rest/src/test/groovy/org/onap/cps/rest/controller/DataRestControllerSpec.groovy
+++ b/cps-rest/src/test/groovy/org/onap/cps/rest/controller/DataRestControllerSpec.groovy
@@ -33,10 +33,6 @@ import org.onap.cps.api.CpsAdminService
import org.onap.cps.api.CpsDataService
import org.onap.cps.api.CpsModuleService
import org.onap.cps.api.CpsQueryService
-import org.onap.cps.spi.exceptions.AlreadyDefinedException
-import org.onap.cps.spi.exceptions.AnchorNotFoundException
-import org.onap.cps.spi.exceptions.DataNodeNotFoundException
-import org.onap.cps.spi.exceptions.DataspaceNotFoundException
import org.onap.cps.spi.model.DataNode
import org.onap.cps.spi.model.DataNodeBuilder
import org.spockframework.spring.SpringBean
@@ -131,6 +127,24 @@ class DataRestControllerSpec extends Specification {
1 * mockCpsDataService.saveData(dataspaceName, anchorName, parentNodeXpath, json)
}
+ def 'Create list node child elements.'() {
+ given: 'parent node xpath and json data inputs'
+ def parentNodeXpath = 'parent node xpath'
+ def jsonData = 'json data'
+ when: 'post is invoked list-node endpoint'
+ def response = mvc.perform(
+ post("$dataNodeBaseEndpoint/anchors/$anchorName/list-node")
+ .contentType(MediaType.APPLICATION_JSON)
+ .param('xpath', parentNodeXpath)
+ .content(jsonData)
+ ).andReturn().response
+ then: 'a created response is returned'
+ response.status == HttpStatus.CREATED.value()
+ then: 'the java API was called with the correct parameters'
+ 1 * mockCpsDataService.saveListNodeData(dataspaceName, anchorName, parentNodeXpath, jsonData)
+
+ }
+
def 'Get data node with leaves'() {
given: 'the service returns data node leaves'
def xpath = 'some xPath'