コード例 #1
0
 @Override
 @Transactional(propagation = Propagation.REQUIRED)
 public Boolean deleteBook(int bookId) throws NoSuchEntityException, ForbiddenException {
   BookEntity book = bookDao.getNotNull(bookId);
   bookAvailabilityService.isBookAvailable(book);
   book.setStatus(BookStatusesEnum.DELETED);
   return bookDao.update(book).getStatus().equals(BookStatusesEnum.DELETED);
 }
コード例 #2
0
 @Override
 public Number countBooksWithLanguage(LanguageEntity languageEntity, BookStatusesEnum status)
     throws ForbiddenException, AuthRequiredException {
   bookAvailabilityService.areBooksWithStatusAvailable(status);
   if (languageEntity == null) {
     return bookDao.countBooks(status);
   }
   Collection<Integer> integers = Sets.newHashSet();
   integers.add(languageEntity.getId());
   return bookDao.countBySubCategories(integers, status);
 }
コード例 #3
0
 @Override
 @Transactional
 public boolean changeStatus(int id, BookStatusesEnum status)
     throws NoSuchEntityException, ForbiddenException, WrongStatusException {
   if (status == null) throw new WrongStatusException();
   BookEntity book = bookDao.getNotNull(id);
   bookAvailabilityService.isStatusChangeAvailable(book, status);
   book.setStatus(status);
   if (status == BookStatusesEnum.ACTIVE) book.setDateChanged(new Date());
   book = bookDao.update(book);
   return book != null;
 }
コード例 #4
0
 @Override
 public Number countBooksForCatalog(
     Set<String> categories, Set<String> subcategories, BookStatusesEnum status)
     throws ForbiddenException, AuthRequiredException {
   bookAvailabilityService.areBooksWithStatusAvailable(status);
   if (CollectionUtils.isEmpty(categories) && CollectionUtils.isEmpty(subcategories)) {
     return bookDao.countBooks(status);
   }
   Collection<Integer> integers =
       subcategoryDao.collectSubcategoryIdsByPriority(categories, subcategories);
   return bookDao.countBySubCategories(integers, status);
 }
コード例 #5
0
 @Override
 @Transactional
 public List<BookEntity> getBooksByAuthor(int authorId, int offset, int limit) {
   List<BookEntity> books;
   if (sessionUtils.isUserWithRole(RolesEnum.admin)
       || (sessionUtils.isUserWithRole(RolesEnum.author)
           && sessionUtils.getUserByToken().getAuthorId() == authorId)) {
     books = bookDao.getBooksByAuthor(authorId, offset, limit, null);
   } else {
     books = bookDao.getBooksByAuthor(authorId, offset, limit, BookStatusesEnum.ACTIVE);
   }
   return books != null ? books : null;
 }
コード例 #6
0
 @Override
 public Number countBooksForCatalog(CategoryEntity categoryEntity, BookStatusesEnum status)
     throws ForbiddenException, AuthRequiredException {
   bookAvailabilityService.areBooksWithStatusAvailable(status);
   if (categoryEntity == null) {
     return bookDao.countBooks(status);
   }
   Collection<Integer> integers = Sets.newHashSet();
   if (CollectionUtils.isNotEmpty(categoryEntity.getSubcategories())) {
     for (SubCategoryEntity sce : categoryEntity.getSubcategories()) integers.add(sce.getId());
   }
   return bookDao.countBySubCategories(integers, status);
 }
コード例 #7
0
 @Override
 @Transactional(propagation = Propagation.REQUIRED)
 public BookEntity getBookById(int bookId) throws ForbiddenException, NoSuchEntityException {
   BookEntity book = bookDao.getNotNull(bookId);
   bookAvailabilityService.isBookAvailable(book);
   return book;
 }
コード例 #8
0
 @Override
 @Transactional
 public Boolean deleteBookToAuthor(int bookId, int authorId)
     throws NoSuchEntityException, ForbiddenException {
   bookAvailabilityService.canDeleteRelationshipToAuthor(bookDao.getNotNull(bookId), authorId);
   return bookAuthorDao.delete(bookId, authorId);
 }
