From: Toine Siebelink Date: Mon, 8 May 2023 09:26:46 +0000 (+0000) Subject: Merge "[CPS] RI: Code Refactoring # Replace '[\s\S]' to '.' as it is same as '.'... X-Git-Tag: 3.3.2~32 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=1be9234c5234883be1e8d66baf7a780fa6be8ccf;hp=-c;p=cps.git Merge "[CPS] RI: Code Refactoring # Replace '[\s\S]' to '.' as it is same as '.' while grouping in regex # Updated the groovy files to add 'assert' and to replace deprecated method # Removed deprecated 'storeDataNode' method." --- 1be9234c5234883be1e8d66baf7a780fa6be8ccf diff --combined cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java index 3a1588a59,16ec270c2..cca5d9c84 --- 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 @@@ -82,7 -82,7 +82,7 @@@ public class CpsDataPersistenceServiceI private final JsonObjectMapper jsonObjectMapper; private final SessionManager sessionManager; - private static final String REG_EX_FOR_OPTIONAL_LIST_INDEX = "(\\[@[\\s\\S]+?])?)"; + private static final String REG_EX_FOR_OPTIONAL_LIST_INDEX = "(\\[@.+?])?)"; private static final String QUERY_ACROSS_ANCHORS = null; private static final AnchorEntity ALL_ANCHORS = null; @@@ -170,11 -170,6 +170,6 @@@ } } - @Override - public void storeDataNode(final String dataspaceName, final String anchorName, final DataNode dataNode) { - storeDataNodes(dataspaceName, anchorName, Collections.singletonList(dataNode)); - } - @Override public void storeDataNodes(final String dataspaceName, final String anchorName, final Collection dataNodes) { @@@ -348,7 -343,6 +343,7 @@@ private static boolean canUseRegexQuickFind(final FetchDescendantsOption fetchDescendantsOption, final CpsPathQuery cpsPathQuery) { return fetchDescendantsOption.equals(FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) + && !cpsPathQuery.hasAncestorAxis() && !cpsPathQuery.hasLeafConditions() && !cpsPathQuery.hasTextFunctionCondition() && !cpsPathQuery.hasContainsFunctionCondition(); @@@ -357,12 -351,17 +352,12 @@@ private List getDataNodesUsingRegexQuickFind(final FetchDescendantsOption fetchDescendantsOption, final AnchorEntity anchorEntity, final CpsPathQuery cpsPathQuery) { - Collection fragmentEntities; final String xpathRegex = FragmentQueryBuilder.getXpathSqlRegexForQuickFindWithDescendants(cpsPathQuery); final List fragmentExtracts = (anchorEntity == ALL_ANCHORS) - ? fragmentRepository.quickFindWithDescendantsAcrossAnchor(xpathRegex) : - fragmentRepository.quickFindWithDescendants(anchorEntity.getId(), xpathRegex); - fragmentEntities = FragmentEntityArranger.toFragmentEntityTrees(anchorEntity, fragmentExtracts); - if (cpsPathQuery.hasAncestorAxis()) { - final Collection ancestorXpaths = processAncestorXpath(fragmentEntities, cpsPathQuery); - fragmentEntities = (anchorEntity == ALL_ANCHORS) ? getAncestorFragmentEntitiesAcrossAnchors(cpsPathQuery, - fragmentEntities) : getFragmentEntities(anchorEntity, ancestorXpaths, fetchDescendantsOption); - } + ? fragmentRepository.quickFindWithDescendantsAcrossAnchors(xpathRegex) + : fragmentRepository.quickFindWithDescendants(anchorEntity.getId(), xpathRegex); + final Collection fragmentEntities = + FragmentEntityArranger.toFragmentEntityTrees(anchorEntity, fragmentExtracts); return createDataNodesFromFragmentEntities(fetchDescendantsOption, fragmentEntities); } @@@ -434,8 -433,8 +429,8 @@@ final CpsPathQuery cpsPathQuery) { final Set ancestorXpath = new HashSet<>(); final Pattern pattern = - Pattern.compile("([\\s\\S]*/" + Pattern.quote(cpsPathQuery.getAncestorSchemaNodeIdentifier()) - + REG_EX_FOR_OPTIONAL_LIST_INDEX + "/[\\s\\S]*"); + Pattern.compile("(.*/" + Pattern.quote(cpsPathQuery.getAncestorSchemaNodeIdentifier()) + + REG_EX_FOR_OPTIONAL_LIST_INDEX + "/.*"); for (final FragmentEntity fragmentEntity : fragmentEntities) { final Matcher matcher = pattern.matcher(fragmentEntity.getXpath()); if (matcher.matches()) {