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;
}
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();
}
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();
}
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);
}
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);
}
Aggregations