コード例 #9
0
 @Override
 @Transactional
 public Boolean deleteBookToKeyword(int bookId, int authorId)
     throws NoSuchEntityException, ForbiddenException {
   bookAvailabilityService.isCurrentUsersBook(bookDao.getNotNull(bookId));
   return bookKeywordDao.delete(bookId, authorId);
 }
コード例 #10
0
 @Override
 @Transactional(propagation = Propagation.REQUIRED)
 public Integer update(BookEntity book)
     throws ValidationException, IllegalDatabaseStateException, ForbiddenException,
         NoSuchEntityException, AuthRequiredException {
   bookAvailabilityService.isCurrentUsersBook(book);
   BookEntity bookEntity = bookDao.update(book);
   return bookEntity.getId();
 }
コード例 #11
0
 @Override
 @Transactional(propagation = Propagation.REQUIRED)
 public List<BookEntity> getBooks(int offset, int limit)
     throws NoSuchEntityException, NotSupportedFieldException, ForbiddenException,
         AuthRequiredException {
   sessionUtils.allowedForUserWithRole(RolesEnum.admin);
   List<BookEntity> books = bookDao.getNotNull(offset, limit);
   return books;
 }
コード例 #12
0
 private Boolean setStatusAndUpdate(Collection<BookEntity> to, BookStatusesEnum statuses)
     throws ForbiddenException {
   for (BookEntity bookEntity : to) {
     bookAvailabilityService.isStatusChangeAvailable(bookEntity, statuses);
     bookEntity.setStatus(statuses);
     if (!bookDao.update(bookEntity).getStatus().equals(statuses)) {
       return false;
     }
   }
   return true;
 }
コード例 #13
0
 @Override
 public Number countBooksForCatalog(SubCategoryEntity subCategoryEntity, BookStatusesEnum status)
     throws ForbiddenException, AuthRequiredException {
   bookAvailabilityService.areBooksWithStatusAvailable(status);
   if (subCategoryEntity == null) {
     throw new IllegalArgumentException();
   }
   Collection<Integer> integers = Sets.newHashSet();
   integers.add(subCategoryEntity.getId());
   return bookDao.countBySubCategories(integers, status);
 }
コード例 #14
0
 @Override
 @Transactional(propagation = Propagation.REQUIRED)
 public Boolean deleteBook(
     Set<Integer> books_id, Set<Integer> authors_id, Set<Integer> publishers_id)
     throws NoSuchEntityException, ForbiddenException {
   List<BookEntity> booksToDelete = Lists.newArrayList();
   if (CollectionUtils.isNotEmpty(books_id)) {
     booksToDelete.addAll(bookDao.get(books_id));
   }
   if (CollectionUtils.isNotEmpty(authors_id)) {
     booksToDelete.addAll(bookDao.getBooksByAuthor(authors_id));
   }
   if (CollectionUtils.isNotEmpty(publishers_id)) {
     booksToDelete.addAll(bookDao.getBooksByPublisher(publishers_id));
   }
   if (CollectionUtils.isEmpty(booksToDelete)) {
     throw new NoSuchEntityException(BookEntity.class.getName());
   }
   return setStatusAndUpdate(booksToDelete, BookStatusesEnum.DELETED);
 }
コード例 #15
0
  @Override
  @Transactional
  public List<AuthorEntity> getBookAuthors(int id) throws NoSuchEntityException {
    BookEntity book = bookDao.getNotNull(id);
    List<AuthorEntity> list = Lists.newArrayList();

    if (book.getBookToAuthor() != null) {
      for (BookAuthorEntity b2a : book.getBookToAuthor()) list.add(b2a.getAuthor());
    }

    return list;
  }
コード例 #16
0
 @Override
 @Transactional
 public List<KeywordEntity> getBookKeywords(int bookId) throws NoSuchEntityException {
   BookEntity bookEntity = bookDao.getNotNull(bookId);
   List<KeywordEntity> res = null;
   if ((bookEntity != null)
       && (bookEntity.getBookToKeywords() != null)
       && (bookEntity.getBookToKeywords().size() > 0)) {
     res = new ArrayList<KeywordEntity>();
     for (BookKeywordEntity key : bookEntity.getBookToKeywords()) res.add(key.getKeyword());
   }
   return res;
 }
