Juan Carlos Picado Herrera avatar Juan Carlos Picado Herrera committed 75d1674

Finished top users.
In progress ENCUESTAME-446

Comments (0)

Files changed (12)

enme-business/src/main/java/org/encuestame/business/service/FrontEndServices.java

 /**
- * 
+ *
  */
 package org.encuestame.business.service;
 
 @Service
 public class FrontEndServices  extends AbstractBaseService implements IFrontEndService {
 
-	 /** Front End Service Log. **/
+     /** Front End Service Log. **/
     private Logger log = Logger.getLogger(this.getClass());
 
     /** Max Results. **/
 
     /** {@link SecurityOperations} **/
     @Autowired
-    private SecurityOperations securityService; 
-    
+    private SecurityOperations securityService;
+
     /**
      * Search Items By tweetPoll.
      *
      *             search exception.
      */
     public List<TweetPollBean> searchItemsByTweetPoll(
-    		final String period,
-            final Integer start, 
+            final String period,
+            final Integer start,
             Integer maxResults,
             final HttpServletRequest request) throws EnMeSearchException {
         final List<TweetPollBean> results = new ArrayList<TweetPollBean>();
      * javax.servlet.http.HttpServletRequest)
      */
     public List<HomeBean> getFrontEndItems(
-    		final String period,
-            final Integer start, 
+            final String period,
+            final Integer start,
             final Integer maxResults,
             final HttpServletRequest request) throws EnMeSearchException {
         // Sorted list based comparable interface
         Collections.sort(allItems);
         // limit the total resuls to maxResults requested
         if (maxResults != null && allItems.size() > maxResults) {
-        	allItems = allItems.subList(0, maxResults);
+            allItems = allItems.subList(0, maxResults);
         }
         return allItems;
     }
-    
+
    /*
     * (non-Javadoc)
     * @see org.encuestame.core.service.imp.IFrontEndService#getLastItemsPublishedFromUserAccount(java.lang.String, java.lang.Integer, java.lang.Boolean, javax.servlet.http.HttpServletRequest)
     */
-	public List<HomeBean> getLastItemsPublishedFromUserAccount(
-			final String username, 
-			final Integer maxResults,
-			final Boolean showUnSharedItems,
-			final HttpServletRequest request) throws EnMeNoResultsFoundException {
-			//get tweetpolls
-		final UserAccount user = getUserAccount(username);
-		log.debug("getLastItemsPublishedFromUserAccount: "+user.getUsername());
-		final List<TweetPoll> lastTp = getTweetPollDao().getTweetPollByUsername(maxResults, user);
-		log.debug("getLastItemsPublishedFromUserAccount lastTp: "+lastTp.size());
-		final List<Poll> lastPoll = getPollDao().getPollByUserIdDate(null, user, maxResults, EnMeUtils.DEFAULT_START);
-		log.debug("getLastItemsPublishedFromUserAccount lastPoll: "+lastPoll.size());
-		final List<HomeBean> totalItems = new ArrayList<HomeBean>();
-		//convert poll to home beans
-		totalItems.addAll(ConvertDomainBean.convertPollListToHomeBean(ConvertDomainBean.convertListToPollBean(lastPoll)));
-		//convert TweetPoll to home beans
-		totalItems.addAll(ConvertDomainBean.convertTweetPollListToHomeBean(ConvertDomainBean.convertListToTweetPollBean(lastTp)));
-		//TODO: add survey Items.
-		
-		//order items
-		Collections.sort(totalItems, new RecentItemsComparator());
-		//fill the relative time.
-		if (request != null) {
-			fillHomeBeanRelativeTime(totalItems, request);
-		}
-		log.debug("getLastItemsPublishedFromUserAccount after sort: "+totalItems.size());
-		//ListUtils.
-    	return totalItems;
+    public List<HomeBean> getLastItemsPublishedFromUserAccount(
+            final String username,
+            final Integer maxResults,
+            final Boolean showUnSharedItems,
+            final HttpServletRequest request) throws EnMeNoResultsFoundException {
+            //get tweetpolls
+        final UserAccount user = getUserAccount(username);
+        log.debug("getLastItemsPublishedFromUserAccount: "+user.getUsername());
+        final List<TweetPoll> lastTp = getTweetPollDao().getTweetPollByUsername(maxResults, user);
+        log.debug("getLastItemsPublishedFromUserAccount lastTp: "+lastTp.size());
+        final List<Poll> lastPoll = getPollDao().getPollByUserIdDate(null, user, maxResults, EnMeUtils.DEFAULT_START);
+        log.debug("getLastItemsPublishedFromUserAccount lastPoll: "+lastPoll.size());
+        final List<HomeBean> totalItems = new ArrayList<HomeBean>();
+        //convert poll to home beans
+        totalItems.addAll(ConvertDomainBean.convertPollListToHomeBean(ConvertDomainBean.convertListToPollBean(lastPoll)));
+        //convert TweetPoll to home beans
+        totalItems.addAll(ConvertDomainBean.convertTweetPollListToHomeBean(ConvertDomainBean.convertListToTweetPollBean(lastTp)));
+        //TODO: add survey Items.
+
+        //order items
+        Collections.sort(totalItems, new RecentItemsComparator());
+        //fill the relative time.
+        if (request != null) {
+            fillHomeBeanRelativeTime(totalItems, request);
+        }
+        log.debug("getLastItemsPublishedFromUserAccount after sort: "+totalItems.size());
+        //ListUtils.
+        return totalItems;
     }
 
     /**
         log.debug("searchItemsByPoll start " + period);
         log.debug("searchItemsByPoll maxResults " + maxResults);
         //avoid null values
-        maxResults = maxResults == null ? this.MAX_RESULTS : maxResults;       
+        maxResults = maxResults == null ? this.MAX_RESULTS : maxResults;
         final List<Poll> items = new ArrayList<Poll>();
         if (period == null) {
             throw new EnMeSearchException("search params required");
      * @return
      */
     public List<TweetPollBean> getTweetPollsbyHashTagName(
-    		final String tagName,
+            final String tagName,
             final Integer initResults,
             final Integer limit,
-            final String filter, 
+            final String filter,
             final HttpServletRequest request,
             final SearchPeriods searchPeriods) {
         final List<TweetPoll> tweetPolls = getTweetPollDao()
         }
         return hit;
     }
-    
+
     /*
      * (non-Javadoc)
      * @see org.encuestame.core.service.imp.IFrontEndService#registerVote()
      */
-	public Status registerVote(final Long itemId,
-			final TypeSearchResult searchResult,
-			 final String ipAddress) {
-
-		//FIXME: need a restrictions to avoid repeated votes  
-				
-    	Status status = Status.SUCCESS;
-    	final Long INCREASE_VOTES = 1L;
-    	final String userVote = getUserPrincipalUsername();
-    	log.debug("registerVote: "+userVote);
-		final Hit hit = new Hit();
-		hit.setHitCategory(HitCategory.VOTE);
-		hit.setIpAddress(ipAddress);
-    		try {
-				//vote process
-				if (searchResult.equals(TypeSearchResult.TWEETPOLL)) {
-					final TweetPoll tp = getTweetPollService().getTweetPollPublishedById(itemId);
-					final Long votes = tp.getNumbervotes() + INCREASE_VOTES;
-					tp.setNumbervotes(votes);
-					hit.setTweetPoll(tp);
-					getTweetPollDao().saveOrUpdate(tp);
-				} else if (searchResult.equals(TypeSearchResult.POLL)) {
-					final Poll poll = getPollService().getPollById(itemId);	
-					final Long votes = poll.getNumbervotes() + INCREASE_VOTES;
-					poll.setNumbervotes(votes);
-					getPollDao().saveOrUpdate(poll);
-					hit.setPoll(poll);
-				} else if (searchResult.equals(TypeSearchResult.SURVEY)) {
-					//TODO: Vote a Survey.
-				}
-				//register the vote.
-				if (!EnMeUtils.ANONYMOUS_USER.equals(userVote)) {
-					UserAccount userAccount = getUserAccount(userVote);
-					hit.setUserAccount(userAccount);
-					log.debug("registerVote by userAccount: "+userAccount.getUsername());
-				}				
-				hit.setHitDate(Calendar.getInstance().getTime());
-				getAccountDao().saveOrUpdate(hit);
-			} catch (EnMeNoResultsFoundException e) {
-				log.error(e);
-				status = Status.FAILED;
-			}    	
-    	return status;
+    public Status registerVote(final Long itemId,
+            final TypeSearchResult searchResult,
+             final String ipAddress) {
+
+        //FIXME: need a restrictions to avoid repeated votes
+
+        Status status = Status.SUCCESS;
+        final Long INCREASE_VOTES = 1L;
+        final String userVote = getUserPrincipalUsername();
+        log.debug("registerVote: "+userVote);
+        final Hit hit = new Hit();
+        hit.setHitCategory(HitCategory.VOTE);
+        hit.setIpAddress(ipAddress);
+            try {
+                //vote process
+                if (searchResult.equals(TypeSearchResult.TWEETPOLL)) {
+                    final TweetPoll tp = getTweetPollService().getTweetPollPublishedById(itemId);
+                    final Long votes = tp.getNumbervotes() + INCREASE_VOTES;
+                    tp.setNumbervotes(votes);
+                    hit.setTweetPoll(tp);
+                    getTweetPollDao().saveOrUpdate(tp);
+                } else if (searchResult.equals(TypeSearchResult.POLL)) {
+                    final Poll poll = getPollService().getPollById(itemId);
+                    final Long votes = poll.getNumbervotes() + INCREASE_VOTES;
+                    poll.setNumbervotes(votes);
+                    getPollDao().saveOrUpdate(poll);
+                    hit.setPoll(poll);
+                } else if (searchResult.equals(TypeSearchResult.SURVEY)) {
+                    //TODO: Vote a Survey.
+                }
+                //register the vote.
+                if (!EnMeUtils.ANONYMOUS_USER.equals(userVote)) {
+                    UserAccount userAccount = getUserAccount(userVote);
+                    hit.setUserAccount(userAccount);
+                    log.debug("registerVote by userAccount: "+userAccount.getUsername());
+                }
+                hit.setHitDate(Calendar.getInstance().getTime());
+                getAccountDao().saveOrUpdate(hit);
+            } catch (EnMeNoResultsFoundException e) {
+                log.error(e);
+                status = Status.FAILED;
+            }
+        return status;
     }
 
     /*
      * java.util.List, java.util.Calendar, java.util.Calendar)
      */
     public void processItemstoCalculateRelevance(
-            final List<TweetPoll> tweetPollList, 
+            final List<TweetPoll> tweetPollList,
             final List<Poll> pollList,
             final List<Survey> surveyList,
             final SearchPeriods periods) {
             getPollDao().saveOrUpdate(poll);
         }
 
-    } 
-    
+    }
+
     /**
      * Get last {@link HashTagRanking} position
      * @param maxDate
      * @param tagName
      * @return
      */
