Exemplo n.º 1
0
 public Collection<Coupon> getAllPurchasedCouponsByType(CouponType type)
     throws CouponSystemException {
   Collection<Coupon> result = new ArrayList<>();
   for (Long couponId : custcouponDBDAO.getAllCouponsByCustomer(customer.getId())) {
     if (coupDBDAO.get(couponId).getType().equals(type)) {
       result.add(coupDBDAO.get(couponId));
     }
   }
   return result;
 }
Exemplo n.º 2
0
 public Collection<Coupon> getAllPurchasedCouponsByPrice(Double price)
     throws CouponSystemException {
   Collection<Coupon> result = new ArrayList<>();
   for (Long couponId : custcouponDBDAO.getAllCouponsByCustomer(customer.getId())) {
     if (coupDBDAO.get(couponId).getPrice() < price) {
       result.add(coupDBDAO.get(couponId));
     }
   }
   return result;
 }
Exemplo n.º 3
0
  public void purchaseCoupon(Coupon c) throws CouponSystemException {

    if (!(custcouponDBDAO.HasCouponBeenPurchased(c, customer))) {
      Coupon temp_coupon = coupDBDAO.get(c.getId());
      if (temp_coupon.getAmount() == 0) {
        throw new CouponSystemException("cannot purchase coupon - no more left");
      } else { // to do - check that coupon is not expired
        custcouponDBDAO.createCoupon(customer.getId(), c.getId());
        temp_coupon.setAmount(c.getAmount() - 1);
        coupDBDAO.update(temp_coupon);
      }
    }
  }