コード例 #17
0
  @Override
  @Transactional(propagation = Propagation.REQUIRED)
  public List<BookEntity> getBooks(int offset, int limit, BookStatusesEnum status)
      throws NoSuchEntityException, NotSupportedFieldException, ForbiddenException,
          AuthRequiredException {
    bookAvailabilityService.areBooksWithStatusAvailable(status);
    List<BookEntity> books = bookDao.getBooksWithStatuses(offset, limit, status);

    if (CollectionUtils.isEmpty(books)) {
      throw new NoSuchEntityException(
          BookEntity.class.getName(),
          String.format("offset %d, limit %d, status %s", offset, limit, status));
    }
    return books;
  }
コード例 #18
0
 @Override
 @Transactional(propagation = Propagation.REQUIRED)
 public Set<BookOnPortalEntity> getBookPortals(int bookId) throws NoSuchEntityException {
   BookEntity book = bookDao.getNotNull(bookId);
   try {
     bookAvailabilityService.isCurrentUsersBook(book);
     return book.getBookPortals();
   } catch (ForbiddenException e) {
     if (book.getBookPortals() == null || book.getBookPortals().size() == 0) return null;
     Set<BookOnPortalEntity> list = new HashSet<BookOnPortalEntity>();
     for (BookOnPortalEntity portal : book.getBookPortals())
       if (BookPortalStatusEnum.ACTIVE.equals(portal.getStatus())) list.add(portal);
     return list;
   }
 }
コード例 #19
0
 @Override
 public List<BookEntity> getBooksForCatalog(
     int offset,
     int limit,
     Set<String> categories,
     Set<String> subcategories,
     BookStatusesEnum status)
     throws NotSupportedFieldException, NoSuchEntityException, ForbiddenException,
         AuthRequiredException {
   bookAvailabilityService.areBooksWithStatusAvailable(status);
   if (CollectionUtils.isEmpty(categories) && CollectionUtils.isEmpty(subcategories)) {
     return getBooks(offset, limit, status);
   }
   Collection<Integer> integers =
       subcategoryDao.collectSubcategoryIdsByPriority(categories, subcategories);
   return bookDao.getBySubCategories(offset, limit, integers, status);
 }
コード例 #20
0
 @Override
 @Transactional(propagation = Propagation.REQUIRED)
 public List<BookEntity> getBooksByIds(
     Iterable<Integer> ids, int count, BookStatusesEnum statusEnum)
     throws NotSupportedFieldException, NoSuchEntityException, ForbiddenException {
   if (ids == null || !ids.iterator().hasNext()) return Lists.newArrayList();
   List<Criterion> criterions = Lists.newArrayList();
   if (statusEnum != null) {
     criterions.add(Restrictions.eq("status", statusEnum));
   } else {
     criterions.add(Restrictions.eq("status", BookStatusesEnum.ACTIVE));
   }
   criterions.add(Restrictions.in("id", Lists.newArrayList(ids)));
   List<BookEntity> res = bookDao.get(0, count, criterions);
   if (sessionUtils.isUserWithAnotherRole(RolesEnum.admin)) {
     if (statusEnum != null && !BookStatusesEnum.ACTIVE.equals(statusEnum)) {
       bookAvailabilityService.areBooksAvailable(res);
     }
   }
   return res;
 }
コード例 #21
0
 @Override
 @Transactional(propagation = Propagation.REQUIRED)
 public BookEntity getBookByIsbn(String isbn)
     throws NoSuchEntityException, IllegalDatabaseStateException {
   return bookDao.getByIsbnNotNull(isbn);
 }
コード例 #22
0
 @Override
 public int countBookComments(int bookId) throws NoSuchEntityException {
   bookDao.getNotNull(bookId);
   return bookCommentDao.count(bookId).intValue();
 }
コード例 #23
0
 @Override
 @Transactional(propagation = Propagation.REQUIRED)
 public Integer get(String isbn) throws NoSuchEntityException, IllegalDatabaseStateException {
   BookEntity book = bookDao.getByIsbnNotNull(isbn);
   return book.getId();
 }
コード例 #24
0
 @Override
 public Integer countBooks(Map<String, List<Criterion>> criterions) {
   return bookDao.countBooks(criterions);
 }