Example #1
0
  public String perform(HttpServletRequest request) {
    List<String> errors = new ArrayList<String>();
    request.setAttribute("errors", errors);

    try {

      CommentForm form = formBeanFactory.create(request);
      request.setAttribute("form", form);

      // Any validation errors?
      errors.addAll(form.getValidationErrors());
      if (errors.size() != 0) {
        return "error.jsp";
      }
      ReviewBean review = new ReviewBean();
      review.setCommentDate(new Date());
      review.setReviewText(form.getContent());
      review.setReviewUid(form.getUidasInt());
      review.setRid(form.getRidasInt());
      UserBean user = userDAO.read(form.getUidasInt());
      review.setUserName(user.getUserName());
      reviewDAO.create(review);

      return "viewRecipe.do?recipeId=" + form.getRecipeId();
    } catch (FormBeanException e) {
      errors.add(e.getMessage());
      return "error.jsp";
    } catch (RollbackException e) {
      e.printStackTrace();
      return "error.jsp";
    }
  }
  @Override
  public String perform(HttpServletRequest request) {
    List<String> errors = new ArrayList<String>();
    request.setAttribute("errors", errors);
    HttpSession session = request.getSession();

    try {
      EmployeeDepositCheckForm form = formBeanFactory.create(request);
      request.setAttribute("form", form);

      VisitorBean[] customerlist = visitorDAO.getAllCustomers();
      request.setAttribute("customerlist", customerlist);

      if (!form.isPresent()) {
        return Constants.employeeDepositCheckJsp;
      }

      errors.addAll(form.getValidationErrors());
      if (errors.size() != 0) {
        return Constants.employeeDepositCheckJsp;
      }

      synchronized (this) {
        VisitorBean visitor = visitorDAO.read(form.getUserName());
        if (visitor == null) {
          errors.add("Customer does not exist");
          return Constants.employeeDepositCheckJsp;
        }
        transactionDAO.depositCheck(visitor.getVisitorId(), (int) form.getAmountAsDouble() * 100);
      }

      request.setAttribute("success", "success");
      return Constants.employeeDepositCheckJsp;

    } catch (FormBeanException e) {
      errors.add(e.getMessage());
      return Constants.employeeDepositCheckJsp;
    } catch (NumberFormatException e) {
      errors.add(e.getMessage());
      return Constants.employeeDepositCheckJsp;
    } catch (RollbackException e) {
      errors.add(e.getMessage());
      return Constants.employeeDepositCheckJsp;
    }
  }
