diff options
Diffstat (limited to 'cps-ri/src')
-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 "); |