summaryrefslogtreecommitdiffstats
path: root/cps-ri/src/main
diff options
context:
space:
mode:
authorToine Siebelink <toine.siebelink@est.tech>2023-07-20 08:52:40 +0000
committerGerrit Code Review <gerrit@onap.org>2023-07-20 08:52:40 +0000
commit6a2eca2859d8b2ab88ff04663902eb7cc74b4fc1 (patch)
treeae627157f1d6adf1dc6535ac351f928746746d4b /cps-ri/src/main
parent6c9621a3ec2334ccf5cee8db23e425b301a53e0c (diff)
parentea71bef75b22c31a4b40a3cacbf5da2ddecb544b (diff)
Merge "Allow duplicate leaf names in Cps Path leaf condition"
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 ");