-	private Integer getHashTagLastPosition(final Date maxDate,
-			final String tagName) {
-		Integer lastPosValue = null;
-		final List<HashTagRanking> tagRanking = getHashTagDao().getHashTagRankingLastPosition(maxDate);
-		if (tagRanking.size() > 0) {
-			for (int i = 0; i < tagRanking.size(); i++) {
-				if (tagRanking.get(i).getHashTag().getHashTag().equals(tagName)) {
-					lastPosValue = i+1;
-				}
-			}
-		}
-		return lastPosValue;
-	}
- 
+    private Integer getHashTagLastPosition(final Date maxDate,
+            final String tagName) {
+        Integer lastPosValue = null;
+        final List<HashTagRanking> tagRanking = getHashTagDao().getHashTagRankingLastPosition(maxDate);
+        if (tagRanking.size() > 0) {
+            for (int i = 0; i < tagRanking.size(); i++) {
+                if (tagRanking.get(i).getHashTag().getHashTag().equals(tagName)) {
+                    lastPosValue = i+1;
+                }
+            }
+        }
+        return lastPosValue;
+    }
+
     /*
      * (non-Javadoc)
      *
      * .lang.String)
      */
     public List<HashTagRankingBean> getHashTagRanking(final String tagName) {
-    	final Date maxRankingDate;
-    	maxRankingDate = getHashTagDao().getMaxHashTagRankingDate(); 
-    	
+        final Date maxRankingDate;
+        maxRankingDate = getHashTagDao().getMaxHashTagRankingDate();
+
         List<HashTagRanking> hashTagRankingList = getHashTagDao()
                 .getHashTagRankStats(maxRankingDate);
         log.debug("Hashtag ranking list --->" + hashTagRankingList.size());
         final Integer value = 1;
         Integer position = 0;
-        Integer lastRankPosition; 
-      
+        Integer lastRankPosition;
+
         final List<HashTagRankingBean> tagRankingBeanList = new ArrayList<HashTagRankingBean>();
-        
+
         HashTagRankingBean ranking = new HashTagRankingBean();
         final Integer hashTagRankListSize = hashTagRankingList.size() - value;
         Integer positionBefore;
         Integer positionAfter;
         log.debug("Hashtag ranking list --->" + hashTagRankListSize);
-        for (int i = 0; i < hashTagRankingList.size(); i++) { 
-			if (hashTagRankingList.get(i).getHashTag().getHashTag()
-					.equals(tagName)) {
+        for (int i = 0; i < hashTagRankingList.size(); i++) {
+            if (hashTagRankingList.get(i).getHashTag().getHashTag()
+                    .equals(tagName)) {
                 // Retrieve hashtag main.
                 position =i;
                 positionBefore = position - value;
                 positionAfter = position + value;
                 lastRankPosition = this.getHashTagLastPosition(maxRankingDate, hashTagRankingList.get(i).getHashTag().getHashTag());
-				ranking = this.createHashTagRankingBean(
-						hashTagRankingList.get(i).getRankId(),
-						hashTagRankingList.get(i).getAverage(), positionAfter, tagName,
-						lastRankPosition);
-  
+                ranking = this.createHashTagRankingBean(
+                        hashTagRankingList.get(i).getRankId(),
+                        hashTagRankingList.get(i).getAverage(), positionAfter, tagName,
+                        lastRankPosition);
+
                 tagRankingBeanList.add(ranking);
                 log.debug("HashTag ranking main ---> "
                         + hashTagRankingList.get(i).getHashTag().getHashTag());
-                log.debug("HashTag ranking main position---> " + position); 
-                
-                if ((position > 0) && (position < hashTagRankListSize)) { 
+                log.debug("HashTag ranking main position---> " + position);
+
+                if ((position > 0) && (position < hashTagRankListSize)) {
                     log.debug(" --- HashTag ranking first option ---");
-                    // Save hashTag before item 
+                    // Save hashTag before item
+                    lastRankPosition = this.getHashTagLastPosition(maxRankingDate, hashTagRankingList.get(positionBefore).getHashTag().getHashTag());
+                    ranking = this
+                            .createHashTagRankingBean(
+                                    hashTagRankingList.get(positionBefore)
+                                            .getRankId(), hashTagRankingList
+                                            .get(positionBefore).getAverage(),
+                                            position,
+                                    hashTagRankingList.get(positionBefore)
+                                            .getHashTag().getHashTag(),
+                                    lastRankPosition);
+                    tagRankingBeanList.add(ranking);
+
+                    // Save hashTag after item
+                    lastRankPosition = this.getHashTagLastPosition(maxRankingDate, hashTagRankingList.get(positionAfter).getHashTag().getHashTag());
+                    ranking = this.createHashTagRankingBean(hashTagRankingList
+                            .get(positionAfter).getRankId(), hashTagRankingList
+                            .get(positionAfter).getAverage(), position +2,
+                            hashTagRankingList.get(positionAfter).getHashTag()
+                                    .getHashTag(), lastRankPosition);
+
+                    tagRankingBeanList.add(ranking);
+                } else if ((position > 0) && (position == hashTagRankListSize)) {
+                    log.debug(" --- HashTag ranking second option --- ");
+                    // Save hashTag before item
                     lastRankPosition = this.getHashTagLastPosition(maxRankingDate, hashTagRankingList.get(positionBefore).getHashTag().getHashTag());
-					ranking = this
-							.createHashTagRankingBean(
-									hashTagRankingList.get(positionBefore)
-											.getRankId(), hashTagRankingList
-											.get(positionBefore).getAverage(),
-											position,
-									hashTagRankingList.get(positionBefore)
-											.getHashTag().getHashTag(),
-									lastRankPosition);
-                    tagRankingBeanList.add(ranking); 
-
-                    // Save hashTag after item 
+                    ranking = this
+                            .createHashTagRankingBean(
+                                    hashTagRankingList.get(positionBefore)
+                                            .getRankId(), hashTagRankingList
+                                            .get(positionBefore).getAverage(),
+                                            position,
+                                    hashTagRankingList.get(positionBefore)
+                                            .getHashTag().getHashTag(),
+                                    lastRankPosition);
+                    tagRankingBeanList.add(ranking);
+                } else if ((position == 0)) {
+                    log.debug(" --- HashTag ranking second option --- ");
+                    // Save hashTag after item
                     lastRankPosition = this.getHashTagLastPosition(maxRankingDate, hashTagRankingList.get(positionAfter).getHashTag().getHashTag());
-					ranking = this.createHashTagRankingBean(hashTagRankingList
-							.get(positionAfter).getRankId(), hashTagRankingList
-							.get(positionAfter).getAverage(), position +2,
-							hashTagRankingList.get(positionAfter).getHashTag()
-									.getHashTag(), lastRankPosition);
-                    
+                    ranking = this.createHashTagRankingBean(hashTagRankingList
+                            .get(positionAfter).getRankId(), hashTagRankingList
+                            .get(positionAfter).getAverage(), i+2,
+                            hashTagRankingList.get(positionAfter).getHashTag()
+                                    .getHashTag(), lastRankPosition);
                     tagRankingBeanList.add(ranking);
-				} else if ((position > 0) && (position == hashTagRankListSize)) {
-					log.debug(" --- HashTag ranking second option --- ");
-					// Save hashTag before item
-				    lastRankPosition = this.getHashTagLastPosition(maxRankingDate, hashTagRankingList.get(positionBefore).getHashTag().getHashTag());
-					ranking = this
-							.createHashTagRankingBean(
-									hashTagRankingList.get(positionBefore)
-											.getRankId(), hashTagRankingList
-											.get(positionBefore).getAverage(),
-											position,
-									hashTagRankingList.get(positionBefore)
-											.getHashTag().getHashTag(),
-									lastRankPosition);
-					tagRankingBeanList.add(ranking);
-				} else if ((position == 0)) { 
-					log.debug(" --- HashTag ranking second option --- ");
-					// Save hashTag after item
-					lastRankPosition = this.getHashTagLastPosition(maxRankingDate, hashTagRankingList.get(positionAfter).getHashTag().getHashTag());
-					ranking = this.createHashTagRankingBean(hashTagRankingList
-							.get(positionAfter).getRankId(), hashTagRankingList
-							.get(positionAfter).getAverage(), i+2,
-							hashTagRankingList.get(positionAfter).getHashTag()
-									.getHashTag(), lastRankPosition);
-					tagRankingBeanList.add(ranking);
-				}
-			}
-		}
-		Collections.sort(tagRankingBeanList); 
-		return tagRankingBeanList;
-	}
-    
+                }
+            }
+        }
+        Collections.sort(tagRankingBeanList);
+        return tagRankingBeanList;
+    }
+
     /**
-     * 
+     *
      * @param id
      * @param average
      * @param position
      * @param lastPos
      * @return
      */
