use of org.olat.resource.accesscontrol.OrderStatus in project OpenOLAT by OpenOLAT.
the class ACFrontendManager method findOrderItems.
@Override
public List<OrderTableItem> findOrderItems(OLATResource resource, IdentityRef delivery, Long orderNr, Date from, Date to, OrderStatus[] status, int firstResult, int maxResults, List<UserPropertyHandler> userPropertyHandlers, SortKey... orderBy) {
List<AccessMethod> methods = methodManager.getAllMethods();
Map<String, AccessMethod> methodMap = new HashMap<>();
for (AccessMethod method : methods) {
methodMap.put(method.getKey().toString(), method);
}
List<RawOrderItem> rawOrders = orderManager.findNativeOrderItems(resource, delivery, orderNr, from, to, status, firstResult, maxResults, userPropertyHandlers, orderBy);
List<OrderTableItem> items = new ArrayList<>(rawOrders.size());
for (RawOrderItem rawOrder : rawOrders) {
String orderStatusStr = rawOrder.getOrderStatus();
OrderStatus orderStatus = OrderStatus.valueOf(orderStatusStr);
Status finalStatus = getStatus(orderStatusStr, rawOrder.getTrxStatus(), rawOrder.getPspTrxStatus());
String methodIds = rawOrder.getTrxMethodIds();
List<AccessMethod> orderMethods = new ArrayList<>(2);
if (StringHelper.containsNonWhitespace(methodIds)) {
String[] methodIdArr = methodIds.split(",");
for (String methodId : methodIdArr) {
if (methodMap.containsKey(methodId)) {
orderMethods.add(methodMap.get(methodId));
}
}
}
OrderTableItem item = new OrderTableItem(rawOrder.getOrderKey(), rawOrder.getOrderNr(), rawOrder.getTotal(), rawOrder.getCreationDate(), orderStatus, finalStatus, rawOrder.getDeliveryKey(), rawOrder.getUsername(), rawOrder.getUserProperties(), orderMethods);
item.setResourceDisplayname(rawOrder.getResourceName());
items.add(item);
}
return items;
}
use of org.olat.resource.accesscontrol.OrderStatus in project OpenOLAT by OpenOLAT.
the class ACOrderDAO method findOrdersByResource.
public List<Order> findOrdersByResource(OLATResource resource, OrderStatus... status) {
StringBuilder sb = new StringBuilder();
sb.append("select distinct(o) from ").append(OrderImpl.class.getName()).append(" o").append(" inner join o.parts orderPart ").append(" inner join orderPart.lines orderLine ").append(" inner join orderLine.offer offer ").append(" where offer.resource.key=:resourceKey");
if (status != null && status.length > 0) {
sb.append(" and o.orderStatusStr in (:status)");
}
TypedQuery<Order> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Order.class).setParameter("resourceKey", resource.getKey());
if (status != null && status.length > 0) {
List<String> statusStr = new ArrayList<String>();
for (OrderStatus s : status) {
statusStr.add(s.name());
}
query.setParameter("status", statusStr);
}
return query.getResultList();
}
use of org.olat.resource.accesscontrol.OrderStatus in project OpenOLAT by OpenOLAT.
the class ACOrderDAO method countNativeOrderItems.
/**
* The method is optimized for our settings: 1 order -> 1 order part -> 1 order line
*
* @param resource
* @param delivery
* @return
*/
public int countNativeOrderItems(OLATResource resource, IdentityRef delivery, Long orderNr, Date from, Date to, OrderStatus... status) {
NativeQueryBuilder sb = new NativeQueryBuilder(1024, dbInstance);
sb.append("select count(o.order_id)").append(" from o_ac_order o").append(" inner join o_ac_order_part order_part on (o.order_id=order_part.fk_order_id and order_part.pos=0)").append(" inner join o_ac_order_line order_line on (order_part.order_part_id=order_line.fk_order_part_id and order_line.pos=0)").append(" inner join o_ac_offer offer on (order_line.fk_offer_id=offer.offer_id)");
boolean where = false;
if (resource != null) {
where = PersistenceHelper.appendAnd(sb, where);
sb.append(" offer.fk_resource_id=:resourceKey ");
}
if (delivery != null) {
where = PersistenceHelper.appendAnd(sb, where);
sb.append(" o.fk_delivery_id=:deliveryKey ");
}
if (status != null && status.length > 0 && status[0] != null) {
where = PersistenceHelper.appendAnd(sb, where);
sb.append("o.order_status in (:status)");
}
if (from != null) {
where = PersistenceHelper.appendAnd(sb, where);
sb.append("o.creationdate >=:from");
}
if (to != null) {
where = PersistenceHelper.appendAnd(sb, where);
sb.append("o.creationdate <=:to");
}
if (orderNr != null) {
where = PersistenceHelper.appendAnd(sb, where);
sb.append("o.order_id=:orderNr");
}
Query query = dbInstance.getCurrentEntityManager().createNativeQuery(sb.toString());
if (resource != null) {
query.setParameter("resourceKey", resource.getKey());
}
if (delivery != null) {
query.setParameter("deliveryKey", delivery.getKey());
}
if (status != null && status.length > 0 && status[0] != null) {
List<String> statusStr = new ArrayList<String>();
for (OrderStatus s : status) {
statusStr.add(s.name());
}
query.setParameter("status", statusStr);
}
if (orderNr != null) {
query.setParameter("orderNr", orderNr);
}
if (from != null) {
Calendar cal = Calendar.getInstance();
cal.setTime(from);
cal.set(Calendar.HOUR, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
query.setParameter("from", cal.getTime(), TemporalType.TIMESTAMP);
}
if (to != null) {
Calendar cal = Calendar.getInstance();
cal.setTime(to);
cal.set(Calendar.HOUR, 23);
cal.set(Calendar.MINUTE, 59);
cal.set(Calendar.SECOND, 59);
cal.set(Calendar.MILLISECOND, 0);
query.setParameter("to", cal.getTime(), TemporalType.TIMESTAMP);
}
Object rawOrders = query.getSingleResult();
return rawOrders instanceof Number ? ((Number) rawOrders).intValue() : 0;
}
use of org.olat.resource.accesscontrol.OrderStatus in project OpenOLAT by OpenOLAT.
the class ACOrderDAO method findOrdersByDelivery.
public List<Order> findOrdersByDelivery(Identity delivery, OrderStatus... status) {
StringBuilder sb = new StringBuilder();
sb.append("select order from ").append(OrderImpl.class.getName()).append(" order").append(" where order.delivery.key=:deliveryKey");
if (status != null && status.length > 0) {
sb.append(" and order.orderStatusStr in (:status)");
}
TypedQuery<Order> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Order.class).setParameter("deliveryKey", delivery.getKey());
if (status != null && status.length > 0) {
List<String> statusStr = new ArrayList<String>();
for (OrderStatus s : status) {
statusStr.add(s.name());
}
query.setParameter("status", statusStr);
}
List<Order> orders = query.getResultList();
return orders;
}
use of org.olat.resource.accesscontrol.OrderStatus in project openolat by klemens.
the class ACFrontendManager method findOrderItems.
@Override
public List<OrderTableItem> findOrderItems(OLATResource resource, IdentityRef delivery, Long orderNr, Date from, Date to, OrderStatus[] status, int firstResult, int maxResults, List<UserPropertyHandler> userPropertyHandlers, SortKey... orderBy) {
List<AccessMethod> methods = methodManager.getAllMethods();
Map<String, AccessMethod> methodMap = new HashMap<>();
for (AccessMethod method : methods) {
methodMap.put(method.getKey().toString(), method);
}
List<RawOrderItem> rawOrders = orderManager.findNativeOrderItems(resource, delivery, orderNr, from, to, status, firstResult, maxResults, userPropertyHandlers, orderBy);
List<OrderTableItem> items = new ArrayList<>(rawOrders.size());
for (RawOrderItem rawOrder : rawOrders) {
String orderStatusStr = rawOrder.getOrderStatus();
OrderStatus orderStatus = OrderStatus.valueOf(orderStatusStr);
Status finalStatus = getStatus(orderStatusStr, rawOrder.getTrxStatus(), rawOrder.getPspTrxStatus());
String methodIds = rawOrder.getTrxMethodIds();
List<AccessMethod> orderMethods = new ArrayList<>(2);
if (StringHelper.containsNonWhitespace(methodIds)) {
String[] methodIdArr = methodIds.split(",");
for (String methodId : methodIdArr) {
if (methodMap.containsKey(methodId)) {
orderMethods.add(methodMap.get(methodId));
}
}
}
OrderTableItem item = new OrderTableItem(rawOrder.getOrderKey(), rawOrder.getOrderNr(), rawOrder.getTotal(), rawOrder.getCreationDate(), orderStatus, finalStatus, rawOrder.getDeliveryKey(), rawOrder.getUsername(), rawOrder.getUserProperties(), orderMethods);
item.setResourceDisplayname(rawOrder.getResourceName());
items.add(item);
}
return items;
}
Aggregations