Package servlet

Class AccountServlet

java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
servlet.AccountServlet
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

@WebServlet("/account") public class AccountServlet extends javax.servlet.http.HttpServlet
Servlet that handles all account related operations. Manages account creation, transactions, joint accounts, and transaction history. Supports multiple storage types.
Author:
TAMIL MUGHILAN
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Handles GET requests for account retrieval operations.
    protected void
    doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Handles POST requests for account modification operations.
    private Integer
    getCurrentUserId(javax.servlet.http.HttpServletRequest request)
    Gets the current user's ID from session.
    getCurrentUserType(javax.servlet.http.HttpServletRequest request)
    Gets the current user's type from session.
    private DataStorage
    getDataStorage(String storageType)
    Gets the correct data storage implementation based on storage type.
    private void
    sendAccountsJsonResponse(javax.servlet.http.HttpServletResponse response, boolean success, String message, List<SavingsAccount> accounts)
    Sends JSON response for account data.
    private void
    sendJsonResponse(javax.servlet.http.HttpServletResponse response, boolean success, String message, Object data)
    Sends JSON response for AJAX requests.

    Methods inherited from class javax.servlet.http.HttpServlet

    doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service

    Methods inherited from class javax.servlet.GenericServlet

    destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AccountServlet

      public AccountServlet()
  • Method Details

    • getDataStorage

      private DataStorage getDataStorage(String storageType) throws SQLException
      Gets the correct data storage implementation based on storage type.
      Parameters:
      storageType - the type of storage (database, collections, mongoDB)
      Returns:
      the data storage implementation
      Throws:
      SQLException - if database connection fails
    • getCurrentUserId

      private Integer getCurrentUserId(javax.servlet.http.HttpServletRequest request)
      Gets the current user's ID from session.
      Parameters:
      request - the HTTP request
      Returns:
      the user ID or null if not found
    • getCurrentUserType

      private TransactionLog.UserType getCurrentUserType(javax.servlet.http.HttpServletRequest request)
      Gets the current user's type from session.
      Parameters:
      request - the HTTP request
      Returns:
      the user type (CUSTOMER, EMPLOYEE, MANAGER) or null
    • sendJsonResponse

      private void sendJsonResponse(javax.servlet.http.HttpServletResponse response, boolean success, String message, Object data) throws IOException
      Sends JSON response for AJAX requests.
      Parameters:
      response - the HTTP response
      success - whether the operation was successful
      message - the response message
      data - the response data
      Throws:
      IOException - if writing response fails
    • sendAccountsJsonResponse

      private void sendAccountsJsonResponse(javax.servlet.http.HttpServletResponse response, boolean success, String message, List<SavingsAccount> accounts) throws IOException
      Sends JSON response for account data.
      Parameters:
      response - the HTTP response
      success - whether the operation was successful
      message - the response message
      accounts - list of accounts to include in response
      Throws:
      IOException - if writing response fails
    • doGet

      protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException
      Handles GET requests for account retrieval operations. Performs Dependency Injection by passing the user's choice of data storage into the Services. Viewing accounts by ID, branch, customer, and transaction history.
      Overrides:
      doGet in class javax.servlet.http.HttpServlet
      Parameters:
      request - the HTTP servlet request
      response - the HTTP servlet response
      Throws:
      javax.servlet.ServletException - if a servlet error occurs
      IOException - if an I/O error occurs
    • doPost

      protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException
      Handles POST requests for account modification operations. Performs Dependency Injection by passing the user's choice of data storage into the Services. Account creation, deposits, withdrawals, and joint account management.
      Overrides:
      doPost in class javax.servlet.http.HttpServlet
      Parameters:
      request - the HTTP servlet request
      response - the HTTP servlet response
      Throws:
      javax.servlet.ServletException - if a servlet error occurs
      IOException - if an I/O error occurs