From 3621cfaad16e698c21d4bf73e453d6158bfbd853 Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Sat, 9 Mar 2019 11:10:18 -0500 Subject: 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) --- .../repository/InfraActiveRequestsRepositoryImpl.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'mso-api-handlers/mso-requests-db-repositories/src/main/java') 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 criteriaQuery = criteriaBuilder.createQuery(InfraActiveRequests.class); final Root 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 getPredicates(final Map filters, final CriteriaBuilder criteriaBuilder, + protected List getPredicates(final Map filters, final CriteriaBuilder criteriaBuilder, final Root tableRoot) { final List predicates = new LinkedList<>(); for (final Entry entry : filters.entrySet()) { -- cgit 1.2.3-korg