summaryrefslogtreecommitdiffstats
path: root/cps-ri/src/main
diff options
context:
space:
mode:
authorNiamh Core <niamh.core@est.tech>2021-08-16 15:41:27 +0000
committerGerrit Code Review <gerrit@onap.org>2021-08-16 15:41:27 +0000
commitf351ced1db57e63663b84acdab9410aa517018c8 (patch)
treec85a4e3cf6b7d650f1269268c3a5fde92677ccde /cps-ri/src/main
parentd80bc376f1412fa892601a6e763c4702590c2e88 (diff)
parentc6babc01c2bce84bd8cfe358d94513ece2c37046 (diff)
Merge "Issue with CPSData API to add an item to an existing list node"
Diffstat (limited to 'cps-ri/src/main')
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java14
1 files changed, 14 insertions, 0 deletions
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
index fdbafd4bee..adb29b6292 100644
--- a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
@@ -108,6 +108,9 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
parentFragment.getChildFragments().addAll(newFragmentEntities);
try {
fragmentRepository.save(parentFragment);
+ dataNodes.forEach(
+ dataNode -> getChildFragments(dataspaceName, anchorName, dataNode)
+ );
} catch (final DataIntegrityViolationException exception) {
final List<String> conflictXpaths = dataNodes.stream()
.map(DataNode::getXpath)
@@ -152,6 +155,17 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
return parentFragment;
}
+ private void getChildFragments(final String dataspaceName, final String anchorName, final DataNode dataNode) {
+ for (final DataNode childDataNode: dataNode.getChildDataNodes()) {
+ final FragmentEntity getChildsParentFragmentByXPath =
+ getFragmentByXpath(dataspaceName, anchorName, dataNode.getXpath());
+ final FragmentEntity childFragmentEntity = toFragmentEntity(getChildsParentFragmentByXPath.getDataspace(),
+ getChildsParentFragmentByXPath.getAnchor(), childDataNode);
+ getChildsParentFragmentByXPath.getChildFragments().add(childFragmentEntity);
+ fragmentRepository.save(getChildsParentFragmentByXPath);
+ }
+ }
+
private static FragmentEntity toFragmentEntity(final DataspaceEntity dataspaceEntity,
final AnchorEntity anchorEntity, final DataNode dataNode) {
return FragmentEntity.builder()