summaryrefslogtreecommitdiffstats
path: root/cps-ri/src
diff options
context:
space:
mode:
authordanielhanrahan <daniel.hanrahan@est.tech>2024-08-31 22:30:16 +0100
committerdanielhanrahan <daniel.hanrahan@est.tech>2024-08-31 22:32:12 +0100
commit8e22c6a80b491cc98d4052e05dc94ee645bf2197 (patch)
treec6a43a986f141eb6ff7dc662888b3da6688796c4 /cps-ri/src
parent5b2edb3e260d1daf69b36e42c5a5bc2e23d64615 (diff)
[Cps Path Parser] Refactoring leaf conditions
Instead of DataLeaf and ComparativeOperators classes, we more simply have LeafConditions class with all info. Issue-ID: CPS-2365 Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech> Change-Id: I8fd18bb56b8ed9d26a3f9d36f487d00a9274c8bc
Diffstat (limited to 'cps-ri/src')
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentQueryBuilder.java20
1 files changed, 9 insertions, 11 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 b2014757d7..8171bbe621 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
@@ -194,22 +194,20 @@ public class FragmentQueryBuilder {
private void queryLeafConditions(final CpsPathQuery cpsPathQuery, final StringBuilder sqlStringBuilder) {
sqlStringBuilder.append(" AND (");
final Queue<String> booleanOperatorsQueue = new LinkedList<>(cpsPathQuery.getBooleanOperators());
- final Queue<String> comparativeOperatorQueue = new LinkedList<>(cpsPathQuery.getComparativeOperators());
- cpsPathQuery.getLeavesData().forEach(leaf -> {
- final String nextComparativeOperator = comparativeOperatorQueue.poll();
- if (leaf.getValue() instanceof Integer) {
- sqlStringBuilder.append("(attributes ->> '").append(leaf.getName()).append("')\\:\\:int");
- sqlStringBuilder.append(nextComparativeOperator);
- sqlStringBuilder.append(leaf.getValue());
+ cpsPathQuery.getLeafConditions().forEach(leafCondition -> {
+ if (leafCondition.value() instanceof Integer) {
+ sqlStringBuilder.append("(attributes ->> '").append(leafCondition.name()).append("')\\:\\:int");
+ sqlStringBuilder.append(leafCondition.operator());
+ sqlStringBuilder.append(leafCondition.value());
} else {
- if ("=".equals(nextComparativeOperator)) {
- final String leafValueAsText = leaf.getValue().toString();
- sqlStringBuilder.append("attributes ->> '").append(leaf.getName()).append("'");
+ if ("=".equals(leafCondition.operator())) {
+ final String leafValueAsText = leafCondition.value().toString();
+ sqlStringBuilder.append("attributes ->> '").append(leafCondition.name()).append("'");
sqlStringBuilder.append(" = '");
sqlStringBuilder.append(EscapeUtils.escapeForSqlStringLiteral(leafValueAsText));
sqlStringBuilder.append("'");
} else {
- throw new CpsPathException(" can use only " + nextComparativeOperator + " with integer ");
+ throw new CpsPathException(" can use only " + leafCondition.operator() + " with integer ");
}
}
if (!booleanOperatorsQueue.isEmpty()) {