public String getComments() {
   this.book = services.getBook(isbn);
   String username =
       FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal().getName();
   this.user = services.getUser(username);
   return comments;
 }
 public boolean isLiked() {
   this.book = services.getBook(isbn);
   String username =
       FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal().getName();
   this.user = services.getUser(username);
   return this.likedThisBook();
 }
 public String likeBook() {
   this.book = services.getBook(isbn);
   String username =
       FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal().getName();
   this.user = services.getUser(username);
   user.getFavorates().add(book);
   services.updateUser(user);
   return "index";
 }
 @PostConstruct
 public void init() {
   this.isbn =
       FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("isbn");
   if (this.isbn.length() > 5) {
     this.book = services.getBook(isbn);
     String username =
         FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal().getName();
     this.user = services.getUser(username);
   }
 }
 public Book getBook() {
   String is =
       FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("isbn");
   if (is != null && !is.isEmpty()) {
     this.isbn = is;
   }
   this.book = services.getBook(isbn);
   String username =
       FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal().getName();
   this.user = services.getUser(username);
   return book;
 }
 public boolean likedThisBook() {
   this.book = services.getBook(isbn);
   String username =
       FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal().getName();
   this.user = services.getUser(username);
   for (Book bk : user.getFavorates()) {
     if (bk.getTitle().contentEquals(book.getTitle())) {
       return true;
     }
   }
   return false;
 }
 public String borrowBook() {
   this.book = services.getBook(isbn);
   String username =
       FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal().getName();
   this.user = services.getUser(username);
   Loan loan = new Loan();
   loan.setBook(book);
   loan.setUsers(user);
   loan.setLoanedTime(new Date());
   loan.setReturned(false);
   book.getLoans().add(loan);
   user.getLoans().add(loan);
   book.setAvaliable(false);
   services.updateUser(user);
   services.addBook(book);
   return "index";
 }
 public String addComments() {
   this.book = services.getBook(isbn);
   String username =
       FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal().getName();
   this.user = services.getUser(username);
   Comment com = new Comment();
   com.setComment(comments);
   com.setRating(score);
   com.setUsers(user);
   com.setBook(book);
   book.getComments().add(com);
   user.getComments().add(com);
   // services.addComments(com);
   services.updateUser(user);
   services.addBook(book);
   this.comments = "";
   // FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
   return "index";
 }
 public void cleanup() {
   this.book = services.getBook(isbn);
   String username =
       FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal().getName();
   this.user = services.getUser(username);
 }