use of org.broadleafcommerce.core.search.redirect.domain.SearchRedirectImpl in project BroadleafCommerce by BroadleafCommerce.
the class SearchRedirectDaoImpl method buildFindSearchRedirectBySearchTermCriteria.
private CriteriaQuery<SearchRedirect> buildFindSearchRedirectBySearchTermCriteria(String searchTerm) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<SearchRedirect> criteria = builder.createQuery(SearchRedirect.class);
Root<SearchRedirectImpl> redirect = criteria.from(SearchRedirectImpl.class);
List<Predicate> restrictions = new ArrayList<>();
restrictions.add(builder.equal(builder.upper(redirect.<String>get("searchTerm")), searchTerm.toUpperCase()));
// Add the active start/end date restrictions
Date currentDate = getCurrentDateAfterFactoringInDateResolution();
if (isNullActiveStartDateActive) {
restrictions.add(builder.or(builder.isNull(redirect.get("activeStartDate")), builder.lessThanOrEqualTo(redirect.get("activeStartDate").as(Date.class), currentDate)));
} else {
restrictions.add(builder.and(builder.isNotNull(redirect.get("activeStartDate")), builder.lessThanOrEqualTo(redirect.get("activeStartDate").as(Date.class), currentDate)));
}
restrictions.add(builder.or(builder.isNull(redirect.get("activeEndDate")), builder.greaterThan(redirect.get("activeEndDate").as(Date.class), currentDate)));
// Add the restrictions to the criteria query
criteria.select(redirect);
criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
return criteria.orderBy(builder.asc(redirect.get("searchPriority")));
}
Aggregations