aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ri/src
diff options
context:
space:
mode:
authorLuke Gleeson <luke.gleeson@est.tech>2023-04-21 14:31:07 +0000
committerGerrit Code Review <gerrit@onap.org>2023-04-21 14:31:07 +0000
commitf5d8051bef715762a31f54d052f7e126e8276fd0 (patch)
treefe2b973b045f8b1414f9ae0556c09d90dee557f7 /cps-ri/src
parentb3c3d36266493a93cb40a5d76de9fc5b80fec789 (diff)
parentd7bc158cd274b3d6cd01bcad86aef258e6880c1c (diff)
Merge "Add contains condition support to cps-path"
Diffstat (limited to 'cps-ri/src')
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentQueryBuilder.java11
1 files changed, 11 insertions, 0 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 1643ca078a..212eb93cb2 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
@@ -97,6 +97,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;
@@ -159,6 +160,16 @@ public class FragmentQueryBuilder {
}
}
+ private static void addContainsFunctionCondition(final CpsPathQuery cpsPathQuery,
+ final StringBuilder sqlStringBuilder,
+ final Map<String, Object> 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<String, Object> queryParameters) {
for (final Map.Entry<String, Object> queryParameter : queryParameters.entrySet()) {
query.setParameter(queryParameter.getKey(), queryParameter.getValue());