private void updatePlan(PlanDTO plan, String action, String sessionId)
      throws PluggableTaskException {
    ItemDTO item = plan.getItem();
    int itemId = item.getId();
    String itemDescription = item.getDescription(item.getEntity().getLanguageId());

    String xml =
        "<updateplans>"
            + "  <plan action='"
            + action
            + "'>"
            + "    <code>"
            + itemId
            + "</code>"
            + "    <description>"
            + itemDescription
            + "</description>"
            + "  </plan>"
            + "</updateplans>";

    String json =
        "{" + "  \"session\": \"" + sessionId + "\", " + "  \"xmldata\": \"" + xml + "\" " + "}";

    Map<String, Object> result = makeCall(json, "updatePlan");

    String error = null;
    if (result.get("status") != null) {
      if (!result.get("status").toString().equals("OK")) {
        error = result.get("error").toString();
      }
    } else {
      error = result.get("description").toString();
    }

    if (error != null) {
      error = "Error calling SugarCRM: " + error;
      LOG.error(error);
      throw new PluggableTaskException(error);
    }
  }
示例#2
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!");
    }
  }