diff options
Diffstat (limited to 'cps-service/src/main/java/org')
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 |