예제 #1
0
  // lazy removing
  private void updateUsersBooks(List<Book> books) {

    List<String> changedList = new ArrayList<String>();
    for (Book b : books) changedList.add(b.getId());

    User user = ProfileController.getAuthenticatedUser();
    user.setBooks(changedList);
    userService.save(user);
    ProfileController.authenticateUser(user);
  }
예제 #2
0
  private void updateBookFields(Book book, BookDto bookDto) {

    book.setAuthor(bookDto.getAuthor());
    book.setDescription(bookDto.getDescription());
    book.setBookLanguage(bookDto.getLanguage());
    book.setPages(bookDto.getPages());
    book.setTitle(bookDto.getTitle());
    book.setYear(bookDto.getYear());

    String categoryId = null;
    if (!bookDto.getCategory().equals("default")) categoryId = bookDto.getCategory();

    book.setCategory(categoryId);
  }
예제 #3
0
  @Override
  public Book save(Book book) {

    bookDao.add(book);
    deleteBookFromCategories(book.getId());

    if (book.getCategory() != null && categoryDao.get(book.getCategory()) != null) {

      Category category = categoryDao.get(book.getCategory());
      HashSet<String> booksSet = category.getBooks();
      if (booksSet == null) booksSet = new HashSet<String>();

      booksSet.add(book.getId());
      category.setBooks(booksSet);
      categoryDao.add(category);
    }

    bookDao.add(book);
    return get(book.getId());
  }
예제 #4
0
  @Override
  public void delete(Book book) {

    deleteBookFromCategories(book.getId());
    bookDao.delete(book);
  }