Search in sources :

Example 1 with OrderStatus

use of org.broadleafcommerce.core.order.service.type.OrderStatus in project BroadleafCommerce by BroadleafCommerce.

the class ResourcePurgeServiceImpl method getCartsToPurgeLength.

/**
 * Get the count of carts to delete from the database. Subclasses may override for custom cart retrieval logic.
 *
 * @param purgeParams configured parameters for the Customer purge process used in the query
 * @param cartsInError list of cart ids to ignore/exclude from the next purge run
 * @return count of carts to delete
 */
/**
 */
protected Long getCartsToPurgeLength(CartPurgeParams purgeParams, List<Long> cartsInError) {
    String[] nameArray = purgeParams.getNameArray();
    OrderStatus[] statusArray = purgeParams.getStatusArray();
    Date dateCreatedMinThreshold = purgeParams.getDateCreatedMinThreshold();
    Boolean isPreview = purgeParams.getIsPreview();
    Long cartBatchSize = purgeParams.getBatchSize();
    Long orderCount = resourcePurgeDao.findCartsCount(nameArray, statusArray, dateCreatedMinThreshold, isPreview, cartsInError);
    // return the lesser of the parameter batch size of the count of the orders to purge
    return cartBatchSize != null && cartBatchSize < orderCount ? cartBatchSize : orderCount;
}
Also used : OrderStatus(org.broadleafcommerce.core.order.service.type.OrderStatus) Date(java.util.Date)

Example 2 with OrderStatus

use of org.broadleafcommerce.core.order.service.type.OrderStatus in project BroadleafCommerce by BroadleafCommerce.

the class OrderItemDaoImpl method readBatchOrderItems.

@Override
public List<OrderItem> readBatchOrderItems(int start, int count, List<OrderStatus> statuses) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<OrderItem> criteria = builder.createQuery(OrderItem.class);
    Root<OrderImpl> order = criteria.from(OrderImpl.class);
    Join<Order, OrderItem> orderItems = order.join("orderItems");
    criteria.select(orderItems);
    List<Predicate> restrictions = new ArrayList<>();
    criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
    if (CollectionUtils.isNotEmpty(statuses)) {
        // We only want results that match the orders with the correct status
        ArrayList<String> statusStrings = new ArrayList<String>();
        for (OrderStatus status : statuses) {
            statusStrings.add(status.getType());
        }
        criteria.where(order.get("status").as(String.class).in(statusStrings));
    }
    TypedQuery<OrderItem> query = em.createQuery(criteria);
    query.setFirstResult(start);
    query.setMaxResults(count);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Order");
    return query.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(org.broadleafcommerce.core.order.domain.Order) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate) OrderStatus(org.broadleafcommerce.core.order.service.type.OrderStatus) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) OrderImpl(org.broadleafcommerce.core.order.domain.OrderImpl)

Example 3 with OrderStatus

use of org.broadleafcommerce.core.order.service.type.OrderStatus in project BroadleafCommerce by BroadleafCommerce.

the class OrderDaoImpl method readBatchOrders.

@Override
public List<Order> readBatchOrders(int start, int pageSize, List<OrderStatus> statuses) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<Order> criteria = builder.createQuery(Order.class);
    Root<OrderImpl> order = criteria.from(OrderImpl.class);
    criteria.select(order);
    if (CollectionUtils.isNotEmpty(statuses)) {
        // We only want results that match the orders with the correct status
        ArrayList<String> statusStrings = new ArrayList<String>();
        for (OrderStatus status : statuses) {
            statusStrings.add(status.getType());
        }
        criteria.where(order.get("status").as(String.class).in(statusStrings));
    }
    TypedQuery<Order> query = em.createQuery(criteria);
    query.setFirstResult(start);
    query.setMaxResults(pageSize);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Order");
    return query.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(org.broadleafcommerce.core.order.domain.Order) OrderStatus(org.broadleafcommerce.core.order.service.type.OrderStatus) NullOrderImpl(org.broadleafcommerce.core.order.domain.NullOrderImpl) OrderImpl(org.broadleafcommerce.core.order.domain.OrderImpl) ArrayList(java.util.ArrayList)

