diff options
author | Sourabh Sourabh <sourabh.sourabh@est.tech> | 2022-09-19 10:08:46 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2022-09-19 10:08:46 +0000 |
commit | 9978739d2f5d5abb48b29822ac9470fc8758cd0f (patch) | |
tree | cadd57f3d29b8b29d2e29b7cc7d23336c4cb08d0 /cps-ri/src/main | |
parent | fd1572fc8e792d95f99cda1a79de47dc3b7e47a1 (diff) | |
parent | 19a59f369cbb348441d69d5e2675f17e0e1b7f3f (diff) |
Merge "Get Node API fix for attribute values with '/'"
Diffstat (limited to 'cps-ri/src/main')
-rw-r--r-- | cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepositoryCpsPathQueryImpl.java | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepositoryCpsPathQueryImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepositoryCpsPathQueryImpl.java index 47a3e8f319..654c1c0854 100644 --- a/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepositoryCpsPathQueryImpl.java +++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepositoryCpsPathQueryImpl.java @@ -38,8 +38,8 @@ import org.onap.cps.utils.JsonObjectMapper; @Slf4j public class FragmentRepositoryCpsPathQueryImpl implements FragmentRepositoryCpsPathQuery { - public static final String SIMILAR_TO_ABSOLUTE_PATH_PREFIX = "%/"; - public static final String SIMILAR_TO_OPTIONAL_LIST_INDEX_POSTFIX = "(\\[[^/]*])?"; + public static final String REGEX_ABSOLUTE_PATH_PREFIX = ".*\\/"; + public static final String REGEX_OPTIONAL_LIST_INDEX_POSTFIX = "(\\[@(?!.*\\[).*?])?$"; @PersistenceContext private EntityManager entityManager; @@ -51,8 +51,8 @@ public class FragmentRepositoryCpsPathQueryImpl implements FragmentRepositoryCps final StringBuilder sqlStringBuilder = new StringBuilder("SELECT * FROM FRAGMENT WHERE anchor_id = :anchorId"); final Map<String, Object> queryParameters = new HashMap<>(); queryParameters.put("anchorId", anchorId); - sqlStringBuilder.append(" AND xpath SIMILAR TO :xpathRegex"); - final String xpathRegex = getSimilarToXpathSqlRegex(cpsPathQuery); + sqlStringBuilder.append(" AND xpath ~ :xpathRegex"); + final String xpathRegex = getXpathSqlRegex(cpsPathQuery); queryParameters.put("xpathRegex", xpathRegex); if (cpsPathQuery.hasLeafConditions()) { sqlStringBuilder.append(" AND attributes @> :leafDataAsJson\\:\\:jsonb"); @@ -68,15 +68,15 @@ public class FragmentRepositoryCpsPathQueryImpl implements FragmentRepositoryCps return fragmentEntities; } - private static String getSimilarToXpathSqlRegex(final CpsPathQuery cpsPathQuery) { + private static String getXpathSqlRegex(final CpsPathQuery cpsPathQuery) { final StringBuilder xpathRegexBuilder = new StringBuilder(); if (CpsPathPrefixType.ABSOLUTE.equals(cpsPathQuery.getCpsPathPrefixType())) { xpathRegexBuilder.append(escapeXpath(cpsPathQuery.getXpathPrefix())); } else { - xpathRegexBuilder.append(SIMILAR_TO_ABSOLUTE_PATH_PREFIX); + xpathRegexBuilder.append(REGEX_ABSOLUTE_PATH_PREFIX); xpathRegexBuilder.append(escapeXpath(cpsPathQuery.getDescendantName())); } - xpathRegexBuilder.append(SIMILAR_TO_OPTIONAL_LIST_INDEX_POSTFIX); + xpathRegexBuilder.append(REGEX_OPTIONAL_LIST_INDEX_POSTFIX); return xpathRegexBuilder.toString(); } |