コード例 #1
0
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    Customer customer = (Customer) request.getAttribute("customer");

    List<InterestPlan> interestPlans = genericCrudService.readAll(InterestPlan.class);

    request.setAttribute("customer", customer);
    request.setAttribute("[FLASH]customer", customer);
    request.setAttribute("interestPlans", interestPlans);
    request.getRequestDispatcher("/admin/addAccount.jsp").forward(request, response);
  }
コード例 #2
0
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    Customer customer = (Customer) request.getAttribute("customer");

    if (customer == null) {
      request.setAttribute(
          "generalError",
          "An error occured. Please try again. If the problem persists, contact the support");
      doGet(request, response);
      return;
    }

    Account account = new Account();

    int interestPlanId = Integer.parseInt(request.getParameter("plan"));
    InterestPlan plan = genericCrudService.read(InterestPlan.class, interestPlanId);

    account.setName(request.getParameter("name"));

    if (!ValidationUtil.validate(account, "name", request)) {
      request.setAttribute("customer", customer);
      request.setAttribute("account", account);
      doGet(request, response);
      return;
    }

    account.setInterestPlan(plan);
    account.setAccountOwner(customer);
    account.setAmount(BigDecimal.ZERO);

    String outputServlet;

    if (genericCrudService.read(Customer.class, customer.getId()) == null) {
      Random rand = new Random(System.currentTimeMillis());
      String password = Long.toString(rand.nextInt() + rand.nextInt());

      try {
        customer.setPassword(passwordService.createHash(password));
      } catch (Exception e) {
        e.printStackTrace();
      }

      genericCrudService.create(customer);
      mailService.sendConfirmationMail(customer, password);
      outputServlet = "/admin/customers";
    } else {
      outputServlet = "/admin/accounts?id=" + customer.getId();
    }

    accountService.create(account);

    if (customer.getAccounts() == null) {
      customer.setAccounts(new ArrayList<Account>());
    }

    customer.getAccounts().add(account);

    genericCrudService.update(customer);

    response.sendRedirect(getServletContext().getContextPath() + outputServlet);
  }