diff options
author | Toine Siebelink <toine.siebelink@est.tech> | 2023-07-20 08:52:40 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2023-07-20 08:52:40 +0000 |
commit | 6a2eca2859d8b2ab88ff04663902eb7cc74b4fc1 (patch) | |
tree | ae627157f1d6adf1dc6535ac351f928746746d4b /cps-ri/src/main/java/org/onap | |
parent | 6c9621a3ec2334ccf5cee8db23e425b301a53e0c (diff) | |
parent | ea71bef75b22c31a4b40a3cacbf5da2ddecb544b (diff) |
Merge "Allow duplicate leaf names in Cps Path leaf condition"
Diffstat (limited to 'cps-ri/src/main/java/org/onap')
-rw-r--r-- | cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentQueryBuilder.java | 21 |
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 "); |