Example #1
0
 /**
  * @param config
  * @throws ServletException
  */
 @Override
 public void init(ServletConfig config) throws ServletException {
   super.init(config);
   studentBookDAO = StudentBookDAO.getInstance();
   studentDAO = StudentDAO.getInstance();
   bookDAO = BookDAO.getInstance();
 }
Example #2
0
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    HttpSession session = request.getSession(true);

    String bookisbn = StringUtils.trimToEmpty(request.getParameter("bookisbn"));
    String bookuuid = StringUtils.trimToEmpty(request.getParameter("bookuuid"));
    String studentAdmNo = StringUtils.trimToEmpty(request.getParameter("admissionNo"));
    String schooluuid = StringUtils.trimToEmpty(request.getParameter("schooluuid"));
    // System.out.println("bookuuid="+bookuuid);

    if (StringUtils.isBlank(bookisbn)) {
      session.setAttribute(SessionConstants.BOOK_BORROW_ERROR, ERROR_BOOK_NOT_FOUND);
    }
    if (StringUtils.isBlank(bookuuid)) {
      session.setAttribute(SessionConstants.BOOK_BORROW_ERROR, ERROR_SOMETHING_WENT_WRONG);

    } else if (StringUtils.isBlank(studentAdmNo)) {
      session.setAttribute(SessionConstants.BOOK_BORROW_ERROR, ERROR_STUDENT_ADMNO_NOT_FOUND);

    } else if (StringUtils.isBlank(schooluuid)) {
      session.setAttribute(SessionConstants.BOOK_BORROW_ERROR, ERROR_SOMETHING_WENT_WRONG);

    } else if (bookDAO.getBookByBorrowStatus(bookisbn, BORROW_STATUS_BORROWED) != null) {
      session.setAttribute(SessionConstants.BOOK_BORROW_ERROR, BOOK_NOT_AVALILABLE);

    } else if (bookDAO.getBookByBookStatus(bookisbn, BOOK_STATUS_REFERENCE) != null) {
      session.setAttribute(SessionConstants.BOOK_BORROW_ERROR, BOOK__REFERENCE);

    } else if (studentBookDAO.getStudentBook(bookuuid, BORROW_STATUS_BORROWED) != null) {
      session.setAttribute(SessionConstants.BOOK_BORROW_ERROR, BOOK_NOT_AVALILABLE);

    } else {
      Book book;
      Student student;
      StudentBook studentBook;
      student = studentDAO.getStudentObjByadmNo(schooluuid, studentAdmNo);
      if (student != null) {
        if (StringUtils.equals(student.getStatusUuid(), statusUuid)) {
          studentBook = new StudentBook();
          studentBook.setStudentUuid(student.getUuid());
          studentBook.setBookUuid(bookuuid);
          studentBook.setBorrowStatus(BORROW_STATUS_BORROWED);

          book = bookDAO.getBookByUUID(schooluuid, bookuuid);
          book.setBorrowStatus(BORROW_STATUS_BORROWED);
          bookDAO.updateBook(book);

          if (studentBookDAO.BorrowBook(studentBook)) {
            session.setAttribute(SessionConstants.BOOK_BORROW_SUCCESS, SUCCESS_BOOK_BORROWED);
          } else {
            session.setAttribute(SessionConstants.BOOK_BORROW_ERROR, ERROR_SOMETHING_WENT_WRONG);
          }
        } else {
          session.setAttribute(SessionConstants.BOOK_BORROW_ERROR, ERROR_STUDENT_INACTIVE);
        }
      } else {
        session.setAttribute(SessionConstants.BOOK_BORROW_ERROR, ERROR_STUDENT_ADMNO_NOT_FOUND);
      }
    }

    response.sendRedirect("lib.jsp");
    return;
  }