/*
  * (non-Javadoc)
  * @see org.encuestame.core.service.imp.IStatisticsService#getTotalSocialLinksbyHashTagUsageAndDateRangeGraph(java.lang.String, org.encuestame.utils.enums.SearchPeriods, javax.servlet.http.HttpServletRequest)
  */
 public List<HashTagDetailStats> getTotalSocialLinksbyHashTagUsageAndDateRangeGraph(
     final String tagName, final SearchPeriods period, final HttpServletRequest request)
     throws EnMeSearchException {
   List<HashTagDetailStats> tagDetailStatsBySocial = new ArrayList<HashTagDetailStats>();
   List<ItemStatDetail> tpSocialSavePublishedDetail = new ArrayList<ItemStatDetail>();
   List<TweetPollSavedPublishedStatus> tpSavedPublished =
       new ArrayList<TweetPollSavedPublishedStatus>();
   if (period == null) {
     throw new EnMeSearchException("search params required.");
   } else {
     // Retrieve all tweetpolls by period
     final List<TweetPoll> tpolls =
         getTweetPollsByHashTag(tagName, null, null, TypeSearchResult.HASHTAG, period);
     for (TweetPoll tweetPoll : tpolls) {
       tpSavedPublished =
           getTweetPollDao()
               .getSocialLinksByTypeAndDateRange(
                   tweetPoll, null, null, TypeSearchResult.TWEETPOLL);
       tpSocialSavePublishedDetail.addAll(
           ConvertDomainBean.convertTweetPollSavedPublishedStatusListToItemDetailBean(
               tpSavedPublished));
     }
     this.removeDuplicatleItemOutOfRange(tpSocialSavePublishedDetail, period.toDays());
     tagDetailStatsBySocial =
         this.compareHashtagListGraph(tpSocialSavePublishedDetail, period, request);
     return tagDetailStatsBySocial;
   }
 }
  /*
   * (non-Javadoc)
   *
   * @see org.encuestame.core.service.imp.IStatisticsService#
   * getTotalVotesbyHashTagUsageAndDateRangeGraph(java.lang.String,
   * org.encuestame.utils.enums.SearchPeriods,
   * javax.servlet.http.HttpServletRequest)
   */
  public List<HashTagDetailStats> getTotalVotesbyHashTagUsageAndDateRangeGraph(
      final String tagName, final SearchPeriods period, final HttpServletRequest request)
      throws EnMeSearchException {
    List<ItemStatDetail> tpResultsBean = new ArrayList<ItemStatDetail>();
    List<TweetPollResult> tpollResults = new ArrayList<TweetPollResult>();
    List<TweetPollSwitch> tpollsSwitch = new ArrayList<TweetPollSwitch>();
    List<HashTagDetailStats> tagDetailStatsByVotes = new ArrayList<HashTagDetailStats>();
    if (period == null) {
      throw new EnMeSearchException("search params required.");
    } else {

      final List<TweetPoll> tpolls =
          getTweetPollsByHashTag(tagName, null, null, TypeSearchResult.HASHTAG, period);
      log.debug("Total Tweetpolls by hashtagName" + tpolls.size());
      for (TweetPoll tweetPoll : tpolls) {
        tpollsSwitch = getTweetPollDao().getListAnswersByTweetPollAndDateRange(tweetPoll);
        log.trace("Total TweetpollSwitch by tweetPoll -->" + tpollsSwitch.size());
        for (TweetPollSwitch tweetPollSwitch : tpollsSwitch) {
          tpollResults = getTweetPollDao().getTweetPollResultsByTweetPollSwitch(tweetPollSwitch);
          log.trace("Total TweetPollResults by tweetPollSwitch -->" + tpollResults.size());
          tpResultsBean.addAll(
              ConvertDomainBean.convertTweetPollResultListToItemDetailBean(tpollResults));
        }
      }
    }
    this.removeDuplicatleItemOutOfRange(tpResultsBean, period.toDays());
    tagDetailStatsByVotes = this.compareHashtagListGraph(tpResultsBean, period, request);
    return tagDetailStatsByVotes;
  }
 /*
  * (non-Javadoc)
  * @see org.encuestame.core.service.imp.IStatisticsService#getTotalSocialLinksbyHashTagUsageAndDateRangeListGraph(java.lang.String, org.encuestame.utils.enums.SearchPeriods, javax.servlet.http.HttpServletRequest)
  */
 @Override
 public List<HashTagListGraphData> getTotalSocialLinksbyHashTagUsageAndDateRangeListGraph(
     String tagName, SearchPeriods period, HttpServletRequest request)
     throws EnMeSearchException, EnMeNoResultsFoundException {
   List<HashTagListGraphData> tagDetailStatsBySocial = new ArrayList<HashTagListGraphData>();
   List<ItemStatDetail> tpSocialSavePublishedDetail = new ArrayList<ItemStatDetail>();
   List<TweetPollSavedPublishedStatus> tpSavedPublished =
       new ArrayList<TweetPollSavedPublishedStatus>();
   if (period == null) {
     throw new EnMeSearchException("search params required.");
   } else {
     final List<TweetPoll> tpolls =
         getTweetPollsByHashTag(tagName, null, null, TypeSearchResult.HASHTAG, period);
     for (TweetPoll tweetPoll : tpolls) {
       final ItemStatDetail statDetail = new ItemStatDetail();
       tpSavedPublished =
           getTweetPollDao()
               .getSocialLinksByTypeAndDateRange(
                   tweetPoll, null, null, TypeSearchResult.TWEETPOLL);
       statDetail.setDate(tweetPoll.getCreateDate());
       statDetail.setItemId(Long.valueOf(tpSavedPublished.size()));
       // FIXME: itemId should be the id of something, now store a "total" value.
       // tpSocialSavePublishedDetail.addAll(ConvertDomainBean.convertTweetPollSavedPublishedStatusListToItemDetailBean(tpSavedPublished));
       tpSocialSavePublishedDetail.add(statDetail);
     }
     this.removeDuplicatleItemOutOfRange(tpSocialSavePublishedDetail, period.toDays());
     tagDetailStatsBySocial.addAll(
         this.groupListItemStatDetail(tpSocialSavePublishedDetail, period, request));
     return tagDetailStatsBySocial;
   }
 }
 /*
  * (non-Javadoc)
  *
  * @see org.encuestame.core.service.imp.IStatisticsService#
  * getTotalHitsUsagebyHashTagAndDateRange(java.lang.String,
  * java.lang.Integer, javax.servlet.http.HttpServletRequest)
  */
 public List<HashTagDetailStats> getTotalHitsUsagebyHashTagAndDateRange(
     final String hashTagName, final SearchPeriods period, final HttpServletRequest request)
     throws EnMeNoResultsFoundException, EnMeSearchException {
   List<Hit> hashTagHits = new ArrayList<Hit>();
   List<HashTagDetailStats> tagDetailStatsByHits = new ArrayList<HashTagDetailStats>();
   final HashTag tag = this.getHashTag(hashTagName, Boolean.TRUE);
   List<ItemStatDetail> itemStatDetailByHits = new ArrayList<ItemStatDetail>();
   if (tag != null) {
     hashTagHits = getFrontEndDao().getHashTagHitsbyDateRange(tag.getHashTagId(), period.toDays());
   }
   itemStatDetailByHits.addAll(ConvertDomainBean.convertHitListToItemDetailBean(hashTagHits));
   tagDetailStatsByHits = this.compareList(itemStatDetailByHits, period, request);
   return tagDetailStatsByHits;
 }