Search in sources :

Example 6 with Order

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));
}
Also used : Order(pl.com.bottega.erp.sales.domain.Order) Product(pl.com.bottega.erp.sales.domain.Product) ProductAddedToOrderEvent(pl.com.bottega.erp.sales.application.events.ProductAddedToOrderEvent)

Example 7 with Order

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();
}
Also used : Order(pl.com.bottega.erp.sales.domain.Order) ProductAddedToOrderEvent(pl.com.bottega.erp.sales.application.events.ProductAddedToOrderEvent) Client(pl.com.bottega.erp.sales.domain.Client) Map(java.util.Map)

Example 8 with Order

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;
}
Also used : Order(pl.com.bottega.erp.sales.domain.Order)

Aggregations

Order (pl.com.bottega.erp.sales.domain.Order)8 ProductAddedToOrderEvent (pl.com.bottega.erp.sales.application.events.ProductAddedToOrderEvent)2 Client (pl.com.bottega.erp.sales.domain.Client)2 Invoice (pl.com.bottega.erp.sales.domain.Invoice)2 Product (pl.com.bottega.erp.sales.domain.Product)2 OrderOperationException (pl.com.bottega.erp.sales.domain.errors.OrderOperationException)2 Map (java.util.Map)1