private void setupTestData() {
    IBook[] book = new IBook[15];
    IMember[] member = new IMember[6];

    book[0] = bookDao_.addBook("author1", "title1", "callNo1");
    book[1] = bookDao_.addBook("author1", "title2", "callNo2");
    book[2] = bookDao_.addBook("author1", "title3", "callNo3");
    book[3] = bookDao_.addBook("author1", "title4", "callNo4");
    book[4] = bookDao_.addBook("author2", "title5", "callNo5");
    book[5] = bookDao_.addBook("author2", "title6", "callNo6");
    book[6] = bookDao_.addBook("author2", "title7", "callNo7");
    book[7] = bookDao_.addBook("author2", "title8", "callNo8");
    book[8] = bookDao_.addBook("author3", "title9", "callNo9");
    book[9] = bookDao_.addBook("author3", "title10", "callNo10");
    book[10] = bookDao_.addBook("author4", "title11", "callNo11");
    book[11] = bookDao_.addBook("author4", "title12", "callNo12");
    book[12] = bookDao_.addBook("author5", "title13", "callNo13");
    book[13] = bookDao_.addBook("author5", "title14", "callNo14");
    book[14] = bookDao_.addBook("author5", "title15", "callNo15");

    member[0] = memberDao_.addMember("fName0", "lName0", "0001", "email0");
    member[1] = memberDao_.addMember("fName1", "lName1", "0002", "email1");
    member[2] = memberDao_.addMember("fName2", "lName2", "0003", "email2");
    member[3] = memberDao_.addMember("fName3", "lName3", "0004", "email3");
    member[4] = memberDao_.addMember("fName4", "lName4", "0005", "email4");
    member[5] = memberDao_.addMember("fName5", "lName5", "0006", "email5");

    Calendar cal = Calendar.getInstance();
    Date now = cal.getTime();

    // create a member with overdue loans
    for (int i = 0; i < 2; i++) {
      ILoan loan = loanDao_.createLoan(member[1], book[i]);
      loanDao_.commitLoan(loan);
    }
    cal.setTime(now);
    cal.add(Calendar.DATE, ILoan.LOAN_PERIOD + 1);
    Date checkDate = cal.getTime();
    loanDao_.updateOverDueStatus(checkDate);

    // create a member with maxed out unpaid fines
    member[2].addFine(10.0f);

    // create a member with maxed out loans
    for (int i = 2; i < 7; i++) {
      ILoan loan = loanDao_.createLoan(member[3], book[i]);
      loanDao_.commitLoan(loan);
    }

    // a member with a fine, but not over the limit
    member[4].addFine(5.0f);

    // a member with a couple of loans but not over the limit
    for (int i = 7; i < 9; i++) {
      ILoan loan = loanDao_.createLoan(member[5], book[i]);
      loanDao_.commitLoan(loan);
    }
    // Note - there are 9 total loans.
  }
예제 #2
0
  @Override
  public void bookScanned(int barcode) {
    System.out.println("bookScanned: got " + barcode);
    if (state != EBorrowState.SCANNING_BOOKS) {
      throw new RuntimeException(
          String.format("BorrowUC_CTL : bookScanned : illegal operation in state: %s", state));
    }
    ui.displayErrorMessage("");

    IBook book = bookDAO.getBookByID(barcode);
    if (book == null) {
      ui.displayErrorMessage(String.format("Book %d not found", barcode));
      return;
    }

    if (book.getState() != EBookState.AVAILABLE) {
      ui.displayErrorMessage(
          String.format("Book %d is not available: %s", book.getID(), book.getState()));
      return;
    }

    if (bookList.contains(book)) {
      ui.displayErrorMessage(String.format("Book %d already scanned: ", book.getID()));
      return;
    }

    scanCount++;
    bookList.add(book);
    ILoan loan = loanDAO.createLoan(borrower, book);
    loanList.add(loan);

    // display current book
    ui.displayScannedBookDetails(book.toString());

    // display pending loans
    ui.displayPendingLoan(buildLoanListDisplay(loanList));

    if (scanCount >= IMember.LOAN_LIMIT) {
      setState(EBorrowState.CONFIRMING_LOANS);
    }
  }