Examples of DomainOperationException


Examples of pl.com.bottega.ecommerce.sharedkernel.exceptions.DomainOperationException

  @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.
View Full Code Here

Examples of pl.com.bottega.ecommerce.sharedkernel.exceptions.DomainOperationException

  }

  void changeQuantityBy(int change) {
    int changed = quantity + change;
    if (changed <= 0)
      throw new DomainOperationException(null, "change below 1");
    this.quantity = changed;
  }
View Full Code Here

Examples of pl.com.bottega.ecommerce.sharedkernel.exceptions.DomainOperationException

  @Inject
  private AutowireCapableBeanFactory spring;
 
  public Reservation create(Client client){
    if (! canReserve(client))
      throw new DomainOperationException(client.getAggregateId(), "Client can not create reservations");
   
    Reservation reservation = new Reservation(AggregateId.generate(), ReservationStatus.OPENED, client.generateSnapshot(), new Date());
    spring.autowireBean(reservation);
   
    addGratis(reservation, client);
View Full Code Here

Examples of pl.com.bottega.ecommerce.sharedkernel.exceptions.DomainOperationException

  public boolean isRemoved() {
    return aggregateStatus == AggregateStatus.ARCHIVE;
  }
 
  protected void domainError(String message) {
    throw new DomainOperationException(aggregateId, message);
  }
View Full Code Here

Examples of pl.com.bottega.ecommerce.sharedkernel.exceptions.DomainOperationException

  public InvoiceRequest create(Client client, Purchase... purchases) {
    InvoiceRequest request = new InvoiceRequest(client.generateSnapshot());
   
    for (Purchase purchase : purchases) {
      if (! purchase.isPaid())
        throw new DomainOperationException(purchase.getAggregateId(), "Purchase is not paid");
     
      for (PurchaseItem item : purchase.getItems()) {
        request.add(new RequestItem(item.getProductData(), item.getQuantity(), item.getTotalCost()));
      }
    }
View Full Code Here

Examples of pl.com.bottega.ecommerce.sharedkernel.exceptions.DomainOperationException

   * @param offer
   * @return
   */
  public Purchase create(AggregateId orderId, Client client, Offer offer){
    if (! canPurchse(client, offer.getAvailabeItems()))
      throw new DomainOperationException(client.getAggregateId(), "client can not purchase");
   
    ArrayList<PurchaseItem> items = new ArrayList<PurchaseItem>(offer.getAvailabeItems().size());
    Money purchaseTotlCost = Money.ZERO;
   
    for (OfferItem item : offer.getAvailabeItems()) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.