From 8e22c6a80b491cc98d4052e05dc94ee645bf2197 Mon Sep 17 00:00:00 2001 From: danielhanrahan Date: Sat, 31 Aug 2024 22:30:16 +0100 Subject: [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 Change-Id: I8fd18bb56b8ed9d26a3f9d36f487d00a9274c8bc --- .../cps/spi/repository/FragmentQueryBuilder.java | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'cps-ri/src/main/java/org/onap') 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 booleanOperatorsQueue = new LinkedList<>(cpsPathQuery.getBooleanOperators()); - final Queue 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()) { -- cgit 1.2.3-korg