From 4111a57d03f054b46fddf030730d2e42b2755233 Mon Sep 17 00:00:00 2001 From: danielhanrahan Date: Thu, 19 Jan 2023 18:20:11 +0000 Subject: Handle root xpaths in getDataNodes Issue-ID: CPS-1458 Signed-off-by: danielhanrahan Change-Id: I64abf97317afe4335c8d04169689ee1396e75860 --- .../cps/spi/impl/CpsDataPersistenceServiceImpl.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'cps-ri/src/main') 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 b85b30d9d4..d2b7273fe1 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 @@ -265,17 +265,26 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName); final AnchorEntity anchorEntity = anchorRepository.getByDataspaceAndName(dataspaceEntity, anchorName); - final Set normalizedXpaths = new HashSet<>(xpaths.size()); - for (final String xpath : xpaths) { + final Collection nonRootXpaths = new HashSet<>(xpaths); + final boolean haveRootXpath = nonRootXpaths.removeIf(CpsDataPersistenceServiceImpl::isRootXpath); + + final Collection normalizedXpaths = new HashSet<>(nonRootXpaths.size()); + for (final String xpath : nonRootXpaths) { try { normalizedXpaths.add(CpsPathUtil.getNormalizedXpath(xpath)); } catch (final PathParsingException e) { log.warn("Error parsing xpath \"{}\" in getDataNodes: {}", xpath, e.getMessage()); } } + final Collection fragmentEntities = + new HashSet<>(fragmentRepository.findByAnchorAndMultipleCpsPaths(anchorEntity.getId(), normalizedXpaths)); + + if (haveRootXpath) { + final List fragmentExtracts = fragmentRepository.getTopLevelFragments(dataspaceEntity, + anchorEntity); + fragmentEntities.addAll(FragmentEntityArranger.toFragmentEntityTrees(anchorEntity, fragmentExtracts)); + } - final List fragmentEntities = - fragmentRepository.findByAnchorAndMultipleCpsPaths(anchorEntity.getId(), normalizedXpaths); return toDataNodes(fragmentEntities, fetchDescendantsOption); } -- cgit 1.2.3-korg