-	private HashTagRankingBean createHashTagRankingBean(final Long id,
-			final Double average, final Integer position, final String tagName,
-			final Integer lastPos) {
-		final HashTagRankingBean tagItemRanking = new HashTagRankingBean(); 
-		tagItemRanking.setPosition(position);
-		tagItemRanking.setTagName(tagName); 
-		tagItemRanking.setLastPosition(lastPos == null ? 0 : lastPos); 
-		return tagItemRanking;
-	}
+    private HashTagRankingBean createHashTagRankingBean(final Long id,
+            final Double average, final Integer position, final String tagName,
+            final Integer lastPos) {
+        final HashTagRankingBean tagItemRanking = new HashTagRankingBean();
+        tagItemRanking.setPosition(position);
+        tagItemRanking.setTagName(tagName);
+        tagItemRanking.setLastPosition(lastPos == null ? 0 : lastPos);
+        return tagItemRanking;
+    }
 
     /*
      * (non-Javadoc)
      * org.encuestame.core.service.imp.IFrontEndService#retrieveGenericStats
      * (java.lang.String, org.encuestame.utils.enums.TypeSearchResult)
      */
-	public GenericStatsBean retrieveGenericStats(final String itemId,
-			final TypeSearchResult itemType, HttpServletRequest request)
-			throws EnMeNoResultsFoundException {
-    	GenericStatsBean genericBean = new GenericStatsBean();
-    	long totalHits = 0L;
+    public GenericStatsBean retrieveGenericStats(final String itemId,
+            final TypeSearchResult itemType, HttpServletRequest request)
+            throws EnMeNoResultsFoundException {
+        GenericStatsBean genericBean = new GenericStatsBean();
+        long totalHits = 0L;
         String createdBy = " ";
         String createdAt = null;
         double average = 0;
         } else if (itemType.equals(TypeSearchResult.HASHTAG)) {
             final HashTag tag = getHashTagItem(itemId);
             totalHits = tag.getHits();
-            createdAt = convertRelativeTimeToString(tag.getUpdatedDate(), request);            
-            likeDislikeRate = 0L;                        
+            createdAt = convertRelativeTimeToString(tag.getUpdatedDate(), request);
+            likeDislikeRate = 0L;
             genericBean = ConvertDomainBean.createGenericStatsBean(likeDislikeRate, totalHits, null, average, createdAt);
         }
         return genericBean;
     }
