Skip to content

Commit

Permalink
Fixed ENCUESTAME-445
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan Picado committed Jun 3, 2012
1 parent f3aa95a commit f58b516
Show file tree
Hide file tree
Showing 25 changed files with 222 additions and 125 deletions.
Expand Up @@ -335,12 +335,16 @@ public HashTag getHashTagItem(final String tagName)
* @param limit
* @return
*/
public List<TweetPollBean> getTweetPollsbyHashTagName(final String tagName,
final Integer initResults, final Integer limit,
final String filter, final HttpServletRequest request) {
public List<TweetPollBean> getTweetPollsbyHashTagName(
final String tagName,
final Integer initResults,
final Integer limit,
final String filter,
final HttpServletRequest request,
final SearchPeriods searchPeriods) {
final List<TweetPoll> tweetPolls = getTweetPollDao()
.getTweetpollByHashTagName(tagName, initResults, limit,
TypeSearchResult.getTypeSearchResult(filter));
TypeSearchResult.getTypeSearchResult(filter), searchPeriods);
log.debug("TweetPoll by HashTagId total size ---> " + tweetPolls.size());
final List<TweetPollBean> tweetPollBean = ConvertDomainBean
.convertListToTweetPollBean(tweetPolls);
Expand All @@ -360,7 +364,7 @@ public List<HomeBean> searchLastPublicationsbyHashTag(
final List<HomeBean> allItems = new ArrayList<HomeBean>();
final List<TweetPollBean> tweetPollItems = this
.getTweetPollsbyHashTagName(hashTag.getHashTag(), initResults,
limit, filter, request);
limit, filter, request, SearchPeriods.ALLTIME);
log.debug("FrontEnd TweetPoll items size :" + tweetPollItems.size());
allItems.addAll(ConvertDomainBean
.convertTweetPollListToHomeBean(tweetPollItems));
Expand Down Expand Up @@ -1335,7 +1339,7 @@ private Long getTotalTweetPollPublished(final UserAccount user,
public List<LinksSocialBean> getHashTagLinks(final HashTag hash) {
final List<TweetPollSavedPublishedStatus> links = getFrontEndDao()
.getLinksByHomeItem(hash, null, null, null, null,
TypeSearchResult.HASHTAG);
TypeSearchResult.HASHTAG, SearchPeriods.ALLTIME);
log.debug("getTweetPollLinks " + links.size());
return ConvertDomainBean.convertTweetPollSavedPublishedStatus(links);
}
Expand Down
Expand Up @@ -68,7 +68,8 @@ public List<HashTagDetailStats> getTotalSocialLinksbyHashTagUsageAndDateRange(
if (period == null) {
throw new EnMeSearchException("search params required.");
} else {
final List<TweetPoll> tpolls = getTweetPollsByHashTag(tagName, null, null, TypeSearchResult.HASHTAG); //FIXME: magic numbers
final List<TweetPoll> tpolls = getTweetPollsByHashTag(tagName, null, null, TypeSearchResult.HASHTAG,
period);
for (TweetPoll tweetPoll : tpolls) {
tpSavedPublished = getTweetPollDao()
.getSocialLinksByTypeAndDateRange(tweetPoll, null,
Expand Down Expand Up @@ -103,7 +104,7 @@ public List<HashTagDetailStats> getTotalVotesbyHashTagUsageAndDateRange(
throw new EnMeSearchException("search params required.");
} else {

final List<TweetPoll> tpolls = getTweetPollsByHashTag(tagName, null, null, TypeSearchResult.HASHTAG);
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()
Expand Down Expand Up @@ -323,8 +324,8 @@ private List<Survey> getTotalSurveyUsageByHashTagAndDateRange(
* javax.servlet.http.HttpServletRequest)
*/
public List<HashTagDetailStats> getTotalUsagebyHashTagAndDateRange(
final String hashTagName,
final SearchPeriods period,
final String hashTagName,
final SearchPeriods period,
final HttpServletRequest request)
throws EnMeNoResultsFoundException, EnMeSearchException {
// Check if the hashtag exists
Expand Down Expand Up @@ -387,24 +388,28 @@ public HashTagDetailStats getTotalUsageByHashTag(
final String tagName,
final Integer initResults,
final Integer maxResults,
final TypeSearchResult filter, final HttpServletRequest request) throws EnMeNoResultsFoundException {
final TypeSearchResult filter,
final HttpServletRequest request,
final SearchPeriods periods) throws EnMeNoResultsFoundException {
// Validate if tag belongs to hashtag and filter isn't empty.
Long totalUsagebyHashTag = 0L;
final HashTag tag = getHashTag(tagName, true);
if (tag != null) {
final List<TweetPoll> tweetsbyTag = this.getTweetPollsByHashTag(
tagName, initResults, maxResults, filter);
tagName, initResults, maxResults, filter, periods);
final int totatTweetPolls = tweetsbyTag.size();
final List<Poll> pollsbyTag = this.getPollsByHashTag(tagName,
initResults, maxResults, filter);
initResults, maxResults, filter, periods);
final int totalPolls = pollsbyTag.size();
final List<Survey> surveysbyTag = this.getSurveysByHashTag(tagName,
initResults, maxResults, filter);
initResults, maxResults, filter, periods);
final int totalSurveys = surveysbyTag.size();
totalUsagebyHashTag = (long) (totatTweetPolls + totalPolls + totalSurveys);

}
final HashTagDetailStats detailStatItem = this.createHashTagDetailButtonStats(HashTagRate.LBL_USAGE, totalUsagebyHashTag, HashTagRate.SUB_LBL_TIMES, request);
final HashTagDetailStats detailStatItem = this
.createHashTagDetailButtonStats(HashTagRate.LBL_USAGE,
totalUsagebyHashTag, HashTagRate.SUB_LBL_TIMES, request);
return detailStatItem;
}

Expand All @@ -415,18 +420,25 @@ public HashTagDetailStats getTotalUsageByHashTag(
* getSocialNetworkUseByHashTag(java.lang.String, java.lang.Integer,
* java.lang.Integer, javax.servlet.http.HttpServletRequest)
*/
public HashTagDetailStats getSocialNetworkUseByHashTag(final String tagName,
final Integer initResults, final Integer maxResults, final HttpServletRequest request) {
public HashTagDetailStats getSocialNetworkUseByHashTag(
final String tagName,
final Integer initResults,
final Integer maxResults,
final HttpServletRequest request,
final SearchPeriods searchPeriods) {
// 1- Get tweetPoll, Polls o Survey
Long linksbyTweetPoll = 0L;
Long linksbyPoll = 0L;
Long totalSocialLinks = 0L;
linksbyTweetPoll = this.getTweetPollSocialNetworkLinksbyTag(tagName,
initResults, maxResults, TypeSearchResult.TWEETPOLL);
initResults, maxResults, TypeSearchResult.TWEETPOLL, searchPeriods);
linksbyPoll = this.getPollsSocialNetworkLinksByTag(tagName,
initResults, maxResults, TypeSearchResult.POLL);
initResults, maxResults, TypeSearchResult.POLL, searchPeriods);
totalSocialLinks = linksbyTweetPoll + linksbyPoll;
final HashTagDetailStats detailStatItem = this.createHashTagDetailButtonStats(HashTagRate.LBL_SOCIAL_NETWORK, totalSocialLinks, HashTagRate.SUB_LBL_TWEETS, request);
//TODO: add Survey support
final HashTagDetailStats detailStatItem = this
.createHashTagDetailButtonStats(HashTagRate.LBL_SOCIAL_NETWORK,
totalSocialLinks, HashTagRate.SUB_LBL_TWEETS, request);
return detailStatItem;
}

Expand Down Expand Up @@ -460,20 +472,29 @@ public HashTagDetailStats getHashTagHitsbyName(
* (java.lang.String, java.lang.Integer, java.lang.Integer,
* javax.servlet.http.HttpServletRequest)
*/
public HashTagDetailStats getHashTagUsedOnItemsVoted(final String tagName,
final Integer initResults, final Integer maxResults, final HttpServletRequest request) {
public HashTagDetailStats getHashTagUsedOnItemsVoted(
final String tagName,
final Integer initResults,
final Integer maxResults,
final HttpServletRequest request,
final SearchPeriods periods) {
Long totalVotesbyTweetPoll = 0L;
Long total = 0L;

final List<TweetPoll> tp = this.getTweetPollsByHashTag(tagName, null, null,
TypeSearchResult.HASHTAG);
TypeSearchResult.HASHTAG, periods);
for (TweetPoll tweetPoll : tp) {
totalVotesbyTweetPoll = getTweetPollDao()
.getTotalVotesByTweetPollId(tweetPoll.getTweetPollId());
total = total + totalVotesbyTweetPoll;
}
log.debug("Total HashTag used by Tweetpoll voted: " + total);
final HashTagDetailStats detailStatItem = this.createHashTagDetailButtonStats(HashTagRate.LBL_VOTES, total, HashTagRate.SUB_LBL_VOTES, request);

//FIXME: POLL VOTES? ENCUESTAME-449

final HashTagDetailStats detailStatItem = this
.createHashTagDetailButtonStats(HashTagRate.LBL_VOTES, total,
HashTagRate.SUB_LBL_VOTES, request);
return detailStatItem;
}

Expand All @@ -488,9 +509,9 @@ public HashTagDetailStats getHashTagUsedOnItemsVoted(final String tagName,
*/
private List<Poll> getPollsByHashTag(final String tagName,
final Integer initResults, final Integer maxResults,
final TypeSearchResult filter) {
final TypeSearchResult filter, final SearchPeriods searchPeriods) {
final List<Poll> pollsByTag = getPollDao().getPollByHashTagName(
tagName, initResults, maxResults, filter);
tagName, initResults, maxResults, filter, searchPeriods);
return pollsByTag;
}

Expand All @@ -503,14 +524,16 @@ private List<Poll> getPollsByHashTag(final String tagName,
* @param filter
* @return
*/
private Long getPollsSocialNetworkLinksByTag(final String tagName,
final Integer initResults, final Integer maxResults,
final TypeSearchResult filter) {
private Long getPollsSocialNetworkLinksByTag(
final String tagName,
final Integer initResults,
final Integer maxResults,
final TypeSearchResult filter,
final SearchPeriods searchPeriods) {
Long linksbyItem = 0L;
Long totalLinksByPoll = 0L;

final List<Poll> polls = this.getPollsByHashTag(tagName, initResults,
maxResults, filter);
maxResults, filter, searchPeriods);
for (Poll poll : polls) {
linksbyItem = getTweetPollDao().getSocialLinksByType(null, null,
poll, TypeSearchResult.POLL);
Expand All @@ -528,12 +551,15 @@ private Long getPollsSocialNetworkLinksByTag(final String tagName,
* @param filter
* @return
*/
private List<Survey> getSurveysByHashTag(final String tagName,
final Integer initResults, final Integer maxResults,
final TypeSearchResult filter) {
private List<Survey> getSurveysByHashTag(
final String tagName,
final Integer initResults,
final Integer maxResults,
final TypeSearchResult filter,
final SearchPeriods searchPeriods) {
final List<Survey> surveysByTag = getSurveyDaoImp()
.getSurveysByHashTagName(tagName, initResults, maxResults,
filter);
filter, searchPeriods);
return surveysByTag;
}

Expand All @@ -545,13 +571,16 @@ private List<Survey> getSurveysByHashTag(final String tagName,
* @param filter
* @return
*/
private Long getTweetPollSocialNetworkLinksbyTag(final String tagName,
final Integer initResults, final Integer maxResults,
final TypeSearchResult filter) {
private Long getTweetPollSocialNetworkLinksbyTag(
final String tagName,
final Integer initResults,
final Integer maxResults,
final TypeSearchResult filter,
final SearchPeriods searchPeriods) {
Long linksbyItem = 0L;
Long totalLinksByTweetPoll = 0L;
final List<TweetPoll> tp = this.getTweetPollsByHashTag(tagName,
initResults, maxResults, filter);
initResults, maxResults, filter, searchPeriods);
for (TweetPoll tweetPoll : tp) {
// Get total value by links
linksbyItem = getTweetPollDao().getSocialLinksByType(tweetPoll,
Expand Down Expand Up @@ -580,5 +609,5 @@ private HashTagDetailStats createHashTagDetailButtonStats(
request, new Object[] {}));

return tagDetails;
}
}
}
Expand Up @@ -331,7 +331,7 @@ public void testGetGenericStats() throws EnMeNoResultsFoundException{
// Poll
final Poll poll = createPoll(new Date(), question, "JCPM", getSpringSecurityLoggedUserAccount(), Boolean.TRUE, Boolean.TRUE);
// Survey
final Survey survey = createDefaultSurvey(getSpringSecurityLoggedUserAccount().getAccount(), "Technology survey", new Date());
//final Survey survey = createDefaultSurvey(getSpringSecurityLoggedUserAccount().getAccount(), "Technology survey", new Date());

final GenericStatsBean genericTweetPollStats = getFrontEndService()
.retrieveGenericStats(tpoll.getTweetPollId().toString(),
Expand All @@ -344,12 +344,14 @@ public void testGetGenericStats() throws EnMeNoResultsFoundException{
Assert.assertNotNull(genericPollStats);


final HashTag hashtag = createHashTag("Continents", 350L);
System.out.println(hashtag.getHashTag());
final HashTag hashtag = createHashTag("continents", 350L);
System.out.println(hashtag.getHashTag());
Assert.assertNotNull(hashtag);
Assert.assertNotNull(hashtag.getHashTagId());
Assert.assertNotNull(hashtag.getHashTag());
@SuppressWarnings("unused")
final GenericStatsBean genericHashTagStats = getFrontEndService()
.retrieveGenericStats(hashtag.getHashTag(),
TypeSearchResult.HASHTAG, this.request);
final GenericStatsBean genericHashTagStats = getFrontEndService().retrieveGenericStats(
hashtag.getHashTag(), TypeSearchResult.HASHTAG, this.request);

//final GenericStatsBean genericSurveyStats = getFrontEndService().retrieveGenericStats(survey.getSid(), TypeSearchResult.SURVEY);
//Assert.assertNotNull(genericSurveyStats);
Expand Down
Expand Up @@ -34,6 +34,7 @@
import org.encuestame.persistence.exception.EnMeExpcetion;
import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
import org.encuestame.test.business.security.AbstractSpringSecurityContext;
import org.encuestame.utils.enums.SearchPeriods;
import org.encuestame.utils.enums.TypeSearchResult;
import org.encuestame.utils.json.FolderBean;
import org.encuestame.utils.json.QuestionBean;
Expand Down Expand Up @@ -333,7 +334,7 @@ public void testRemoveHashTagsFromPoll() throws EnMeExpcetion {

final List<Poll> retrievePollsbyTagBeforeRemove = getPollDao()
.getPollByHashTagName(this.tag1.getHashTag(), this.START,
this.MAX_RESULTS, TypeSearchResult.HASHTAG);
this.MAX_RESULTS, TypeSearchResult.HASHTAG, SearchPeriods.ALLTIME);
assertEquals(retrievePollsbyTagBeforeRemove.size(), 2);

// Remove hashtag
Expand All @@ -342,7 +343,7 @@ public void testRemoveHashTagsFromPoll() throws EnMeExpcetion {

final List<Poll> retrievePollsbyTagAfterRemove = getPollDao()
.getPollByHashTagName(this.tag1.getHashTag(), this.START,
this.MAX_RESULTS, TypeSearchResult.HASHTAG);
this.MAX_RESULTS, TypeSearchResult.HASHTAG, SearchPeriods.ALLTIME);
assertEquals(retrievePollsbyTagAfterRemove.size(), 1);
}
}
Expand Up @@ -28,6 +28,7 @@
import org.encuestame.persistence.domain.HashTagRanking;
import org.encuestame.persistence.domain.tweetpoll.TweetPoll;
import org.encuestame.utils.DateUtil;
import org.encuestame.utils.enums.SearchPeriods;
import org.springframework.beans.factory.annotation.Autowired;

/**
Expand Down Expand Up @@ -162,7 +163,9 @@ private HashTagRanking createHashTagRanking(final double average, final HashTag
*/
public Long getHashTagFrecuency(final String tagName, final Integer initResults, final Integer limit){
final Integer totalRelTweetPoll;
final List<TweetPoll> tweetPolls = getTweetPoll().getTweetpollByHashTagName(tagName, initResults, limit, null);
final List<TweetPoll> tweetPolls = getTweetPoll()
.getTweetpollByHashTagName(tagName, initResults, limit, null,
SearchPeriods.ALLTIME);
totalRelTweetPoll = tweetPolls.size();
//TODO:Pending count relevance hashtags for polls and surveys.
return totalRelTweetPoll.longValue();
Expand Down
Expand Up @@ -391,10 +391,11 @@ public List<TweetPoll> getTweetPollsByHashTag(
final String tagName,
final Integer initResults,
final Integer maxResults,
final TypeSearchResult filter) {
final TypeSearchResult filter,
final SearchPeriods searchPeriods) {
final List<TweetPoll> tweetsbyTag = getTweetPollDao()
.getTweetpollByHashTagName(tagName, initResults, maxResults,
filter);
filter, searchPeriods);
return tweetsbyTag;
}

Expand Down
Expand Up @@ -104,7 +104,7 @@ List<HashTagBean> getHashTags(
*/
List<TweetPollBean> getTweetPollsbyHashTagName(final String tagName, final Integer initResults,
final Integer limit, final String filter,
final HttpServletRequest request);
final HttpServletRequest request, final SearchPeriods searchPeriods);

/**
* Get frontEnd items.
Expand Down
Expand Up @@ -112,8 +112,11 @@ List<HashTagDetailStats> getTotalHitsUsagebyHashTagAndDateRange(
* @return
* @throws EnMeNoResultsFoundException
*/
HashTagDetailStats getTotalUsageByHashTag(final String tagName, final Integer initResults,
final Integer maxResults, final TypeSearchResult filter, final HttpServletRequest request) throws EnMeNoResultsFoundException;
HashTagDetailStats getTotalUsageByHashTag(final String tagName,
final Integer initResults, final Integer maxResults,
final TypeSearchResult filter, final HttpServletRequest request,
final SearchPeriods periods)
throws EnMeNoResultsFoundException;

/**
* Get total social network links published by {@link TweetPoll}, {@link Poll} and {@link Survey}.
Expand All @@ -123,7 +126,10 @@ HashTagDetailStats getTotalUsageByHashTag(final String tagName, final Integer in
* @param request
* @return
*/
HashTagDetailStats getSocialNetworkUseByHashTag(final String tagName, final Integer initResults, final Integer maxResults, final HttpServletRequest request);
HashTagDetailStats getSocialNetworkUseByHashTag(final String tagName,
final Integer initResults, final Integer maxResults,
final HttpServletRequest request,
final SearchPeriods searchPeriods);

/**
* Get total hash tag hits by tag name.
Expand All @@ -147,6 +153,9 @@ HashTagDetailStats getHashTagHitsbyName(final String tagName,
* @param request
* @return
*/
HashTagDetailStats getHashTagUsedOnItemsVoted(final String tagName, final Integer initResults, final Integer max, final HttpServletRequest request);
HashTagDetailStats getHashTagUsedOnItemsVoted(final String tagName,
final Integer initResults, final Integer max,
final HttpServletRequest request,
final SearchPeriods periods);

}
Expand Up @@ -62,6 +62,7 @@ public ModelMap getPublishedSocialLinks(
HttpServletRequest request, HttpServletResponse response)
throws JsonGenerationException, JsonMappingException, IOException {
try {
//FUTURE: Add SEARCHPERIODS Filter.
final Map<String, Object> jsonResponse = new HashMap<String, Object>();
if (TypeSearchResult.TWEETPOLL.name().equals(type)) {
final TweetPoll tweetPoll = getTweetPollService()
Expand Down

0 comments on commit f58b516

Please sign in to comment.