From 337c8d436186d87742caefc95aeee7ba2a36b687 Mon Sep 17 00:00:00 2001 From: sourabh_sourabh Date: Tue, 1 Nov 2022 14:40:25 +0000 Subject: Node API - GET Method performance issue - Modified toDataNode call based on fetch descendants option. - Used fragment extract to build fragment entity. - Modified data set to have correct parent id for descendants. Reviewers : Toine, Priyank and Joe Issue-ID: CPS-1171 Signed-off-by: sourabh_sourabh Change-Id: I27a537fe72dd396722e6cfde7d8c454ed2579ec0 Signed-off-by: sourabh_sourabh --- .../spi/impl/CpsDataPersistenceServiceImpl.java | 57 +++++++++++++++++----- 1 file changed, 44 insertions(+), 13 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 5fe646ff8..dc848e657 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 @@ -232,22 +232,13 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService if (isRootXpath(xpath)) { return fragmentRepository.findFirstRootByDataspaceAndAnchor(dataspaceEntity, anchorEntity); } else { - final String normalizedXpath; - try { - normalizedXpath = CpsPathUtil.getNormalizedXpath(xpath); - } catch (final PathParsingException e) { - throw new CpsPathException(e.getMessage()); - } + final String normalizedXpath = getNormalizedXpath(xpath); final FragmentEntity fragmentEntity; if (FetchDescendantsOption.OMIT_DESCENDANTS.equals(fetchDescendantsOption)) { fragmentEntity = fragmentRepository.getByDataspaceAndAnchorAndXpath(dataspaceEntity, anchorEntity, normalizedXpath); } else { - final List fragmentExtracts = - fragmentRepository.findByAnchorIdAndParentXpath(anchorEntity.getId(), normalizedXpath); - log.debug("Fetched {} fragment entities by anchor {} and cps path {}.", - fragmentExtracts.size(), anchorName, xpath); - fragmentEntity = FragmentEntityArranger.toFragmentEntityTree(anchorEntity, fragmentExtracts); + fragmentEntity = buildFragmentEntityFromFragmentExtracts(anchorEntity, normalizedXpath); } if (fragmentEntity == null) { throw new DataNodeNotFoundException(dataspaceEntity.getName(), anchorEntity.getName(), xpath); @@ -256,6 +247,17 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService } } + private FragmentEntity buildFragmentEntityFromFragmentExtracts(final AnchorEntity anchorEntity, + final String normalizedXpath) { + final FragmentEntity fragmentEntity; + final List fragmentExtracts = + fragmentRepository.findByAnchorIdAndParentXpath(anchorEntity.getId(), normalizedXpath); + log.debug("Fetched {} fragment entities by anchor {} and cps path {}.", + fragmentExtracts.size(), anchorEntity.getName(), normalizedXpath); + fragmentEntity = FragmentEntityArranger.toFragmentEntityTree(anchorEntity, fragmentExtracts); + return fragmentEntity; + } + @Override public List queryDataNodes(final String dataspaceName, final String anchorName, final String cpsPath, final FetchDescendantsOption fetchDescendantsOption) { @@ -274,8 +276,37 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService fragmentEntities = ancestorXpaths.isEmpty() ? Collections.emptyList() : fragmentRepository.findAllByAnchorAndXpathIn(anchorEntity, ancestorXpaths); } - return fragmentEntities.stream().map(fragmentEntity -> toDataNode(fragmentEntity, fetchDescendantsOption)) - .collect(Collectors.toUnmodifiableList()); + return createDataNodesFromFragmentEntities(fetchDescendantsOption, anchorEntity, + fragmentEntities); + } + + private List createDataNodesFromFragmentEntities(final FetchDescendantsOption fetchDescendantsOption, + final AnchorEntity anchorEntity, + final List fragmentEntities) { + final List dataNodes = new ArrayList<>(fragmentEntities.size()); + for (final FragmentEntity proxiedFragmentEntity : fragmentEntities) { + final DataNode dataNode; + if (FetchDescendantsOption.OMIT_DESCENDANTS.equals(fetchDescendantsOption)) { + dataNode = toDataNode(proxiedFragmentEntity, fetchDescendantsOption); + } else { + final String normalizedXpath = getNormalizedXpath(proxiedFragmentEntity.getXpath()); + final FragmentEntity unproxiedFragmentEntity = buildFragmentEntityFromFragmentExtracts(anchorEntity, + normalizedXpath); + dataNode = toDataNode(unproxiedFragmentEntity, fetchDescendantsOption); + } + dataNodes.add(dataNode); + } + return Collections.unmodifiableList(dataNodes); + } + + private static String getNormalizedXpath(final String xpathSource) { + final String normalizedXpath; + try { + normalizedXpath = CpsPathUtil.getNormalizedXpath(xpathSource); + } catch (final PathParsingException e) { + throw new CpsPathException(e.getMessage()); + } + return normalizedXpath; } @Override -- cgit 1.2.3-korg