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);
}
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);
}
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();
}
Aggregations