예제 #1
0
파일: Delete.java 프로젝트: malik491/ResApp
  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    AccountBean loggedinAccount = getLoggedinAccount(request);
    if (loggedinAccount == null) {
      // not logged in. go to login page
      getServletContext().getRequestDispatcher(LOGIN_JSP_URL).forward(request, response);
      return;
    }

    String jspMsg = null;

    if (loggedinAccount.getRole() == AccountRole.MANAGER
        || loggedinAccount.getRole() == AccountRole.ADMIN) {
      String username = (String) request.getParameter(ParamLabels.Credentials.USERNAME);
      boolean isValid = new CredentialsValidator().isValidUsername(username);
      if (isValid) {
        AccountServiceClient serviceClient =
            new AccountServiceClient(loggedinAccount.getCredentials(), ACCOUT_WEB_SERVICE_URL);
        Boolean deleted = serviceClient.delete(username);
        jspMsg =
            (deleted == null) ? serviceClient.getResponseMessage() : "Successfully deleted account";
      }
    }

    if (jspMsg != null) request.setAttribute(ParamLabels.JspMsg.MSG, jspMsg);

    String jspUrl = "/account/delete.jsp";
    getServletContext().getRequestDispatcher(jspUrl).forward(request, response);
  }
예제 #2
0
파일: View.java 프로젝트: malik491/ResApp
  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    AccountBean loggedinAccount = getLoggedinAccount(request);
    if (loggedinAccount == null) {
      // not logged in. go to login page
      getServletContext().getRequestDispatcher(LOGIN_JSP_URL).forward(request, response);
      return;
    }

    String jspMsg = null;
    OrderBean order = null;

    if (loggedinAccount.getRole() == AccountRole.MANAGER) {
      long orderId = getIdFromRequest(request, ParamLabels.Order.ID, 0);
      boolean isValid = new OrderValidator().validateId(orderId, false);

      if (isValid) {
        OrderServiceClient serviceClient =
            new OrderServiceClient(loggedinAccount.getCredentials(), ORDER_WEB_SERVICE_URL);
        order = serviceClient.get(orderId);
        jspMsg = (order == null) ? serviceClient.getResponseMessage() : null;
      } else {
        jspMsg = "Invalid Order Id";
      }
    }

    if (jspMsg != null) request.setAttribute(ParamLabels.JspMsg.MSG, jspMsg);
    if (order != null) request.setAttribute(ParamLabels.Order.ORDER_BEAN, order);

    String jspUrl = "/order/view.jsp";
    getServletContext().getRequestDispatcher(jspUrl).forward(request, response);
  }