summaryrefslogtreecommitdiffstats
path: root/cps-ri/src/main
diff options
context:
space:
mode:
authordanielhanrahan <daniel.hanrahan@est.tech>2023-07-14 13:09:41 +0100
committerDaniel Hanrahan <daniel.hanrahan@est.tech>2023-07-17 16:23:37 +0000
commitea71bef75b22c31a4b40a3cacbf5da2ddecb544b (patch)
treedb00ee9e23fb1decec2a8fe6eefd8f04192a1086 /cps-ri/src/main
parentdcf84ad73f0301ef41049e692b9963f6dcac3661 (diff)
Allow duplicate leaf names in Cps Path leaf condition
Presently, a query using the same leaf name twice will fail: //books[@price > 10 and @price < 20] It is caused by storing data leaves in a Map. This is fixed by storing data leaves in a List<DataLeaf>. Issue-ID: CPS-1779 Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech> Change-Id: Ie6990ea5e622cf37e986b720a0a07fb69ce4f03b
Diffstat (limited to 'cps-ri/src/main')
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentQueryBuilder.java21
1 files changed, 9 insertions, 12 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 7b5c0c693f..be06ebac03 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
@@ -37,7 +37,6 @@ import org.onap.cps.spi.entities.DataspaceEntity;
import org.onap.cps.spi.entities.FragmentEntity;
import org.onap.cps.spi.exceptions.CpsPathException;
import org.onap.cps.spi.utils.EscapeUtils;
-import org.onap.cps.utils.JsonObjectMapper;
import org.springframework.stereotype.Component;
@RequiredArgsConstructor
@@ -49,8 +48,6 @@ public class FragmentQueryBuilder {
@PersistenceContext
private EntityManager entityManager;
- private final JsonObjectMapper jsonObjectMapper;
-
/**
* Create a sql query to retrieve by anchor(id) and cps path.
*
@@ -128,18 +125,18 @@ public class FragmentQueryBuilder {
sqlStringBuilder.append(" AND (");
final Queue<String> booleanOperatorsQueue = new LinkedList<>(cpsPathQuery.getBooleanOperators());
final Queue<String> comparativeOperatorQueue = new LinkedList<>(cpsPathQuery.getComparativeOperators());
- cpsPathQuery.getLeavesData().entrySet().forEach(entry -> {
+ cpsPathQuery.getLeavesData().forEach(leaf -> {
final String nextComparativeOperator = comparativeOperatorQueue.poll();
- if (entry.getValue() instanceof Integer) {
- sqlStringBuilder.append("(attributes ->> ");
- sqlStringBuilder.append("'").append(entry.getKey()).append("')\\:\\:int");
- sqlStringBuilder.append(" ").append(nextComparativeOperator).append(" ");
- sqlStringBuilder.append("'").append(jsonObjectMapper.asJsonString(entry.getValue())).append("'");
+ if (leaf.getValue() instanceof Integer) {
+ sqlStringBuilder.append("(attributes ->> '").append(leaf.getName()).append("')\\:\\:int");
+ sqlStringBuilder.append(nextComparativeOperator);
+ sqlStringBuilder.append(leaf.getValue());
} else {
if ("=".equals(nextComparativeOperator)) {
- sqlStringBuilder.append(" attributes @> ");
- sqlStringBuilder.append("'");
- sqlStringBuilder.append(jsonObjectMapper.asJsonString(entry));
+ final String leafValueAsText = leaf.getValue().toString();
+ sqlStringBuilder.append("attributes ->> '").append(leaf.getName()).append("'");
+ sqlStringBuilder.append(" = '");
+ sqlStringBuilder.append(leafValueAsText);
sqlStringBuilder.append("'");
} else {
throw new CpsPathException(" can use only " + nextComparativeOperator + " with integer ");