Search in sources :

Example 1 with SearchRedirectImpl

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")));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) SearchRedirect(org.broadleafcommerce.core.search.redirect.domain.SearchRedirect) ArrayList(java.util.ArrayList) SearchRedirectImpl(org.broadleafcommerce.core.search.redirect.domain.SearchRedirectImpl) Date(java.util.Date) Predicate(javax.persistence.criteria.Predicate)

Aggregations

ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Predicate (javax.persistence.criteria.Predicate)1 SearchRedirect (org.broadleafcommerce.core.search.redirect.domain.SearchRedirect)1 SearchRedirectImpl (org.broadleafcommerce.core.search.redirect.domain.SearchRedirectImpl)1