}
@Implements(BorrowBooks.class)
public void borrow(int membershipId, int bookId) {
//Member m = authenticate(membershipId);
Member m = null;
if (m==null) {
throw new LibraryException("Could not find member: "+membershipId);
}
int borrowedBookCount = m.getBorrowedBookCount();
if (borrowedBookCount < m.getBorrowedBookLimit()) {
Book b = db.retrieveBook(bookId);
BookState bs = b.getState();
if ((bs==BookState.ON_SHELF) || (bs==BookState.RETURNED)) {
b.setState(BookState.BORROWED);
b.setBorrower(m);
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MONTH, 1);
b.setReturnDate(cal.getTime());
db.saveBook(b);
m.setBorrowedBookCount(borrowedBookCount+1);
db.saveMember(m);
} else {
throw new LibraryException("Book is already borrowed "+b.getState());
}
} else {
throw new LibraryException("Book limit exceeded for "+m.getName());
}
}