aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ri
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ri')
-rw-r--r--cps-ri/pom.xml2
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentQueryBuilder.java38
2 files changed, 23 insertions, 17 deletions
diff --git a/cps-ri/pom.xml b/cps-ri/pom.xml
index e9b2abb3f3..7ce24d960b 100644
--- a/cps-ri/pom.xml
+++ b/cps-ri/pom.xml
@@ -33,7 +33,7 @@
<artifactId>cps-ri</artifactId>
<properties>
- <minimum-coverage>0.82</minimum-coverage>
+ <minimum-coverage>0.80</minimum-coverage>
</properties>
<dependencies>
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 c231595931..ca6e18bad3 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
@@ -22,12 +22,16 @@
package org.onap.cps.spi.repository;
import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
+import java.util.Queue;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
import org.onap.cps.cpspath.parser.CpsPathPrefixType;
import org.onap.cps.cpspath.parser.CpsPathQuery;
import org.onap.cps.spi.entities.FragmentEntity;
@@ -60,18 +64,7 @@ public class FragmentQueryBuilder {
final Map<String, Object> queryParameters = new HashMap<>();
queryParameters.put("anchorId", anchorId);
sqlStringBuilder.append(" AND xpath ~ :xpathRegex");
- final String xpathRegex = getXpathSqlRegex(cpsPathQuery, false);
- queryParameters.put("xpathRegex", xpathRegex);
- if (cpsPathQuery.hasLeafConditions()) {
- sqlStringBuilder.append(" AND attributes @> :leafDataAsJson\\:\\:jsonb");
- queryParameters.put("leafDataAsJson", jsonObjectMapper.asJsonString(
- cpsPathQuery.getLeavesData()));
- }
-
- addTextFunctionCondition(cpsPathQuery, sqlStringBuilder, queryParameters);
- final Query query = entityManager.createNativeQuery(sqlStringBuilder.toString(), FragmentEntity.class);
- setQueryParameters(query, queryParameters);
- return query;
+ return getQuery(cpsPathQuery, sqlStringBuilder, queryParameters);
}
/**
@@ -83,14 +76,27 @@ public class FragmentQueryBuilder {
public Query getQueryForCpsPath(final CpsPathQuery cpsPathQuery) {
final StringBuilder sqlStringBuilder = new StringBuilder("SELECT * FROM FRAGMENT WHERE xpath ~ :xpathRegex");
final Map<String, Object> queryParameters = new HashMap<>();
+ return getQuery(cpsPathQuery, sqlStringBuilder, queryParameters);
+ }
+
+ private Query getQuery(final CpsPathQuery cpsPathQuery, final StringBuilder sqlStringBuilder,
+ final Map<String, Object> queryParameters) {
final String xpathRegex = getXpathSqlRegex(cpsPathQuery, false);
queryParameters.put("xpathRegex", xpathRegex);
+ final List<String> queryBooleanOperatorsType = cpsPathQuery.getBooleanOperatorsType();
if (cpsPathQuery.hasLeafConditions()) {
- sqlStringBuilder.append(" AND attributes @> :leafDataAsJson\\:\\:jsonb");
- queryParameters.put("leafDataAsJson", jsonObjectMapper.asJsonString(
- cpsPathQuery.getLeavesData()));
+ sqlStringBuilder.append(" AND (");
+ final Queue<String> booleanOperatorsQueue = (queryBooleanOperatorsType == null) ? null : new LinkedList<>(
+ queryBooleanOperatorsType);
+ cpsPathQuery.getLeavesData().entrySet().forEach(entry -> {
+ sqlStringBuilder.append(" attributes @> ");
+ sqlStringBuilder.append("'" + jsonObjectMapper.asJsonString(entry) + "'");
+ if (!CollectionUtils.isEmpty(booleanOperatorsQueue)) {
+ sqlStringBuilder.append(" " + booleanOperatorsQueue.poll() + " ");
+ }
+ });
+ sqlStringBuilder.append(")");
}
-
addTextFunctionCondition(cpsPathQuery, sqlStringBuilder, queryParameters);
final Query query = entityManager.createNativeQuery(sqlStringBuilder.toString(), FragmentEntity.class);
setQueryParameters(query, queryParameters);