Search in sources :

Example 1 with Client

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

the class AddSampleProductsOnStartup method addSampleProductsToRepo.

@PostConstruct
public void addSampleProductsToRepo() {
    TransactionStatus tx = transactionManager.getTransaction(new DefaultTransactionDefinition());
    for (int i = 1; i < 21; i++) {
        em.persist(product(String.format("Electronic Gizmo %02d", i), 0.99));
        em.persist(product(String.format("Cell Phone with 32GB flash memory %02d", i), 299.99));
        em.persist(food(String.format("Software Engineering Audiobook %02d", i), 17.50));
        em.persist(drug(String.format("PC Game including Zombies Part %02d", i), 39.89));
        em.persist(product(String.format("Tablet with Keyboard %02d", i), 459.99));
    }
    em.persist(new Client());
    transactionManager.commit(tx);
}
Also used : DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) TransactionStatus(org.springframework.transaction.TransactionStatus) Client(pl.com.bottega.erp.sales.domain.Client) PostConstruct(javax.annotation.PostConstruct)

Example 2 with Client

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

Example 3 with Client

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

Aggregations

Client (pl.com.bottega.erp.sales.domain.Client)3 Order (pl.com.bottega.erp.sales.domain.Order)2 Map (java.util.Map)1 PostConstruct (javax.annotation.PostConstruct)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)1 ProductAddedToOrderEvent (pl.com.bottega.erp.sales.application.events.ProductAddedToOrderEvent)1