/**
  * Verifies the "completeness" of podcast resource sent over the wire
  *
  * @param podcast
  * @return
  */
 private boolean isFullUpdate(Podcast podcast) {
   return podcast.getId() == null
       || podcast.getFeed() == null
       || podcast.getLinkOnPodcastpedia() == null
       || podcast.getTitle() == null
       || podcast.getDescription() == null;
 }
 @Transactional("transactionManager")
 public void updatePartiallyPodcast(Podcast podcast) throws AppException {
   // do a validation to verify existence of the resource
   Podcast verifyPodcastExistenceById = verifyPodcastExistenceById(podcast.getId());
   if (verifyPodcastExistenceById == null) {
     throw new AppException(
         Response.Status.NOT_FOUND.getStatusCode(),
         404,
         "The resource you are trying to update does not exist in the database",
         "Please verify existence of data in the database for the id - " + podcast.getId(),
         AppConstants.BLOG_POST_URL);
   }
   copyPartialProperties(verifyPodcastExistenceById, podcast);
   podcastDao.updatePodcast(new PodcastEntity(verifyPodcastExistenceById));
 }
 private void validateInputForCreation(Podcast podcast) throws AppException {
   if (podcast.getFeed() == null) {
     throw new AppException(
         Response.Status.BAD_REQUEST.getStatusCode(),
         400,
         "Provided data not sufficient for insertion",
         "Please verify that the feed is properly generated/set",
         AppConstants.BLOG_POST_URL);
   }
   if (podcast.getTitle() == null) {
     throw new AppException(
         Response.Status.BAD_REQUEST.getStatusCode(),
         400,
         "Provided data not sufficient for insertion",
         "Please verify that the title is properly generated/set",
         AppConstants.BLOG_POST_URL);
   }
   // etc...
 }
  /** ******************* UPDATE-related methods implementation ********************* */
  @Transactional("transactionManager")
  public void updateFullyPodcast(Podcast podcast) throws AppException {
    // do a validation to verify FULL update with PUT
    if (isFullUpdate(podcast)) {
      throw new AppException(
          Response.Status.BAD_REQUEST.getStatusCode(),
          400,
          "Please specify all properties for Full UPDATE",
          "required properties - id, title, feed, lnkOnPodcastpedia, description",
          AppConstants.BLOG_POST_URL);
    }

    Podcast verifyPodcastExistenceById = verifyPodcastExistenceById(podcast.getId());
    if (verifyPodcastExistenceById == null) {
      throw new AppException(
          Response.Status.NOT_FOUND.getStatusCode(),
          404,
          "The resource you are trying to update does not exist in the database",
          "Please verify existence of data in the database for the id - " + podcast.getId(),
          AppConstants.BLOG_POST_URL);
    }

    podcastDao.updatePodcast(new PodcastEntity(podcast));
  }
  /** ******************* Create related methods implementation ********************* */
  @Transactional("transactionManager")
  public Long createPodcast(Podcast podcast) throws AppException {

    validateInputForCreation(podcast);

    // verify existence of resource in the db (feed must be unique)
    PodcastEntity podcastByFeed = podcastDao.getPodcastByFeed(podcast.getFeed());
    if (podcastByFeed != null) {
      throw new AppException(
          Response.Status.CONFLICT.getStatusCode(),
          409,
          "Podcast with feed already existing in the database with the id " + podcastByFeed.getId(),
          "Please verify that the feed and title are properly generated",
          AppConstants.BLOG_POST_URL);
    }

    return podcastDao.createPodcast(new PodcastEntity(podcast));
  }