diff options
Diffstat (limited to 'cps-ri')
-rw-r--r-- | cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentQueryBuilder.java | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentQueryBuilder.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentQueryBuilder.java index e62471b005..b2014757d7 100644 --- a/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentQueryBuilder.java +++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentQueryBuilder.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2022-2023 Nordix Foundation + * Copyright (C) 2022-2024 Nordix Foundation * Modifications Copyright (C) 2023 TechMahindra Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -92,7 +92,8 @@ public class FragmentQueryBuilder { sqlStringBuilder.append("SELECT distinct(fragment.anchor_id) FROM fragment " + "JOIN anchor ON anchor.id = fragment.anchor_id WHERE dataspace_id = :dataspaceId"); queryParameters.put("dataspaceId", dataspaceEntity.getId()); - addXpathSearch(cpsPathQuery, sqlStringBuilder, queryParameters); + addAbsoluteParentXpathSearchCondition(cpsPathQuery, sqlStringBuilder, queryParameters, ACROSS_ALL_ANCHORS); + addXpathSearchCondition(cpsPathQuery, sqlStringBuilder, queryParameters); addLeafConditions(cpsPathQuery, sqlStringBuilder); addTextFunctionCondition(cpsPathQuery, sqlStringBuilder, queryParameters); addContainsFunctionCondition(cpsPathQuery, sqlStringBuilder, queryParameters); @@ -125,7 +126,8 @@ public class FragmentQueryBuilder { sqlStringBuilder.append("SELECT * FROM fragment WHERE anchor_id = :anchorId"); queryParameters.put("anchorId", anchorEntity.getId()); } - addXpathSearch(cpsPathQuery, sqlStringBuilder, queryParameters); + addAbsoluteParentXpathSearchCondition(cpsPathQuery, sqlStringBuilder, queryParameters, anchorEntity); + addXpathSearchCondition(cpsPathQuery, sqlStringBuilder, queryParameters); addLeafConditions(cpsPathQuery, sqlStringBuilder); addTextFunctionCondition(cpsPathQuery, sqlStringBuilder, queryParameters); addContainsFunctionCondition(cpsPathQuery, sqlStringBuilder, queryParameters); @@ -135,9 +137,9 @@ public class FragmentQueryBuilder { return query; } - private static void addXpathSearch(final CpsPathQuery cpsPathQuery, - final StringBuilder sqlStringBuilder, - final Map<String, Object> queryParameters) { + private static void addXpathSearchCondition(final CpsPathQuery cpsPathQuery, + final StringBuilder sqlStringBuilder, + final Map<String, Object> queryParameters) { sqlStringBuilder.append(" AND (xpath LIKE :escapedXpath OR " + "(xpath LIKE :escapedXpath||'[@%]' AND xpath NOT LIKE :escapedXpath||'[@%]/%[@%]'))"); if (CpsPathPrefixType.ABSOLUTE.equals(cpsPathQuery.getCpsPathPrefixType())) { @@ -147,6 +149,25 @@ public class FragmentQueryBuilder { } } + private static void addAbsoluteParentXpathSearchCondition(final CpsPathQuery cpsPathQuery, + final StringBuilder sqlStringBuilder, + final Map<String, Object> queryParameters, + final AnchorEntity anchorEntity) { + if (CpsPathPrefixType.ABSOLUTE.equals(cpsPathQuery.getCpsPathPrefixType())) { + if (cpsPathQuery.getNormalizedParentPath().isEmpty()) { + sqlStringBuilder.append(" AND parent_id IS NULL"); + } else { + if (anchorEntity == ACROSS_ALL_ANCHORS) { + sqlStringBuilder.append(" AND parent_id IN (SELECT id FROM fragment WHERE xpath = :parentXpath)"); + } else { + sqlStringBuilder.append(" AND parent_id = (SELECT id FROM fragment WHERE xpath = :parentXpath" + + " AND anchor_id = :anchorId)"); + } + queryParameters.put("parentXpath", cpsPathQuery.getNormalizedParentPath()); + } + } + } + private static void addPaginationCondition(final StringBuilder sqlStringBuilder, final Map<String, Object> queryParameters, final PaginationOption paginationOption) { |