Search in sources :

Example 1 with OrderOperationException

use of pl.com.bottega.erp.sales.domain.errors.OrderOperationException in project ddd-cqrs-sample by BottegaIT.

the class SubmitOrderCommandHandler method handle.

@Override
public Void handle(SubmitOrderCommand command) {
    Order order = orderRepository.load(command.getOrderId());
    Specification<Order> orderSpecification = generateSpecification(systemUser);
    if (!orderSpecification.isSatisfiedBy(order))
        throw new OrderOperationException("Order does not meet specification", order.getEntityId());
    //Domain logic
    order.submit();
    //Domain service
    Invoice invoice = invoicingService.issuance(order, generateTaxPolicy(systemUser));
    orderRepository.save(order);
    invoiceRepository.save(invoice);
    return null;
}
Also used : Order(pl.com.bottega.erp.sales.domain.Order) Invoice(pl.com.bottega.erp.sales.domain.Invoice) OrderOperationException(pl.com.bottega.erp.sales.domain.errors.OrderOperationException)

Example 2 with OrderOperationException

use of pl.com.bottega.erp.sales.domain.errors.OrderOperationException in project ddd-cqrs-sample by BottegaIT.

the class PurchaseApplicationService method approveOrder.

/**
     * Sample of the separation of domain logic in aggregate and domain logic in
     * domain service
     * 
     * @param orderId
     */
public void approveOrder(Long orderId) {
    Order order = orderRepository.load(orderId);
    Specification<Order> orderSpecification = generateSpecification(systemUser);
    if (!orderSpecification.isSatisfiedBy(order))
        throw new OrderOperationException("Order does not meet specification", order.getEntityId());
    // Domain logic
    order.submit();
    // Domain service
    Invoice invoice = invoicingService.issuance(order, generateTaxPolicy(systemUser));
    invoiceRepository.save(invoice);
    orderRepository.save(order);
}
Also used : Order(pl.com.bottega.erp.sales.domain.Order) Invoice(pl.com.bottega.erp.sales.domain.Invoice) OrderOperationException(pl.com.bottega.erp.sales.domain.errors.OrderOperationException)

Aggregations

Invoice (pl.com.bottega.erp.sales.domain.Invoice)2 Order (pl.com.bottega.erp.sales.domain.Order)2 OrderOperationException (pl.com.bottega.erp.sales.domain.errors.OrderOperationException)2