diff options
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.java | 66 |
1 files changed, 37 insertions, 29 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 39cccd8aaa..761aaa1446 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 @@ -22,23 +22,6 @@ package org.onap.so.db.request.data.repository; -import org.onap.so.db.request.beans.InfraActiveRequests; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Repository; -import org.springframework.transaction.annotation.Transactional; - -import javax.persistence.EntityManager; -import javax.persistence.NonUniqueResultException; -import javax.persistence.Query; -import javax.persistence.TypedQuery; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Order; -import javax.persistence.criteria.Predicate; -import javax.persistence.criteria.Root; import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -52,6 +35,24 @@ import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.TimeUnit; +import javax.persistence.EntityManager; +import javax.persistence.NonUniqueResultException; +import javax.persistence.Query; +import javax.persistence.TypedQuery; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Order; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; + +import org.onap.so.db.request.beans.InfraActiveRequests; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + @Repository @Transactional(readOnly = true) @@ -219,17 +220,17 @@ public class InfraActiveRequestsRepositoryImpl implements InfraActiveRequestsRep } } } - if(!predicates.isEmpty()){ - predicates.add(tableRoot.get(REQUEST_STATUS) - .in(Arrays.asList("PENDING", "IN_PROGRESS", "TIMEOUT", "PENDING_MANUAL_TASK"))); - - final Order order = cb.desc(tableRoot.get(START_TIME)); - - final List<InfraActiveRequests> dupList = executeInfraQuery(crit, predicates, order); - - if (dupList != null && !dupList.isEmpty()) { - infraActiveRequests = dupList.get(0); - } + if (!predicates.isEmpty()) { + predicates.add(tableRoot.get(REQUEST_STATUS) + .in(Arrays.asList("PENDING", "IN_PROGRESS", "TIMEOUT", "PENDING_MANUAL_TASK"))); + + final Order order = cb.desc(tableRoot.get(START_TIME)); + + final List<InfraActiveRequests> dupList = executeInfraQuery(crit, predicates, order); + + if (dupList != null && !dupList.isEmpty()) { + infraActiveRequests = dupList.get(0); + } } return infraActiveRequests; @@ -560,7 +561,14 @@ public class InfraActiveRequestsRepositoryImpl implements InfraActiveRequestsRep predicates.add(criteriaBuilder.greaterThanOrEqualTo(tableRoot.get(START_TIME), minTime)); predicates.add(criteriaBuilder.lessThanOrEqualTo(tableRoot.get(END_TIME), maxTime)); - criteriaQuery.where(criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]))); + 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)); + if (maxResult != null) { return entityManager.createQuery(criteriaQuery).setMaxResults(maxResult).getResultList(); } |