- 
+
 
     /**
      * Get survey by id.
      * org.encuestame.core.service.imp.IFrontEndService#getTopRatedProfile(java
      * .lang.Boolean)
      */
-	public List<ProfileRatedTopBean> getTopRatedProfile(final Boolean status)
-			throws EnMeNoResultsFoundException {
-		Long topValue = 0L;
-		Long totalPublications;
-		Long publishedTweetPolls;
-		Long publishedPolls;
-
-		final List<ProfileRatedTopBean> profileItems = new ArrayList<ProfileRatedTopBean>();
-
-		final List<UserAccount> users = getSecurityService()
-				.getUserAccountsAvailable(status);
-
-		for (UserAccount userAccount : users) {
-			publishedTweetPolls = this.getTotalTweetPollPublished(userAccount,
-					status);
-
-			publishedPolls = this.getTotalPollPublished(userAccount, status);
-			totalPublications = publishedTweetPolls + publishedPolls;
-			topValue = topValue + totalPublications;
-			profileItems.add(this.createProfileTopBean(0, 0L, 0L, 0, topValue,
-					totalPublications, "myurl", userAccount.getUsername()));
-		}
-		Collections.sort(profileItems);
-		return profileItems;
-	}
-
-	/**
-	 * Create {@link ProfileRatedTopBean}.
-	 * @param currentPos
-	 * @param dislike
-	 * @param likeVotes
-	 * @param lastPos
-	 * @param topValue
-	 * @param total
-	 * @param url
-	 * @param username
-	 * @return
-	 */
-	private ProfileRatedTopBean createProfileTopBean(final Integer currentPos,
-			final Long dislike, final Long likeVotes, final Integer lastPos,
-			final Long topValue, final Long total, final String url, final String username) {
-		ProfileRatedTopBean profile = new ProfileRatedTopBean();
-		profile.setCurrentPos(currentPos);
-		profile.setDisLikeVotes(dislike);
-		profile.setLastPos(lastPos);
-		profile.setLikeVotes(likeVotes);
-		profile.setTopValue(topValue);
-		profile.setTotalbyItems(total);
-		profile.setUrl(url);
-		profile.setUsername(username);
-
-		return profile;
-
-	}
-    
+    public List<ProfileRatedTopBean> getTopRatedProfile(final Boolean status)
+            throws EnMeNoResultsFoundException {
+        Long topValue = 0L;
+        Long totalPublications;
+        Long publishedTweetPolls;
+        Long publishedPolls;
+
+        final List<ProfileRatedTopBean> profileItems = new ArrayList<ProfileRatedTopBean>();
+
+        final List<UserAccount> users = getSecurityService()
+                .getUserAccountsAvailable(status);
+
+        for (UserAccount userAccount : users) {
+            publishedTweetPolls = this.getTotalTweetPollPublished(userAccount,
+                    status);
+
+            publishedPolls = this.getTotalPollPublished(userAccount, status);
+            totalPublications = publishedTweetPolls + publishedPolls;
+            topValue = topValue + totalPublications;
+            profileItems.add(this.createProfileTopBean(0, 0L, 0L, 0, topValue,
+                    totalPublications, "myurl", userAccount.getUsername()));
+        }
+        Collections.sort(profileItems);
+        return profileItems;
+    }
+
+    /**
+     * Create {@link ProfileRatedTopBean}.
+     * @param currentPos
+     * @param dislike
+     * @param likeVotes
+     * @param lastPos
+     * @param topValue
+     * @param total
+     * @param url
+     * @param username
+     * @return
+     */
+    private ProfileRatedTopBean createProfileTopBean(final Integer currentPos,
+            final Long dislike, final Long likeVotes, final Integer lastPos,
+            final Long topValue, final Long total, final String url, final String username) {
+        ProfileRatedTopBean profile = new ProfileRatedTopBean();
+        profile.setCurrentPos(currentPos);
+        profile.setDisLikeVotes(dislike);
+        profile.setLastPos(lastPos);
+        profile.setLikeVotes(likeVotes);
+        profile.setTopValue(topValue);
+        profile.setTotalbyItems(total);
+        profile.setUrl(url);
+        profile.setUsername(username);
+
+        return profile;
+
+    }
+
     private Long getTotalPollPublished(final UserAccount user, final Boolean status){
-    	  final Long totalPollPublished;
-    	  totalPollPublished = getPollDao().getTotalPollsbyUser(user, status);
-    	return totalPollPublished;
+          final Long totalPollPublished;
+          totalPollPublished = getPollDao().getTotalPollsbyUser(user, status);
+        return totalPollPublished;
     }
