Search in sources :

Example 1 with Order

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

the class OrderShipmentStatusTrackerSaga method completeIfPossible.

private void completeIfPossible() {
    if (data.getOrderId() != null && data.getShipmentId() != null && data.getShipmentReceived()) {
        Order shippedOrder = orderRepository.load(data.getOrderId());
        shippedOrder.archive();
        orderRepository.save(shippedOrder);
        markAsCompleted();
    }
}
Also used : Order(pl.com.bottega.erp.sales.domain.Order)

Example 2 with Order

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

the class AddProductToOrderCommandHandler method handle.

@Override
public Void handle(AddProductToOrderCommand command) {
    Product product = productRepository.load(command.getProductId());
    Order order = orderRepository.load(command.getOrderId());
    order.addProduct(product, command.getQuantity());
    orderRepository.save(order);
    return null;
}
Also used : Order(pl.com.bottega.erp.sales.domain.Order) Product(pl.com.bottega.erp.sales.domain.Product)

Example 3 with Order

use of pl.com.bottega.erp.sales.domain.Order 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 4 with Order

use of pl.com.bottega.erp.sales.domain.Order 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)

Example 5 with Order

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

the class PurchaseApplicationService method createNewOrder.

/**
     * Sample usage of factory and repository
     * 
     * @throws OrderCreationException
     */
public void createNewOrder() throws OrderCreationException {
    Client client = loadClient(systemUser.getUserId());
    Order order = orderFactory.crateOrder(client);
    orderRepository.persist(order);
}
Also used : Order(pl.com.bottega.erp.sales.domain.Order) Client(pl.com.bottega.erp.sales.domain.Client)

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