summaryrefslogtreecommitdiffstats
path: root/cps-service/src/main/java
diff options
context:
space:
mode:
authorRuslan Kashapov <ruslan.kashapov@pantheon.tech>2021-05-14 12:04:34 +0300
committerRishi Chail <rishi.chail@est.tech>2021-05-24 15:36:55 +0000
commitb0e78acb6aefdcb5866955802099e6091b2a6952 (patch)
tree8f06ec09b2d9fba00dc8dfe4fbbe639330417c15 /cps-service/src/main/java
parent940d8e4a950d8ce8075a712d9dc3852de828e5b5 (diff)
Replace list-node content (part 1): CPS Service and persistence layers
Issue-ID: CPS-362 Change-Id: I669c9fc6ef67c1992fe95e17a765f0c616b00f7e Signed-off-by: Ruslan Kashapov <ruslan.kashapov@pantheon.tech>
Diffstat (limited to 'cps-service/src/main/java')
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/CpsDataService.java14
-rwxr-xr-xcps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java18
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java11
3 files changed, 39 insertions, 4 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java b/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java
index 8e59ebcbb0..3b50c51445 100644
--- a/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java
+++ b/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java
@@ -105,4 +105,18 @@ public interface CpsDataService {
*/
void replaceNodeTree(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
@NonNull String jsonData);
+
+ /**
+ * Replaces (if exists) child data fragment representing list-node (with one or more elements)
+ * under existing data node for the given anchor and dataspace.
+ *
+ * @param dataspaceName dataspace name
+ * @param anchorName anchor name
+ * @param parentNodeXpath parent node xpath
+ * @param jsonData json data representing list element
+ * @throws DataValidationException when json data is invalid (incl. list-node being empty)
+ * @throws DataNodeNotFoundException when parent node cannot be found by parent node xpath
+ */
+ void replaceListNodeData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
+ @NonNull String jsonData);
}
diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java
index 523657a7fc..23bf4f2ee9 100755
--- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java
+++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java
@@ -71,9 +71,6 @@ public class CpsDataServiceImpl implements CpsDataService {
final String parentNodeXpath, final String jsonData) {
final Collection<DataNode> dataNodesCollection =
buildDataNodeCollectionFromJson(dataspaceName, anchorName, parentNodeXpath, jsonData);
- if (dataNodesCollection.isEmpty()) {
- throw new DataValidationException("Invalid list data.", "List node is empty.");
- }
cpsDataPersistenceService.addListDataNodes(dataspaceName, anchorName, parentNodeXpath, dataNodesCollection);
}
@@ -98,6 +95,14 @@ public class CpsDataServiceImpl implements CpsDataService {
cpsDataPersistenceService.replaceDataNodeTree(dataspaceName, anchorName, dataNode);
}
+ @Override
+ public void replaceListNodeData(final String dataspaceName, final String anchorName, final String parentNodeXpath,
+ final String jsonData) {
+ final Collection<DataNode> dataNodes =
+ buildDataNodeCollectionFromJson(dataspaceName, anchorName, parentNodeXpath, jsonData);
+ cpsDataPersistenceService.replaceListDataNodes(dataspaceName, anchorName, parentNodeXpath, dataNodes);
+ }
+
private DataNode buildDataNodeFromJson(final String dataspaceName, final String anchorName,
final String parentNodeXpath, final String jsonData) {
@@ -123,10 +128,15 @@ public class CpsDataServiceImpl implements CpsDataService {
final var schemaContext = getSchemaContext(dataspaceName, anchor.getSchemaSetName());
final NormalizedNode<?, ?> normalizedNode = YangUtils.parseJsonData(jsonData, schemaContext, parentNodeXpath);
- return new DataNodeBuilder()
+ final Collection<DataNode> dataNodes = new DataNodeBuilder()
.withParentNodeXpath(parentNodeXpath)
.withNormalizedNodeTree(normalizedNode)
.buildCollection();
+ if (dataNodes.isEmpty()) {
+ throw new DataValidationException("Invalid list data.", "List node is empty.");
+ }
+ return dataNodes;
+
}
private SchemaContext getSchemaContext(final String dataspaceName, final String schemaSetName) {
diff --git a/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java b/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java
index 0ed3bf0051..3b16b0d813 100644
--- a/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java
+++ b/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java
@@ -101,6 +101,17 @@ public interface CpsDataPersistenceService {
void replaceDataNodeTree(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull DataNode dataNode);
/**
+ * Replaces existing list data node content including descendants.
+ *
+ * @param dataspaceName dataspace name
+ * @param anchorName anchor name
+ * @param parentNodeXpath parent node xpath
+ * @param dataNodes collection of data nodes representing list node elements
+ */
+ void replaceListDataNodes(@NonNull String dataspaceName, @NonNull String anchorName,
+ @NonNull String parentNodeXpath, @NonNull Collection<DataNode> dataNodes);
+
+ /**
* Get a datanode by cps path.
*
* @param dataspaceName dataspace name