public void checkoutBook(String memberID, String bookCopyId) { // Get Library member's FULL object from file System LibraryMember lm = libraryMemberService.readLibraryMember(memberID); // CheckoutRecord checkoutRecord = lm.getRecord(); // Get BookCopy which we are trying to checkout BookCopy bookCopy = BookCopy.getBookCopy(bookCopyId); // Get the Book Object Book book = Book.get(bookCopy.getISBN()); // Current/ today's date LocalDate checkoutDate = LocalDate.now(); // Duedate = current date PLUS no of days to lend LocalDate dueDate = checkoutDate.plusDays(book.getDaysOfLend()); // Create a new checkout entry CheckoutEntry checkoutEntry = new CheckoutEntry(bookCopy, checkoutDate, dueDate, false); checkoutRecord.addEntry(checkoutEntry); lm.setRecord(checkoutRecord); lm.writeLibraryMember(lm); }
@Override public boolean checkoutBook(String memberId, String isbn) throws LibrarySystemException { Book currentBook = searchBook(isbn); BookCopy[] book = currentBook.getCopies(); for (BookCopy bc : book) { if (computeStatus(bc)) { DataAccessFacade dc = new DataAccessFacade(); LocalDate currentDate = LocalDate.now(); LocalDate dueDate = currentDate.plusDays(bc.getBook().getMaxCheckoutLength()); CheckoutRecordEntry newCheckoutRecordEntry = new CheckoutRecordEntry(currentDate, dueDate, bc); LibraryMember member = search(memberId); CheckoutRecord rc = member.getCheckoutRecord(); if (rc.getCheckoutRecordEntries() == null) { List<CheckoutRecordEntry> entries = new ArrayList<>(); entries.add(newCheckoutRecordEntry); member.getCheckoutRecord().setCheckoutRecordEntries(entries); } else { member.getCheckoutRecord().getCheckoutRecordEntries().add(newCheckoutRecordEntry); } bc.changeAvailability(); dc.updateMember(member); dc.saveNewBook(currentBook); return true; } } return false; }
public void visitLibraryMember(LibraryClass programClass, LibraryMember libraryMember) { // Let the visitor visit the classes referenced in the descriptor string. libraryMember.referencedClassesAccept(classVisitor); }