Package pl.com.bottega.ecommerce.sales.domain.reservation

Examples of pl.com.bottega.ecommerce.sales.domain.reservation.Reservation


  @Inject
  private SuggestionService suggestionService;

  // @Secured requires BUYER role
  public AggregateId createOrder() {
    Reservation reservation = reservationFactory.create(loadClient());
    reservationRepository.save(reservation);
    return reservation.getAggregateId();
  }
View Full Code Here


   * Reservation add product by given quantity
   */
  @Override
  public void addProduct(AggregateId orderId, AggregateId productId,
      int quantity) {
    Reservation reservation = reservationRepository.load(orderId);
   
    Product product = productRepository.load(productId);
   
    if (! product.isAvailabe()){
      Client client = loadClient()
      product = suggestionService.suggestEquivalent(product, client);
    }
     
    reservation.add(product, quantity);
   
    reservationRepository.save(reservation);
  }
View Full Code Here

  /**
   * Can be invoked many times for the same order (with different params).<br>
   * Offer VO is not stored in the Repo, it is stored on the Client Tier instead.
   */
  public Offer calculateOffer(AggregateId orderId) {
    Reservation reservation = reservationRepository.load(orderId);

    DiscountPolicy discountPolicy = discountFactory.create(loadClient());
   
    /*
     * Sample pattern: Aggregate generates Value Object using function<br>
     * Higher order function is closured by policy
     */
    return reservation.calculateOffer(discountPolicy);
  }
View Full Code Here

   */
  @Override
  @Transactional(isolation = Isolation.SERIALIZABLE)//highest isolation needed because of manipulating many Aggregates
  public void confirm(AggregateId orderId, OrderDetailsCommand orderDetailsCommand, Offer seenOffer)
      throws OfferChangedExcpetion {
    Reservation reservation = reservationRepository.load(orderId);
    if (reservation.isClosed())
      throw new DomainOperationException(reservation.getAggregateId(), "reservation is already closed");
   
    /*
     * Sample pattern: Aggregate generates Value Object using function<br>
     * Higher order function is closured by policy
     */
    Offer newOffer = reservation.calculateOffer(
                  discountFactory.create(loadClient()));
   
    /*
     * Sample pattern: Client Tier sends back old VOs, Server generates new VOs based on Aggregate state<br>
     * Notice that this VO is not stored in Repo, it's stored on the Client Tier.
     */
    if (! newOffer.sameAs(seenOffer, 5))//TODO load delta from conf.
      throw new OfferChangedExcpetion(reservation.getAggregateId(), seenOffer, newOffer);
   
    Client client = loadClient();//create per logged client, not reservation owner         
    Purchase purchase = purchaseFactory.create(reservation.getAggregateId(), client, seenOffer);
       
    if (! client.canAfford(purchase.getTotalCost()))
      throw new DomainOperationException(client.getAggregateId(), "client has insufficent money");
   
    purchaseRepository.save(purchase);//Aggregate must be managed by persistence context before firing events (synchronous listeners may need to load it)
   
    /*
     * Sample model where one aggregate creates another. Client does not manage payment lifecycle, therefore application must manage it.
     */
    Payment payment = client.charge(purchase.getTotalCost());
    paymentRepository.save(payment);
   
    purchase.confirm()
    reservation.close();       
   
    reservationRepository.save(reservation);
    clientRepository.save(client);
   
  }
View Full Code Here

  @Inject
  private SystemContext systemContext;
 
  @Override
  public Void handle(AddProdctCommand command) {
    Reservation reservation = reservationRepository.load(command.getOrderId());
   
    Product product = productRepository.load(command.getProductId());
   
    if (! product.isAvailabe()){
      Client client = loadClient()
      product = suggestionService.suggestEquivalent(product, client);
    }
     
    reservation.add(product, command.getQuantity());
   
    reservationRepository.save(reservation);
   
    return null;
  }
View Full Code Here

  @PersistenceContext
  private EntityManager entityManager;

  @Override
  public OrderDto find(AggregateId orderId) {
    Reservation reservation = entityManager.find(Reservation.class, orderId);
    Purchase purchase = entityManager.find(Purchase.class, orderId);
   
    return toOrderDto(reservation, purchase);
  }
View Full Code Here

TOP

Related Classes of pl.com.bottega.ecommerce.sales.domain.reservation.Reservation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.