aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ri
diff options
context:
space:
mode:
authorDylanB95EST <dylan.byrne@est.tech>2021-08-09 18:39:14 +0100
committerDylanB95EST <dylan.byrne@est.tech>2021-08-16 16:28:20 +0100
commitc6babc01c2bce84bd8cfe358d94513ece2c37046 (patch)
tree993747f979a38c749cbf7ef0ae6cbdd8df27ce1c /cps-ri
parent0e210d77ec39915046a95615f5f9d2a2dc65162b (diff)
Issue with CPSData API to add an item to an existing list node
Issueing Fix for Bug around 2 Api's /cps/api/v1/dataspaces/{dataspacename}/anchors/{anchor-name}/list-node and cps-ncmp/api/ncmp-dmi/v1/ch where child data nodes do not get persisted to the DB. Issue-ID: CPS-524 Change-Id: I4e433a2fddd56b8714b798a2d5b0e5fb683e3205 Signed-off-by: DylanB95EST <dylan.byrne@est.tech>
Diffstat (limited to 'cps-ri')
-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()