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;
  }
  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!");
    }
  }
  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!");
    }
  }