-    
+
     /**
      * Retrieve total tweetpolls published by user.
      * @param user
      * @param status
      * @return
      */
-	private Long getTotalTweetPollPublished(final UserAccount user,
-			final Boolean status) {
-		final Long totalTweetPollPublished;
-		totalTweetPollPublished = getTweetPollDao().getTotalTweetPoll(user,
-				status);
-		log.debug("total tweetPolss published by -->" + totalTweetPollPublished);
-		return totalTweetPollPublished;
-	}
+    private Long getTotalTweetPollPublished(final UserAccount user,
+            final Boolean status) {
+        final Long totalTweetPollPublished;
+        totalTweetPollPublished = getTweetPollDao().getTotalTweetPoll(user,
+                status);
+        log.trace("total tweetPolss published by -->" + totalTweetPollPublished);
+        return totalTweetPollPublished;
+    }
 
     /*
      * (non-Javadoc)
      */
     public void getTotalUsagebyHashTagAndDateRange() {}
 
-   
-  
+
+
 
     /**
      * @return the tweetPollService
      */
     public void setSecurityService(SecurityOperations securityService) {
         this.securityService = securityService;
-    } 
- 
+    }
+
 }

enme-business/src/main/java/org/encuestame/business/service/PictureService.java

      * @throws EnMeGenericException
      */
     private byte[] getGravatarPicture(final String email, final PictureType size) throws EnMeGenericException {
-        log.debug("getGravatarPicture:{ "+size);
-        log.debug("getGravatarPicture:{ "+email);
+        log.trace("getGravatarPicture:{ "+size);
+        log.trace("getGravatarPicture:{ "+email);
         return PictureUtils.downloadGravatar(email, size.toInt());
     }
 
      * @throws EnMeGenericException
      */
     public byte[] getProfilePicture(final String username, final PictureType pictureType) throws IOException, EnMeGenericException {
-        log.debug("getProfilePicture "+username);
-        log.debug("getProfilePicture "+pictureType.toString());
+        log.trace("getProfilePicture "+username);
+        log.trace("getProfilePicture "+pictureType.toString());
         final UserAccount user = getUserAccount(username);
         if (user.getPictureSource().equals(PictureSource.UPLOADED)) {
             return this.getProfilePicture(pictureType, user);

enme-js/resources-enme-war/src/main/resources/resource/js/me/web/widget/rated/RatedOperations.js

     */
    _key : null,
 
+   /**
+    * A items print counter.
+    * @property items
+    */
+   items : 0,
+
+   /**
+    * Clean the main node before load the service.
+    * @property
+    */
+   clean_after_reload : true,
+
    /*
     * print items.
     */
    _print : function(items) {
       if ( typeof(items) == 'object' ) {
+          this.items += items.length;
           dojo.forEach(items, dojo.hitch(this,function(item) {
             this._item_store.appendChild(this._createItem(item));
           }));
          var load = dojo.hitch(this, function(data) {
              if (this._key != null) {
                  this._items = data.success[this._key];
-                 dojo.empty(this._item_store);
+                 if (this.clean_after_reload) {
+                   dojo.empty(this._item_store);
+                  }
                  this._print(this._items);
              }
          });
          var error = function(error) {
              this.errorMesage(error);
          };
-//         /encuestame.service.xhrGet(this.getURLService().service(this.service), this.getParams(), load, error);
          this.getURLService().get(this.service, this.getParams(), load, error , dojo.hitch(this, function() {
 
          }));

enme-js/resources-enme-war/src/main/resources/resource/js/me/web/widget/rated/RatedProfile.js

      "me/web/widget/rated/Comment",
      "me/web/widget/rated/RatedOperations",
      "me/web/widget/rated/UsersProfile",
+     "me/web/widget/ui/More",
      "me/core/enme",
      "dojo/text!me/web/widget/rated/templates/profile-rate.html" ],
     function(
     comment,
     ratedOperations,
     userProfile,
+    More,
     _ENME,
      template) {
 
   return declare([ _WidgetBase, _TemplatedMixin, ratedOperations,  main_widget, _WidgetsInTemplateMixin], {
 
-      // template string.
-      templateString : template,
+     // template string.
+     templateString : template,
+
+     /**
+      *
+      * @property
+      */
+     _params : {
+        status : true
+     },
 
       /*
       *
       */
      _key : ["profile"],
 
+
+     clean_after_reload : false,
+
     /*
      *
      */
     postCreate : function() {
+      this.more = new More({
+           parentWidget : this
+      });
+
+      var parent = this;
+      this.more.loadItems = dojo.hitch(this, function () {
+          parent._loadItems();
+      });
+      // if more
+      if(this._more) {
+        this._more.appendChild(this.more.domNode);
+      }
+      // if service exist, load items.
       if (this.service != null) {
           this._loadItems();
       }
           return widget.domNode;
       },
 
-      /*
-       * comment params.
+      /**
+       * Return a list of service parameters.
+       * @method getParams
        */
       getParams : function() {
-          return { status : true };
+          return this.more.merge(this._params);
       }
   });
 });

enme-js/resources-enme-war/src/main/resources/resource/js/me/web/widget/rated/templates/profile-rate.html

 <section class="web-rated-comments">
     <div class="web-rated-comments-items" data-dojo-attach-point="_item_store"></div>
+    <div class="web-rated-comments-more" data-dojo-attach-point="_more"></div>
 </section>

enme-js/resources-enme-war/src/main/resources/resource/js/me/web/widget/ui/More.js

  *  @namespace Widget
  *  @class More
  */
-define([ "dojo/_base/declare",
+define([
+    "dojo/_base/declare",
+    "dojo/_base/lang",
     "dijit/_WidgetBase",
     "dijit/_TemplatedMixin",
     "dijit/_WidgetsInTemplateMixin",
     "me/core/main_widgets/EnmeMainLayoutWidget",
     "me/core/enme",
-    "dojo/text!me/web/widget/ui/templates/more.html" ], function(declare,
-    _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, main_widget,
-    _ENME, template) {
-  return declare([ _WidgetBase, _TemplatedMixin, main_widget,
-      _WidgetsInTemplateMixin ], {
+    "dojo/text!me/web/widget/ui/templates/more.html" ], function(
+      declare,
+      lang,
+      _WidgetBase,
+      _TemplatedMixin,
+      _WidgetsInTemplateMixin,
+      main_widget,
+      _ENME,
+      template) {
+  return declare([ _WidgetBase,
+                   _TemplatedMixin,
+                    main_widget,
+                   _WidgetsInTemplateMixin ], {
 
-    // template string.
+    /**
+     * template string.
+     * @property templateString
+     */
     templateString : template,
 
-    /*
+    /**
      *
+     * @property pagination
      */
     pagination : {
-      _maxResults : 0,
-      _start : 0
+       end : 10,
+       start : 0
+    },
+
+    more_max : 5,
+
+
+    parentWidget : 0,
+
+    /**
+     * Merge external object with more pagination
+     * @property
+     */
+    merge : function (params) {
+      return lang.mixin(this.pagination, params);
     },
 
-    /*
+    /**
      *
+     * @property
      */
     postCreate : function() {
-      dojo.connect(this._stream, "onclick", dojo.hitch(this, function(
-          event) {
+      dojo.connect(this._stream, "onclick", dojo.hitch(this, function(event) {
         if (dojo.isFunction(this.loadItems)) {
-          this.loadItems();
-          this.pagination._start = this.pagination._start
-              + this.pagination._maxResults;
+           this.pagination.start = this.parentWidget.items;
+           this.pagination.end = this.pagination.start + this.more_max;
+           this.loadItems();
+           this.pagination.start = this.pagination.start + this.pagination.end;
         }
       }));
     },
 
+
+
     /**
      *
      */
     loadItems : function() {
-
+        // override method
     },
 
     /**

enme-js/resources-enme-war/src/main/resources/resource/js/me/web/widget/ui/templates/more.html

 <div class="web-list-more">
     <div class="pagination" data-dojo-attach-point="_pagination">
-        <div data-dojo-attach-point="_stream" class="titleNext"> More</div>
+        <div data-dojo-attach-point="_stream" class="titleNext">
+        	 More
+        </div>
     </div>
 </div>

enme-mvc/src/main/java/org/encuestame/mvc/controller/json/FrontEndJsonController.java

 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.log4j.Logger;
+import org.apache.commons.collections.ListUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.codehaus.jackson.JsonGenerationException;
 import org.codehaus.jackson.map.JsonMappingException;
 import org.encuestame.core.config.EnMePlaceHolderConfigurer;
 
 
     /** Log. **/
-    private Logger log = Logger.getLogger(this.getClass());
+    private Log log = LogFactory.getLog(this.getClass());
 
     /**
      * Get frontend items.
                 throw new EnMeSearchException("search params required.");
             } else {
                 List<ProfileRatedTopBean> itemList = getFrontService().getTopRatedProfile(status);
-                if (start != null && end != null && start < end && end <= itemList.size()) {
-                    itemList = itemList.subList(start, end);
-                } else if(start != null && end == null) {
-                     itemList = itemList.subList(start, itemList.size());
+                log.debug("topppp user getTopRatedProfile1 "+itemList.size());
+                log.debug("topppp user start < end2 "+(start < end));
+                log.debug("topppp user start < end3 "+(end <= itemList.size()));
+                log.debug("topppp user start < end4 "+(start < itemList.size()));
+                if (start != null && end != null && start < end) {
+                    if (end <= itemList.size()) {
+                        itemList = itemList.subList(start, end);
+                        log.debug("topppp user 111");
+                    } else if (start <= itemList.size()) {
+                        itemList = itemList.subList(start, itemList.size());
+                    } else if (start > itemList.size()) {
+                        itemList = ListUtils.EMPTY_LIST;
+                        log.debug("topppp user 3333");
+                    } else {
+                        log.debug("topppp user 4444");
+                    }
                 }
                 jsonResponse.put("profile", itemList);
                 setItemResponse(jsonResponse);

enme-persistence/enme-dao/src/main/java/org/encuestame/persistence/dao/imp/AccountDaoImp.java

          final List list =  getHibernateTemplate().findByNamedParam("select count(*) from UserAccount "
                  +" WHERE account = :account", "account", account);
          if (list.get(0) instanceof Long){
-             log.debug("instace of Long");
+             log.trace("instace of Long");
              resultsSize = (Long) list.get(0);
          }
          return resultsSize;
      */
     //@Cacheable(cacheName = "userByUsername")
     public final UserAccount getUserByUsername(final String username)throws HibernateException {
-        log.debug("getUserByUsername by :{"+username);
+        log.trace("getUserByUsername by :{"+username);
         final DetachedCriteria criteria = DetachedCriteria.forClass(UserAccount.class);
         criteria.add(Restrictions.eq("username", username));
         getHibernateTemplate().setQueryCacheRegion("query.user.by.username");

enme-persistence/enme-dao/src/main/java/org/encuestame/persistence/dao/imp/PollDao.java

      */
     @SuppressWarnings("unchecked")
     public List<Poll> getPollByHashTagName(
-    		final String tagName,
-    		final Integer startResults,
+            final String tagName,
+            final Integer startResults,
             final Integer limitResults,
             final TypeSearchResult filterby,
             final SearchPeriods searchPeriods) {
      * (non-Javadoc)
      * @see org.encuestame.persistence.dao.IPoll#retrievePollResults(org.encuestame.persistence.domain.survey.Poll)
      */
-	@SuppressWarnings("unchecked")
-	public List<PollResult> retrievePollResults(final Poll poll) {
-		final DetachedCriteria criteria = DetachedCriteria
-				.forClass(PollResult.class);
-		criteria.add(Restrictions.eq("poll", poll));
-		return getHibernateTemplate().findByCriteria(criteria);
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * @see org.encuestame.persistence.dao.IPoll#getTotalVotesByPollIdAndDateRange(java.lang.Long, org.encuestame.utils.enums.SearchPeriods)
-	 */
-	public Long getTotalVotesByPollIdAndDateRange(final Long pollId,
-			final SearchPeriods period) {
-		final DetachedCriteria criteria = DetachedCriteria
-				.forClass(PollResult.class);
-		criteria.setProjection(Projections.rowCount());
-		criteria.add(Restrictions.eq("poll.pollId", pollId));
-		calculateSearchPeriodsDates(period, criteria, "votationDate");
-		@SuppressWarnings("unchecked")
-		List<Long> results = getHibernateTemplate().findByCriteria(criteria);
-
-		return (Long) (results.get(0) == null ? 0 : results.get(0));
-	}
+    @SuppressWarnings("unchecked")
+    public List<PollResult> retrievePollResults(final Poll poll) {
+        final DetachedCriteria criteria = DetachedCriteria
+                .forClass(PollResult.class);
+        criteria.add(Restrictions.eq("poll", poll));
+        return getHibernateTemplate().findByCriteria(criteria);
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.encuestame.persistence.dao.IPoll#getTotalVotesByPollIdAndDateRange(java.lang.Long, org.encuestame.utils.enums.SearchPeriods)
+     */
+    public Long getTotalVotesByPollIdAndDateRange(final Long pollId,
+            final SearchPeriods period) {
+        final DetachedCriteria criteria = DetachedCriteria
+                .forClass(PollResult.class);
+        criteria.setProjection(Projections.rowCount());
+        criteria.add(Restrictions.eq("poll.pollId", pollId));
+        calculateSearchPeriodsDates(period, criteria, "votationDate");
+        @SuppressWarnings("unchecked")
+        List<Long> results = getHibernateTemplate().findByCriteria(criteria);
+
+        return (Long) (results.get(0) == null ? 0 : results.get(0));
+    }
 
      /*
       * (non-Javadoc)
      */
     @SuppressWarnings("unchecked")
     public List<Poll> getPollByUserIdDate(
-    		final Date date,
-    		final UserAccount userAcc,
+            final Date date,
+            final UserAccount userAcc,
             final Integer maxResults,
             final Integer start ){
         final DetachedCriteria criteria = DetachedCriteria.forClass(Poll.class);
         criteria.add(Restrictions.eq("editorOwner", userAcc));
         if ( date != null) {
-        	criteria.add(Restrictions.between("createdAt", date, getNextDayMidnightDate()));
+            criteria.add(Restrictions.between("createdAt", date, getNextDayMidnightDate()));
         }
         return (List<Poll>) filterByMaxorStart(criteria, maxResults, start);
     }
         criteria.add(Restrictions.eq("publish", publishStatus));
         @SuppressWarnings("unchecked")
         List<Long> results = getHibernateTemplate().findByCriteria(criteria);
-        log.debug("Retrieve total polls by  " + user.getUsername() + "--->"
+        log.trace("Retrieve total polls by  " + user.getUsername() + "--->"
                 + results.size());
         return (Long) (results.get(0) == null ? 0 : results.get(0));
     }
      */
     @SuppressWarnings("unchecked")
     public PollResult validateVoteIP(
-    		final String ip,
+            final String ip,
             final Poll poll) {
         return (PollResult) DataAccessUtils
                 .uniqueResult(getHibernateTemplate()
     }
 
     @SuppressWarnings("unchecked")
-	public Poll getPollbyQuestion(final Long questionId){
-    	final DetachedCriteria criteria = DetachedCriteria.forClass(Poll.class);
-    	criteria.createAlias("question", "question");
-    	criteria.add(Restrictions.eq("question", questionId));
-    	return (Poll) DataAccessUtils.uniqueResult(getHibernateTemplate().findByCriteria(criteria));
+    public Poll getPollbyQuestion(final Long questionId){
+        final DetachedCriteria criteria = DetachedCriteria.forClass(Poll.class);
+        criteria.createAlias("question", "question");
+        criteria.add(Restrictions.eq("question", questionId));
+        return (Poll) DataAccessUtils.uniqueResult(getHibernateTemplate().findByCriteria(criteria));
     }
 
     /**
     */
    public List<Object[]> retrieveResultPollsbyAnswer(final Long pollId,
            final Long answerId) {
-   	final String pollResultsCounter = "select answer.questionAnswerId, answer.answer, answer.color,"
+       final String pollResultsCounter = "select answer.questionAnswerId, answer.answer, answer.color,"
                + "count(poll.pollId) FROM PollResult "
                + "where poll.pollId= :pollId AND answer.questionAnswerId= :answerId "
                + "group by answer.answer, answer.questionAnswerId, answer.color";

enme-persistence/enme-dao/src/main/java/org/encuestame/persistence/dao/imp/TweetPollDao.java

             final Boolean isCompleted, final Boolean isScheduled,
             final Boolean isFavourite, final Boolean isPublished,
             final String keyword, final String period) {
-     	 final Date initDate = DateUtil.decreaseDateAsWeek(Calendar.getInstance().getTime());
-    	 return retrieveTweetPollByDate(account,
+          final Date initDate = DateUtil.decreaseDateAsWeek(Calendar.getInstance().getTime());
+         return retrieveTweetPollByDate(account,
                 maxResults, start, isCompleted, isScheduled, isFavourite,
                 isPublished, keyword, period, initDate);
     }
         criteria.add(Restrictions.eq("publishTweetPoll", publishTweetPoll));
         @SuppressWarnings("unchecked")
         List<Long> results = getHibernateTemplate().findByCriteria(criteria);
-        log.debug("Retrieve total tweetPolls by  " + user.getUsername()
+        log.trace("Retrieve total tweetPolls by  " + user.getUsername()
                 + "--->" + results.size());
         return (Long) (results.get(0) == null ? 0 : results.get(0));
     }

enme-utils/src/main/java/org/encuestame/utils/web/ProfileRatedTopBean.java

     private String username;
 
     /** **/
-    private Long topValue; 
-    
+    private Long topValue;
+
     /** **/
     private Long totalbyItems;
-    
+
     /** **/
     private String url;
-    
+
     /** **/
     private Long likeVotes;
-    
+
     /** **/
     private Long disLikeVotes;
-    
+
     /** **/
     private Integer currentPos;
-    
+
     /** **/
     private Integer lastPos;
-    
+
 
     /**
      * @return the username
         this.topValue = topValue;
     }
 
-    
-    /**
-	 * @return the totalbyItems
-	 */
-	public Long getTotalbyItems() {
-		return totalbyItems;
-	}
-
-	/**
-	 * @param totalbyItems the totalbyItems to set
-	 */
-	public void setTotalbyItems(Long totalbyItems) {
-		this.totalbyItems = totalbyItems;
-	} 
-	
-	/**
-	 * @return the url
-	 */
-	public String getUrl() {
-		return url;
-	}
-
-	/**
-	 * @param url the url to set
-	 */
-	public void setUrl(final String url) {
-		this.url = url;
-	}
-
-	/**
-	 * @return the likeVotes
-	 */
-	public Long getLikeVotes() {
-		return likeVotes;
-	}
-
-	/**
-	 * @param likeVotes the likeVotes to set
-	 */
-	public void setLikeVotes(final Long likeVotes) {
-		this.likeVotes = likeVotes;
-	}
-
-	/**
-	 * @return the disLikeVotes
-	 */
-	public Long getDisLikeVotes() {
-		return disLikeVotes;
-	}
-
-	/**
-	 * @param disLikeVotes the disLikeVotes to set
-	 */
-	public void setDisLikeVotes(final Long disLikeVotes) {
-		this.disLikeVotes = disLikeVotes;
-	}
-
-	/**
-	 * @return the currentPos
-	 */
-	public Integer getCurrentPos() {
-		return currentPos;
-	}
-
-	/**
-	 * @param currentPos the currentPos to set
-	 */
-	public void setCurrentPos(final Integer currentPos) {
-		this.currentPos = currentPos;
-	}
-
-	/**
-	 * @return the lastPos
-	 */
-	public Integer getLastPos() {
-		return lastPos;
-	}
-
-	/**
-	 * @param lastPos the lastPos to set
-	 */
-	public void setLastPos(final Integer lastPos) {
-		this.lastPos = lastPos;
-	}
-
-	public int compareTo(Object o) {
+
+    /**
+     * @return the totalbyItems
+     */
+    public Long getTotalbyItems() {
+        return totalbyItems;
+    }
+
+    /**
+     * @param totalbyItems the totalbyItems to set
+     */
+    public void setTotalbyItems(Long totalbyItems) {
+        this.totalbyItems = totalbyItems;
+    }
+
+    /**
+     * @return the url
+     */
+    public String getUrl() {
+        return url;
+    }
+
+    /**
+     * @param url the url to set
+     */
+    public void setUrl(final String url) {
+        this.url = url;
+    }
+
+    /**
+     * @return the likeVotes
+     */
+    public Long getLikeVotes() {
+        return likeVotes;
+    }
+
+    /**
+     * @param likeVotes the likeVotes to set
+     */
+    public void setLikeVotes(final Long likeVotes) {
+        this.likeVotes = likeVotes;
+    }
+
+    /**
+     * @return the disLikeVotes
+     */
+    public Long getDisLikeVotes() {
+        return disLikeVotes;
+    }
+
+    /**
+     * @param disLikeVotes the disLikeVotes to set
+     */
+    public void setDisLikeVotes(final Long disLikeVotes) {
+        this.disLikeVotes = disLikeVotes;
+    }
+
+    /**
+     * @return the currentPos
+     */
+    public Integer getCurrentPos() {
+        return currentPos;
+    }
+
+    /**
+     * @param currentPos the currentPos to set
+     */
+    public void setCurrentPos(final Integer currentPos) {
+        this.currentPos = currentPos;
+    }
+
+    /**
+     * @return the lastPos
+     */
+    public Integer getLastPos() {
+        return lastPos;
+    }
+
+    /**
+     * @param lastPos the lastPos to set
+     */
+    public void setLastPos(final Integer lastPos) {
+        this.lastPos = lastPos;
+    }
+
+    public int compareTo(Object o) {
         ProfileRatedTopBean profile = (ProfileRatedTopBean) o;
-        log.debug("Profile Value: " + profile.getTopValue());
-        log.debug("This profile Value: " + this.getTopValue());
         int CompareToValue = Float.compare(profile.getTopValue() == null ? 0
                 : profile.getTopValue(),
                 this.getTopValue() == null ? 0 : this.getTopValue());
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.