コード例 #1
0
  public void delete() {
    if (plan != null) {
      purgeCustomerPrices();
      planDas.delete(plan);

      // trigger internal event
      EventManager.process(new PlanDeletedEvent(plan));
    } else {
      LOG.error("Cannot delete, PlanDTO not found or not set!");
    }
  }
コード例 #2
0
  public Integer create(PlanDTO plan) {
    if (plan != null) {
      validateAttributes(plan);

      this.plan = planDas.save(plan);

      // trigger internal event
      EventManager.process(new NewPlanEvent(plan));

      return this.plan.getId();
    }

    LOG.error("Cannot save a null PlanDTO!");
    return null;
  }
コード例 #3
0
  public void addPrice(PlanItemDTO planItem) {
    if (plan != null) {
      PriceModelBL.validateAttributes(planItem.getModels().values());

      plan.addPlanItem(planItem);

      LOG.debug("Saving updates to plan %s", plan.getId());
      this.plan = planDas.save(plan);

      refreshCustomerPrices();

      // trigger internal event
      EventManager.process(new PlanUpdatedEvent(plan));

    } else {
      LOG.error("Cannot add price, PlanDTO not found or not set!");
    }
  }
コード例 #4
0
  public void update(PlanDTO dto) {
    if (plan != null) {

      // un-subscribe existing customers before updating
      List<CustomerDTO> subscribers = getCustomersByPlan(plan.getId());
      for (CustomerDTO customer : subscribers) {
        unsubscribe(customer.getBaseUser().getUserId());
      }

      // clean all remaining prices just-in-case there's an orphaned record
      if (plan.getPlanItems().size() > 0) {
        purgeCustomerPrices();
      }

      // do update
      validateAttributes(dto);

      plan.setDescription(dto.getDescription());
      plan.setItem(dto.getItem());
      plan.setPeriod(dto.getPeriod());

      plan.getPlanItems().clear();
      plan.getPlanItems().addAll(dto.getPlanItems());

      LOG.debug("Saving updates to plan %s", plan.getId());
      this.plan = planDas.save(plan);

      // re-subscribe customers after plan has been saved
      for (CustomerDTO customer : subscribers) {
        subscribe(customer.getBaseUser().getUserId());
      }

      // trigger internal event
      EventManager.process(new PlanUpdatedEvent(plan));

    } else {
      LOG.error("Cannot update, PlanDTO not found or not set!");
    }
  }
コード例 #5
0
 public void set(Integer planId) {
   this.plan = planDas.find(planId);
 }
コード例 #6
0
 /**
  * Returns all plans that affect the pricing of the given item, or that include the item in a
  * bundle.
  *
  * @param itemId item id
  * @return list of plans, empty list if none found
  */
 public List<PlanDTO> getPlansByAffectedItem(Integer itemId) {
   return planDas.findByAffectedItem(itemId);
 }
コード例 #7
0
 /**
  * Returns all plans that use the given item as the "plan subscription" item.
  *
  * @param itemId item id
  * @return list of plans, empty list if none found
  */
 public List<PlanDTO> getPlansBySubscriptionItem(Integer itemId) {
   return planDas.findByPlanSubscriptionItem(itemId);
 }
コード例 #8
0
 /**
  * Returns a list of all customers that have subscribed to the given plan. A customer subscribes
  * to a plan by adding the plan subscription item to a recurring order.
  *
  * @param planId id of plan
  * @return list of customers subscribed to the plan, empty if none found
  */
 public List<CustomerDTO> getCustomersByPlan(Integer planId) {
   return planDas.findCustomersByPlan(planId);
 }
コード例 #9
0
 /**
  * Returns true if the customer is subscribed to this plan.
  *
  * @param userId user id of the customer to check
  * @return true if customer is subscribed, false if not
  */
 public boolean isSubscribed(Integer userId) {
   return planDas.isSubscribed(userId, plan.getId());
 }