use of pl.com.bottega.erp.sales.domain.Order in project ddd-cqrs-sample by BottegaIT.
the class PurchaseApplicationService method addProductToOrder.
/**
* Sample call of the domain logic<br>
* Sample publishing Application (not Domain) Event
*
* @param productId
* @param orderId
* @param quantity
*/
public void addProductToOrder(Long productId, Long orderId, int quantity) {
Order order = orderRepository.load(orderId);
Product product = productRepository.load(productId);
// Domain logic
order.addProduct(product, quantity);
orderRepository.save(order);
// if we want to Spy Clients:)
eventPublisher.publish(new ProductAddedToOrderEvent(product.getEntityId(), systemUser.getUserId(), quantity));
}
use of pl.com.bottega.erp.sales.domain.Order in project ddd-cqrs-sample by BottegaIT.
the class CreateOrderCommandHandler method handle.
@Override
public Long handle(CreateOrderCommand command) {
Client currentClient = clientRepository.load(systemUser.getUserId());
Order order = orderFactory.crateOrder(currentClient);
for (Map.Entry<Long, Integer> productIdWithCount : command.getProductIdsWithCounts().entrySet()) {
Long productId = productIdWithCount.getKey();
Integer count = productIdWithCount.getValue();
order.addProduct(productRepository.load(productId), count);
applicationEventPublisher.publish(new ProductAddedToOrderEvent(productId, systemUser.getUserId(), 1));
}
orderRepository.persist(order);
return order.getEntityId();
}
use of pl.com.bottega.erp.sales.domain.Order in project ddd-cqrs-sample by BottegaIT.
the class JpaOrderRepository method load.
@Override
public Order load(Long orderId) {
Order order = super.load(orderId);
injector.injectDependencies(order);
order.setRebatePolicy(rebatePolicyFactory.createRebatePolicy());
return order;
}
Aggregations