private void createSoleDistributor(
      HttpServletRequest request, HttpServletResponse response, PrintWriter out) throws Exception {
    HttpSession session = request.getSession();
    ArrayList<OperatingRegion> soleDisList = new ArrayList<OperatingRegion>();
    // int listIndex = Integer.parseInt(request.getParameter("listIndex"));
    soleDisList = (ArrayList) session.getAttribute("soleDistributionList");
    String custId =
        (request.getParameter("inquirer_id") != null) ? request.getParameter("inquirer_id") : "";
    if (custId.equals("")) {
      String json =
          gson.toJson(
              new JsonReturnMsg(
                  "Create Sole Distributor", "Please Chose A Whole Saler First. ", "error"));
      out.println(json);
    } else {
      Customer c = customerFacade.find(Long.parseLong(custId));
      String exist = "";
      for (OperatingRegion sd : soleDisList) {

        exist = soleDistributionFacade.checkSoleDistributionExist(sd.getRegion());
        if (!exist.equals("")) {
          String json =
              gson.toJson(
                  new JsonReturnMsg(
                      "Create Sole Distribution",
                      "<span style='color: red'>"
                          + exist
                          + "'s</span> Sole Distributionship Already Taken.",
                      "error"));
          out.println(json);
          break;
        }
      }

      if (exist.equals("")) {
        for (OperatingRegion sd : soleDisList) {
          soleDistributionFacade.addSoleDistribution(sd.getRegion(), c.getInquirer_id());
          //                    //check
          //                    soleDistributionFacade.create(sd);
          //                    sd.setCustomer(c);
          //                    soleDistributionFacade.edit(sd);
          //
          //                    c.getSoleDistribution().add(sd);
          //                    customerFacade.edit(c);
        }
        String json =
            gson.toJson(
                new JsonReturnMsg("Create Sole Distributor", "Sole Distributor Created.", "info"));
        out.println(json);
      }
    }
  }
  private String checkChildRegionExist(HttpServletRequest request, String region) {
    HttpSession session = request.getSession();
    ArrayList<OperatingRegion> soleDisList = new ArrayList<OperatingRegion>();
    soleDisList = (ArrayList) session.getAttribute("soleDistributionList");
    String ret = "";

    for (OperatingRegion sd : soleDisList) {
      if (region.endsWith(sd.getRegion())) {
        ret = sd.getRegion();
        break;
      }
      if (sd.getRegion().endsWith(region)) {
        ret = region;
        break;
      }
    }

    return ret;
  }
  private void addDistribution(
      HttpServletRequest request, HttpServletResponse response, PrintWriter out) throws Exception {
    HttpSession session = request.getSession();
    ArrayList<OperatingRegion> soleDisList = new ArrayList<OperatingRegion>();
    String region = request.getParameter("region");
    String json;
    if (region == null || region.isEmpty()) {
      json =
          gson.toJson(
              new JsonReturnMsg(
                  "Create Sole Distribution",
                  "Please enter a valid City, State(Province) or Country.",
                  "error"));
      out.println(json);
    } else {
      soleDisList = (ArrayList) session.getAttribute("soleDistributionList");

      boolean sdExist = false;
      for (OperatingRegion sd : soleDisList) {
        if (sd.getRegion().equals(region)) {
          sdExist = true;
          json =
              gson.toJson(
                  new JsonReturnMsg("Create Sole Distribution", "Region Already Added.", "error"));
          out.println(json);
          break;
        }
      }

      if (!sdExist) {
        String custId =
            (request.getParameter("inquirer_id") != null)
                ? request.getParameter("inquirer_id")
                : "";
        if (custId.equals("")) {
          json =
              gson.toJson(
                  new JsonReturnMsg(
                      "Create Sole Distributor", "Please Chose A Whole Saler First. ", "error"));
          out.println(json);
        } else {

          String existInList = checkDistribution(request, region);

          if (!existInList.equals("")) {
            json =
                gson.toJson(
                    new JsonReturnMsg(
                        "Create Sole Distribution",
                        "<span style='color: red'>"
                            + existInList
                            + "</span> Already Exist In Your List.",
                        "error"));
            out.println(json);
          } else {

            String exist = soleDistributionFacade.checkSoleDistributionExist(region);
            if (exist.equals("")) {
              OperatingRegion sd = new OperatingRegion();
              sd.setRegion(region);
              soleDisList.add(sd);
              session.setAttribute("soleDistributionList", soleDisList);
              json = gson.toJson(new JsonReturnMsg("Info", "Sole Distributionship Added.", "info"));
              out.println(json);
            } else {
              json =
                  gson.toJson(
                      new JsonReturnMsg(
                          "Create Sole Distribution",
                          "<span style='color: red'>"
                              + exist
                              + "'s</span> Sole Distributionship Already Taken.",
                          "error"));
              out.println(json);
            }
          }
        }
      }
    }
  }