Example #3
0
  public String perform(HttpServletRequest request) {
    HttpSession session = request.getSession();
    List<String> errors = new ArrayList<String>();
    // authority judge
    if ((EmployeeBean) session.getAttribute("employee") == null) {
      return "employeelogin.do";
    }

    request.setAttribute("errors", errors);
    EmployeeBean employee = (EmployeeBean) session.getAttribute("employee");
    if (employee == null) {
      return "employeelogin.do";
    }

    /*
     * Check the deposit form.
     */
    DepositCheckForm depositcheckform = new DepositCheckForm(request);
    request.setAttribute("depositcheckform", depositcheckform);
    if (!depositcheckform.isPresent()) {
      return "employee_deposit_check.jsp";
    }
    errors.addAll(depositcheckform.getValidationErrors());
    if (errors.size() != 0) {
      return "employee_deposit_check.jsp";
    }

    CustomerBean customer = (CustomerBean) session.getAttribute("modifyCustomer");
    int id = customer.getCustomerId();
    try {
      customer = customerDAO.read(id);
    } catch (RollbackException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }

    double amount = depositcheckform.getAmount();

    //////////////////////
    // Transaction START //
    //////////////////////
    try {
      Transaction.begin();
      TransactionBean transaction = new TransactionBean();
      // what kind of transaction
      transaction.setTransactionType(TransactionType.DEPOSIT.toString());
      // who request the deposit
      transaction.setCustomerId(customer.getCustomerId());
      // how much money(in long)
      transaction.writeAmount(amount);
      // Create transaction
      transactionDAO.create(transaction);

      // update balance&available immediately.
      customer.writeCashBalance(amount);
      customerDAO.update(customer);

      Transaction.commit();
    } catch (RollbackException e) {
      e.printStackTrace();
    }
    ////////////////////
    // Transaction END//
    ////////////////////

    session.setAttribute("modifyCustomer", customer);
    // session.setAttribute("customer", customer);

    session.setAttribute(
        "message", "Thank you! You have successfully sent your deposit check request!");
    return "success_employee.jsp";
  }
  @Override
  public String perform(HttpServletRequest request) {
    HttpSession session = request.getSession();
    List<String> errors = new ArrayList<String>();
    request.setAttribute("errors", errors);

    try {
      if (session.getAttribute("user") != null
          && session.getAttribute("user") instanceof CustomerBean) {
        CustomerBean user = (CustomerBean) request.getSession().getAttribute("user");

        int customer_Id = user.getCustomerId();

        List<TransactionShareBean> transactionShares = new ArrayList<TransactionShareBean>();
        TransactionBean[] transactions =
            transactionDAO.match(MatchArg.equals("customerId", customer_Id));
        for (TransactionBean t : transactions) {
          TransactionShareBean tShare = new TransactionShareBean();

          tShare.setTransactionId(t.getTransactionId());
          tShare.setCustomeId(t.getCustomerId());

          if (t.getFundId() == 0) {
            tShare.setFundId(-1);
            tShare.setShares(-1);
            tShare.setSharePrice(-1);
            if (t.getTransactionType().equals("2")) {
              tShare.setTransactionType("Request Check");
            } else {
              tShare.setTransactionType("Deposit Check");
            }
            if (t.getExecuteDate() != null) {
              tShare.setExecuteDate(t.getExecuteDate());
            } else {
              tShare.setExecuteDate("Pending");
            }
            tShare.setAmount(t.getAmount() / 100.0);
          } else {
            int fundId = t.getFundId();
            tShare.setFundId(fundId);
            String fundName = fundDAO.getFundName(fundId);
            tShare.setFundName(fundName);

            if (t.getTransactionType().equals("8")) {
              tShare.setTransactionType("Buy Fund");

              if (t.getExecuteDate() == null) {
                tShare.setExecuteDate("Pending");
                tShare.setShares(-1);
                tShare.setSharePrice(-1);
              } else {
                String executeDate = t.getExecuteDate();
                tShare.setExecuteDate(executeDate);
                tShare.setShares(t.getShares() / 1000.0);
                long sharePrice = fundPriceHistoryDAO.getSharePrice(fundId, executeDate);
                tShare.setSharePrice(sharePrice / 100.0);
              }
              tShare.setAmount(t.getAmount() / 100.0);
            } else {
              tShare.setTransactionType("Sell Fund");
              if (t.getExecuteDate() == null) {
                tShare.setExecuteDate("Pending");
                tShare.setAmount(-1);
                tShare.setSharePrice(-1);
              } else {
                String executeDate = t.getExecuteDate();
                tShare.setExecuteDate(executeDate);
                tShare.setAmount(t.getAmount() / 100.0);
                long sharePrice = fundPriceHistoryDAO.getSharePrice(fundId, executeDate);
                tShare.setSharePrice(sharePrice / 100.0);
              }
              tShare.setShares(t.getShares() / 1000.0);
            }
          }
          transactionShares.add(tShare);
        }

        if (transactionShares.size() == 0) {
          errors.add("No transaction history to be viewed");
          request.setAttribute("customer", user);
          return "transactionHistory_Customer.jsp";
        } else {
          request.setAttribute("customer", user);
          request.setAttribute("transactions", transactionShares);
          return "transactionHistory_Customer.jsp";
        }
      } else {
        return "login.do";
      }
    } catch (RollbackException e) {
      errors.add("System roll back!");
      e.printStackTrace();
      return "transactionHistory_Customer.jsp";
    } catch (Exception e2) {
      errors.add("Other errors!");
      e2.printStackTrace();
      return "transactionHistory_Customer.jsp";
    }
  }