diff options
Diffstat (limited to 'cps-ri/src/main/java/org')
-rw-r--r-- | cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java | 26 |
1 files changed, 25 insertions, 1 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 343a0886b..ae399a138 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 @@ -27,6 +27,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet.Builder; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -73,7 +74,30 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService final var fragmentEntity = toFragmentEntity(parentFragment.getDataspace(), parentFragment.getAnchor(), dataNode); parentFragment.getChildFragments().add(fragmentEntity); - fragmentRepository.save(parentFragment); + try { + fragmentRepository.save(parentFragment); + } catch (final DataIntegrityViolationException exception) { + throw AlreadyDefinedException.forDataNode(dataNode.getXpath(), anchorName, exception); + } + } + + @Override + public void addListDataNodes(final String dataspaceName, final String anchorName, final String parentNodeXpath, + final Collection<DataNode> dataNodes) { + final FragmentEntity parentFragment = getFragmentByXpath(dataspaceName, anchorName, parentNodeXpath); + final List<FragmentEntity> newFragmentEntities = + dataNodes.stream().map( + dataNode -> toFragmentEntity(parentFragment.getDataspace(), parentFragment.getAnchor(), dataNode) + ).collect(Collectors.toUnmodifiableList()); + parentFragment.getChildFragments().addAll(newFragmentEntities); + try { + fragmentRepository.save(parentFragment); + } catch (final DataIntegrityViolationException exception) { + final List<String> conflictXpaths = dataNodes.stream() + .map(DataNode::getXpath) + .collect(Collectors.toList()); + throw AlreadyDefinedException.forDataNodes(conflictXpaths, anchorName, exception); + } } @Override |