From d7bc158cd274b3d6cd01bcad86aef258e6880c1c Mon Sep 17 00:00:00 2001 From: Rudrangi Anupriya Date: Mon, 17 Apr 2023 14:19:46 +0530 Subject: Add contains condition support to cps-path Issue-ID: CPS-1272 Change-Id: Ic81d1322cacc64a8752916324b801d02be47d34f Signed-off-by: Rudrangi Anupriya --- .../org/onap/cps/spi/repository/FragmentQueryBuilder.java | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'cps-ri/src/main/java') 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 ca6e18bad3..ab9c02e888 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 @@ -98,6 +98,7 @@ public class FragmentQueryBuilder { sqlStringBuilder.append(")"); } addTextFunctionCondition(cpsPathQuery, sqlStringBuilder, queryParameters); + addContainsFunctionCondition(cpsPathQuery, sqlStringBuilder, queryParameters); final Query query = entityManager.createNativeQuery(sqlStringBuilder.toString(), FragmentEntity.class); setQueryParameters(query, queryParameters); return query; @@ -160,6 +161,16 @@ public class FragmentQueryBuilder { } } + private static void addContainsFunctionCondition(final CpsPathQuery cpsPathQuery, + final StringBuilder sqlStringBuilder, + final Map queryParameters) { + if (cpsPathQuery.hasContainsFunctionCondition()) { + sqlStringBuilder.append(" AND attributes ->> :containsLeafName LIKE CONCAT('%',:containsValue,'%') "); + queryParameters.put("containsLeafName", cpsPathQuery.getContainsFunctionConditionLeafName()); + queryParameters.put("containsValue", cpsPathQuery.getContainsFunctionConditionValue()); + } + } + private static void setQueryParameters(final Query query, final Map queryParameters) { for (final Map.Entry queryParameter : queryParameters.entrySet()) { query.setParameter(queryParameter.getKey(), queryParameter.getValue()); -- cgit 1.2.3-korg