/**
  * Delete news by id
  *
  * @param idNews
  * @return true when the operation was successful, otherwise false
  * @throws ServiceException
  */
 @Transactional(rollbackFor = ServiceException.class)
 @Override
 public boolean deleteNews(int idNews) throws ServiceException {
   boolean relationDeletedIsSuccessA = newsService.deleteRelationForAuthorAndNewsByNews(idNews);
   boolean relationDeletedIsSuccessT = newsService.deleteRelationForTagAndNewsByNews(idNews);
   boolean deletedNewsIsSuccess = newsService.deleteNews(idNews);
   return deletedNewsIsSuccess && relationDeletedIsSuccessA && relationDeletedIsSuccessT;
 }
 /**
  * change tag in news
  *
  * @param idNews
  * @param tags
  * @return true when the operation was successful, otherwise false
  * @throws ServiceException
  */
 @Transactional(rollbackFor = ServiceException.class)
 @Override
 public boolean editRelationsForTagAndNews(int idNews, List<Integer> tags)
     throws ServiceException {
   newsService.deleteRelationForTagAndNewsByNews(idNews);
   if (tags != null) {
     for (Integer tag : tags) {
       newsService.addRelationForTagAndNews(idNews, tag);
     }
   }
   return true;
 }
 /**
  * Add news with author and tags
  *
  * @param news
  * @param author
  * @param tags
  * @return newsId
  * @throws ServiceException
  */
 @Transactional(rollbackFor = ServiceException.class)
 @Override
 public int addNews(News news, Author author, List<Integer> tags) throws ServiceException {
   int idNews =
       newsService.addNews(
           news.getShortText(), news.getFullText(), news.getTitle(), news.getCreationDate());
   newsService.addRelationForAuthorAndNews(idNews, author.getAuthorId());
   if (tags != null) {
     for (Integer tag : tags) {
       newsService.addRelationForTagAndNews(idNews, tag);
     }
   }
   return idNews;
 }
 /**
  * Add new tag in news
  *
  * @param idNews
  * @param tagName
  * @return true when the operation was successful, otherwise false
  * @throws ServiceException
  */
 @Transactional(rollbackFor = ServiceException.class)
 @Override
 public boolean addTag(int idNews, String tagName) throws ServiceException {
   int id = tagService.addTag(tagName);
   boolean relationAddedIsSuccess = newsService.addRelationForTagAndNews(idNews, id);
   return id != 0 && relationAddedIsSuccess;
 }
 /**
  * Get list of all news
  *
  * @param currentIndex
  * @param filter
  * @param countNewsOfPage
  * @return List of news
  * @throws ServiceException
  */
 @Transactional(rollbackFor = ServiceException.class)
 @Override
 public List<News> getAllNewsForPage(int currentIndex, FilterForm filter, int countNewsOfPage)
     throws ServiceException {
   return newsService.getAllNewsForPage(
       currentIndex * countNewsOfPage - 2, currentIndex * countNewsOfPage, filter);
 }
 /**
  * Delete author by id
  *
  * @param idAuthor
  * @return true when the operation was successful, otherwise false
  * @throws ServiceException
  */
 @Transactional(rollbackFor = ServiceException.class)
 @Override
 public boolean deleteAuthor(int idAuthor) throws ServiceException {
   boolean relationDeletedIsSuccess = newsService.deleteRelationForAuthorAndNewsByAuthor(idAuthor);
   boolean authorDeletedIsSuccess = authorService.deleteAuthor(idAuthor);
   return authorDeletedIsSuccess && relationDeletedIsSuccess;
 }
 /**
  * Adding author in news
  *
  * @param idNews
  * @param nameOfAuthor
  * @return true when the operation was successful, otherwise false
  * @throws ServiceException
  */
 @Transactional(rollbackFor = ServiceException.class)
 @Override
 public boolean addAuthor(int idNews, String nameOfAuthor) throws ServiceException {
   int id = authorService.addAuthorByName(nameOfAuthor);
   boolean relationAddedIsSuccess = newsService.addRelationForAuthorAndNews(idNews, id);
   return id != 0 && relationAddedIsSuccess;
 }