From c6babc01c2bce84bd8cfe358d94513ece2c37046 Mon Sep 17 00:00:00 2001 From: DylanB95EST Date: Mon, 9 Aug 2021 18:39:14 +0100 Subject: 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 --- .../onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'cps-ri/src') 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 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() -- cgit 1.2.3-korg