From 24bf350947acb7fcb62878932d520387bc922a96 Mon Sep 17 00:00:00 2001 From: Ruslan Kashapov Date: Mon, 19 Apr 2021 12:40:01 +0300 Subject: Create child data node (part 1): CPS service + REST Issue-ID: CPS-337 Change-Id: I9c5c62d144b5301ac80e2b82a5cc66a980dad011 Signed-off-by: Ruslan Kashapov --- .../onap/cps/rest/controller/DataRestController.java | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 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 f466ebcef0..3385f35fe8 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 @@ -21,8 +21,6 @@ package org.onap.cps.rest.controller; -import javax.validation.Valid; -import javax.validation.constraints.NotNull; import org.onap.cps.api.CpsDataService; import org.onap.cps.rest.api.CpsDataApi; import org.onap.cps.spi.FetchDescendantsOption; @@ -38,13 +36,19 @@ import org.springframework.web.bind.annotation.RestController; @RequestMapping("${rest.api.cps-base-path}") public class DataRestController implements CpsDataApi { + private static final String ROOT_XPATH = "/"; + @Autowired private CpsDataService cpsDataService; @Override - public ResponseEntity createNode(@Valid final String jsonData, @NotNull final String dataspaceName, - @NotNull @Valid final String anchorName) { - cpsDataService.saveData(dataspaceName, anchorName, jsonData); + public ResponseEntity createNode(final String jsonData, final String dataspaceName, final String anchorName, + final String parentNodeXpath) { + if (isRootXpath(parentNodeXpath)) { + cpsDataService.saveData(dataspaceName, anchorName, jsonData); + } else { + cpsDataService.saveData(dataspaceName, anchorName, parentNodeXpath, jsonData); + } return new ResponseEntity<>(HttpStatus.CREATED); } @@ -56,7 +60,7 @@ public class DataRestController implements CpsDataApi { @Override public ResponseEntity getNodeByDataspaceAndAnchor(final String dataspaceName, final String anchorName, final String xpath, final Boolean includeDescendants) { - if ("/".equals(xpath)) { + if (isRootXpath(xpath)) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } final FetchDescendantsOption fetchDescendantsOption = Boolean.TRUE.equals(includeDescendants) @@ -79,4 +83,8 @@ public class DataRestController implements CpsDataApi { cpsDataService.replaceNodeTree(dataspaceName, anchorName, parentNodeXpath, jsonData); return new ResponseEntity<>(HttpStatus.OK); } + + private static boolean isRootXpath(final String xpath) { + return ROOT_XPATH.equals(xpath); + } } -- cgit 1.2.3-korg