use of com.company.sales.entity.OrderLine in project documentation by cuba-platform.
the class OrderLineChangedListener method beforeCommit.
@EventListener
public void beforeCommit(EntityChangedEvent<OrderLine, UUID> event) {
Order order;
if (event.getType() != EntityChangedEvent.Type.DELETED) {
// <1>
order = // <2>
txDm.load(event.getEntityId()).view(// <3>
"orderLine-with-order").one().getOrder();
} else {
// <5>
Id<Order, UUID> orderId = event.getChanges().getOldReferenceId("order");
order = txDm.load(orderId).one();
}
long count = // <6>
txDm.load(OrderLine.class).query("select o from sales_OrderLine o where o.order = :order").parameter("order", order).view("orderLine-with-product").list().stream().filter(orderLine -> Boolean.TRUE.equals(orderLine.getProduct().getSpecial())).count();
order.setNumberOfSpecialProducts((int) count);
// <7>
txDm.save(order);
}
Aggregations