Example 4 with OrderStatus

use of org.broadleafcommerce.core.order.service.type.OrderStatus in project BroadleafCommerce by BroadleafCommerce.

the class ResourcePurgeDaoImpl method buildCartQuery.

protected <T> TypedQuery<T> buildCartQuery(String[] names, OrderStatus[] statuses, Date dateCreatedMinThreshold, Boolean isPreview, Class<T> returnType, List<Long> excludedIds) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<T> criteria = builder.createQuery(returnType);
    Root<OrderImpl> root = criteria.from(OrderImpl.class);
    if (Long.class.equals(returnType)) {
        criteria.select((Selection<? extends T>) builder.count(root));
    } else {
        criteria.select((Selection<? extends T>) root);
    }
    List<Predicate> restrictions = new ArrayList<Predicate>();
    List<String> statusList = new ArrayList<String>();
    if (statuses != null) {
        for (OrderStatus status : statuses) {
            statusList.add(status.getType());
        }
    } else {
        statusList.add("IN_PROCESS");
    }
    restrictions.add(root.get("status").in(statusList));
    if (names != null) {
        restrictions.add(root.get("name").in(Arrays.asList(names)));
    }
    if (dateCreatedMinThreshold != null) {
        restrictions.add(builder.lessThan(root.get("auditable").get("dateCreated").as(Date.class), dateCreatedMinThreshold));
    }
    if (isPreview != null) {
        if (isPreview) {
            restrictions.add(builder.isTrue(root.get("previewable").get("isPreview").as(Boolean.class)));
        } else {
            restrictions.add(builder.or(builder.isNull(root.get("previewable").get("isPreview")), builder.isFalse(root.get("previewable").get("isPreview").as(Boolean.class))));
        }
    }
    if (excludedIds != null && excludedIds.size() > 0) {
        applyLimitedInClause(excludedIds, builder, root, restrictions);
    }
    criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
    return em.createQuery(criteria);
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) OrderStatus(org.broadleafcommerce.core.order.service.type.OrderStatus) OrderImpl(org.broadleafcommerce.core.order.domain.OrderImpl) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate)

Example 5 with OrderStatus

use of org.broadleafcommerce.core.order.service.type.OrderStatus in project BroadleafCommerce by BroadleafCommerce.

the class ResourcePurgeServiceImpl method getCartsToPurge.

/**
 * Get the list of carts to delete from the database. Subclasses may override for custom cart retrieval logic.
 *
 * @param purgeParams configured parameters for the Cart purge process
 * @param cartsInError list of cart ids to be ignored/excluded from the query
 * @return list of carts to delete
 */
protected List<Order> getCartsToPurge(CartPurgeParams purgeParams, int startPos, int length, List<Long> cartsInError) {
    String[] nameArray = purgeParams.getNameArray();
    OrderStatus[] statusArray = purgeParams.getStatusArray();
    Date dateCreatedMinThreshold = purgeParams.getDateCreatedMinThreshold();
    Boolean isPreview = purgeParams.getIsPreview();
    return resourcePurgeDao.findCarts(nameArray, statusArray, dateCreatedMinThreshold, isPreview, startPos, length, cartsInError);
}
Also used : OrderStatus(org.broadleafcommerce.core.order.service.type.OrderStatus) Date(java.util.Date)

Aggregations

OrderStatus (org.broadleafcommerce.core.order.service.type.OrderStatus)5 ArrayList (java.util.ArrayList)3 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)3 OrderImpl (org.broadleafcommerce.core.order.domain.OrderImpl)3 Date (java.util.Date)2 Predicate (javax.persistence.criteria.Predicate)2 Order (org.broadleafcommerce.core.order.domain.Order)2 GiftWrapOrderItem (org.broadleafcommerce.core.order.domain.GiftWrapOrderItem)1 NullOrderImpl (org.broadleafcommerce.core.order.domain.NullOrderImpl)1 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)1