/** * Get books for user * * @param userId the user that is being searched for * @param wantToSeeWishList do they want to see the books that have been read or the books that * they want to read * @return the list of books requested */ public ArrayList<ArrayList<String>> getUserReadingList(int userId, int wantToSeeWishList) { List<UserReadingList> allUsersReadingList = new ArrayList<UserReadingList>(); allUsersReadingList = getAllUserReadingList(); ArrayList<ArrayList<String>> userReadingList = new ArrayList<ArrayList<String>>(); ArrayList<String> bookInfo = null; BookDaoWithHibernate book = new BookDaoWithHibernate(); ReviewListDaoWithHibernate review = new ReviewListDaoWithHibernate(); for (UserReadingList bookToRead : allUsersReadingList) { if (bookToRead.getUser_id() == userId) { int wishList = bookToRead.getWish_list(); // if book is on the wish list dont show if (wishList == wantToSeeWishList) { bookInfo = new ArrayList<String>(); log.info(bookToRead.getBook_id()); int bookId = bookToRead.getBook_id(); String dateAdded = bookToRead.getDate_added(); int readingId = bookToRead.getReading_id(); // get book title and author from bookID String title = book.getTitleFromId(bookId); String author = book.getAuthorFromId(bookId); // get notes and recommended from bookId, userId and readingId String notes = review.getNotesFromReview(bookId, userId, readingId); int rating = (int) review.getRatingFromReview(bookId, userId, readingId); String recommended = "Yes"; if (rating != 1) { recommended = "No"; } String bookIdString = Integer.toString(bookId); // log.info(bookIdString); bookInfo.add(bookIdString); bookInfo.add(title); bookInfo.add(author); bookInfo.add(notes); bookInfo.add(recommended); bookInfo.add(dateAdded); userReadingList.add(bookInfo); } } } log.info("user reading list size" + userReadingList.size()); return userReadingList; }
/** * check to see if a person has read a book * * @param userId user to see if they have read a book * @param bookId book being checked on * @return if the book has been read or not */ public boolean hasUserReadBook(int userId, int bookId) { List<UserReadingList> allUsersReadingList = new ArrayList<UserReadingList>(); allUsersReadingList = getAllUserReadingList(); boolean hasReadBook = false; for (UserReadingList readingList : allUsersReadingList) { if (readingList.getUser_id() == userId) { if (readingList.getBook_id() == bookId) { if (readingList.getWish_list() == 0) { hasReadBook = true; } } } } return hasReadBook; }