summaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-requests-db-repositories/src/main
diff options
context:
space:
mode:
authorBenjamin, Max (mb388a) <mb388a@us.att.com>2019-03-09 11:10:18 -0500
committerBenjamin, Max (mb388a) <mb388a@us.att.com>2019-03-09 11:10:18 -0500
commit3621cfaad16e698c21d4bf73e453d6158bfbd853 (patch)
treea3c10a688f7c103fcfe9582b3de6880d45313878 /mso-api-handlers/mso-requests-db-repositories/src/main
parente77d365050c7a465278908f7774464ee8095f4a1 (diff)
db search logic/unit test now works as expected
modified search predicate to inclue null or endtime do not duplicate time boundaries in predicate Change-Id: I5a3b0f323c0e08717419669a8b2a11461ca2b990 Issue-ID: SO-1615 Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'mso-api-handlers/mso-requests-db-repositories/src/main')
-rw-r--r--mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryImpl.java16
1 files changed, 6 insertions, 10 deletions
diff --git a/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryImpl.java b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryImpl.java
index 761aaa1446..e3f15764d7 100644
--- a/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryImpl.java
+++ b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryImpl.java
@@ -551,6 +551,7 @@ public class InfraActiveRequestsRepositoryImpl implements InfraActiveRequestsRep
}
try {
final CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
+
final CriteriaQuery<InfraActiveRequests> criteriaQuery =
criteriaBuilder.createQuery(InfraActiveRequests.class);
final Root<InfraActiveRequests> tableRoot = criteriaQuery.from(InfraActiveRequests.class);
@@ -558,17 +559,12 @@ public class InfraActiveRequestsRepositoryImpl implements InfraActiveRequestsRep
final Timestamp minTime = new Timestamp(startTime);
final Timestamp maxTime = new Timestamp(endTime);
- predicates.add(criteriaBuilder.greaterThanOrEqualTo(tableRoot.get(START_TIME), minTime));
- predicates.add(criteriaBuilder.lessThanOrEqualTo(tableRoot.get(END_TIME), maxTime));
-
final Predicate basePredicate = criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
-
- final Predicate additionalPredicate = criteriaBuilder.and(tableRoot.get(END_TIME).isNull(),
- criteriaBuilder.greaterThanOrEqualTo(tableRoot.get(START_TIME), minTime),
- criteriaBuilder.lessThanOrEqualTo(tableRoot.get(START_TIME), maxTime));
-
- criteriaQuery.where(criteriaBuilder.or(basePredicate, additionalPredicate));
+ final Predicate additionalPredicate = criteriaBuilder.and(
+ criteriaBuilder.greaterThanOrEqualTo(tableRoot.get(START_TIME), minTime),
+ criteriaBuilder.or(tableRoot.get(END_TIME).isNull(), criteriaBuilder.lessThanOrEqualTo(tableRoot.get(END_TIME), maxTime)));
+ criteriaQuery.where(criteriaBuilder.and(basePredicate, additionalPredicate));
if (maxResult != null) {
return entityManager.createQuery(criteriaQuery).setMaxResults(maxResult).getResultList();
}
@@ -579,7 +575,7 @@ public class InfraActiveRequestsRepositoryImpl implements InfraActiveRequestsRep
}
}
- private List<Predicate> getPredicates(final Map<String, String[]> filters, final CriteriaBuilder criteriaBuilder,
+ protected List<Predicate> getPredicates(final Map<String, String[]> filters, final CriteriaBuilder criteriaBuilder,
final Root<InfraActiveRequests> tableRoot) {
final List<Predicate> predicates = new LinkedList<>();
for (final Entry<String, String[]> entry : filters.entrySet()) {