aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ri/src/main/java/org
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-ri/src/main/java/org
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-ri/src/main/java/org')
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java25
1 files changed, 25 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 ae399a1381..10440924e9 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
@@ -35,6 +35,7 @@ import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
+import javax.transaction.Transactional;
import org.onap.cps.spi.CpsDataPersistenceService;
import org.onap.cps.spi.FetchDescendantsOption;
import org.onap.cps.spi.entities.AnchorEntity;
@@ -253,6 +254,30 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
fragmentRepository.save(fragmentEntity);
}
+ @Override
+ @Transactional
+ public void replaceListDataNodes(final String dataspaceName, final String anchorName, final String parentNodeXpath,
+ final Collection<DataNode> dataNodes) {
+ final var parentEntity = getFragmentByXpath(dataspaceName, anchorName, parentNodeXpath);
+ final var firstChildNodeXpath = dataNodes.iterator().next().getXpath();
+ final var listNodeXpath = firstChildNodeXpath.substring(0, firstChildNodeXpath.lastIndexOf("["));
+ removeListNodeDescendants(parentEntity, listNodeXpath);
+ final Set<FragmentEntity> childFragmentEntities = dataNodes.stream().map(
+ dataNode -> convertToFragmentWithAllDescendants(
+ parentEntity.getDataspace(), parentEntity.getAnchor(), dataNode)
+ ).collect(Collectors.toUnmodifiableSet());
+ parentEntity.getChildFragments().addAll(childFragmentEntities);
+ fragmentRepository.save(parentEntity);
+ }
+
+ private void removeListNodeDescendants(final FragmentEntity parentFragmentEntity, final String listNodeXpath) {
+ final String listNodeXpathPrefix = listNodeXpath + "[";
+ if (parentFragmentEntity.getChildFragments()
+ .removeIf(fragment -> fragment.getXpath().startsWith(listNodeXpathPrefix))) {
+ fragmentRepository.save(parentFragmentEntity);
+ }
+ }
+
private void removeExistingDescendants(final FragmentEntity fragmentEntity) {
fragmentEntity.setChildFragments(Collections.emptySet());
fragmentRepository.save(fragmentEntity);