class InfraActiveRequestsRepositoryImpl implements InfraActiveRequestsRepositoryCustom {

    @Override
    public List<InfraActiveRequests> getInfraActiveRequests(final Map<String, String[]> filters, final long startTime,
            final long endTime, final Integer maxResult) {
        if (filters == null) {
            return Collections.emptyList();
        }
        try {
            final CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();

            final CriteriaQuery<InfraActiveRequests> criteriaQuery =
                    criteriaBuilder.createQuery(InfraActiveRequests.class);
            final Root<InfraActiveRequests> tableRoot = criteriaQuery.from(InfraActiveRequests.class);
            final List<Predicate> predicates = getPredicates(filters, criteriaBuilder, tableRoot);

            final Timestamp minTime = new Timestamp(startTime);
            final Timestamp maxTime = new Timestamp(endTime);
            final Predicate basePredicate = criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
            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();
            }
            return entityManager.createQuery(criteriaQuery).getResultList();
        } catch (final Exception exception) {
            logger.error("Unable to execute query using filters: {}", filters, exception);
            return Collections.emptyList();
        }
    }

}