Commits

Juan Carlos Picado Herrera committed 706a085 Merge

Merge branch 'development', remote-tracking branch 'origin' into juanpicado

Comments (0)

Files changed (84)

encuestame-business/src/main/java/org/encuestame/business/service/AbstractBaseService.java

 import java.io.File;
 import java.util.Calendar;
 import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Locale;
+import java.util.Map;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.encuestame.business.service.imp.MailServiceOperations;
 import org.encuestame.business.setup.DirectorySetupOperations;
 import org.encuestame.core.util.ConvertDomainBean;
-import org.encuestame.core.util.MD5Utils;
 import org.encuestame.persistence.domain.Email;
 import org.encuestame.persistence.domain.EmailList;
 import org.encuestame.persistence.domain.EmailSubscribe;
 import org.encuestame.persistence.domain.security.UserAccount;
 import org.encuestame.persistence.exception.EnMeExpcetion;
 import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
+import org.encuestame.utils.DateUtil;
+import org.encuestame.utils.MD5Utils;
+import org.encuestame.utils.RelativeTimeEnum;
+import org.encuestame.utils.web.TweetPollBean;
 import org.encuestame.utils.web.UnitEmails;
 import org.encuestame.utils.web.UnitLists;
 import org.encuestame.utils.web.UserAccountBean;
 import org.hibernate.HibernateException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.web.servlet.support.RequestContextUtils;
 
 import twitter4j.Twitter;
 import twitter4j.TwitterException;
      */
     public AbstractBaseService() {}
 
+
+
+    /**
+     *
+     * @param tpbean
+     * @param request
+     */
+    public TweetPollBean  convertTweetPollRelativeTime(final TweetPollBean tpbean, final HttpServletRequest request){
+        final HashMap<Integer, RelativeTimeEnum> relativeTime =  DateUtil.getRelativeTime(tpbean.getCreatedDateAt());
+        final Iterator it = relativeTime.entrySet().iterator();
+        while (it.hasNext()) {
+            final Map.Entry<Integer, RelativeTimeEnum> e = (Map.Entry<Integer, RelativeTimeEnum>)it.next();
+            log.debug("--"+e.getKey() + "**" + e.getValue());
+            tpbean.setRelativeTime(convertRelativeTimeMessage(e.getValue(), e.getKey(), request));
+        }
+        return tpbean;
+    }
+
+    /**
+     * Convert Relative Time Message.
+     * @param relativeTimeEnum
+     * @param number
+     * @param request
+     * @param objects
+     * @return
+     */
+    public String convertRelativeTimeMessage(
+            final RelativeTimeEnum relativeTimeEnum,
+            final Integer number,
+            final HttpServletRequest request){
+        final StringBuilder builder = new StringBuilder();
+        //builder.append(number);
+        //builder.append(" ");
+        log.debug("Convert Message Relative Time");
+        log.debug("Relative ENUM -->"+relativeTimeEnum);
+        log.debug("NUMBER -->"+number);
+        String str[] = {number.toString()};
+        if (relativeTimeEnum.equals(RelativeTimeEnum.ONE_SECOND_AGO)) {
+            builder.append(getMessage("relative.time.one.second.ago", request, str));
+        } else if(relativeTimeEnum.equals(RelativeTimeEnum.SECONDS_AGO)) {
+            builder.append(getMessage("relative.time.one.seconds.ago", request, str));
+        } else if(relativeTimeEnum.equals(RelativeTimeEnum.A_MINUTE_AGO)) {
+            builder.append(getMessage("relative.time.one.minute.ago", request, str));
+        } else if(relativeTimeEnum.equals(RelativeTimeEnum.MINUTES_AGO)) {
+            builder.append(getMessage("relative.time.one.minutes.ago", request, str));
+        } else if(relativeTimeEnum.equals(RelativeTimeEnum.AN_HOUR_AGO)) {
+            builder.append(getMessage("relative.time.one.hour.ago", request, str));
+        } else if(relativeTimeEnum.equals(RelativeTimeEnum.HOURS_AGO)) {
+            builder.append(getMessage("relative.time.one.hours.ago", request, str));
+        } else if(relativeTimeEnum.equals(RelativeTimeEnum.MONTHS_AGO)) {
+            builder.append(getMessage("relative.time.one.months.ago", request, str));
+        } else if(relativeTimeEnum.equals(RelativeTimeEnum.ONE_MONTH_AGO)) {
+            builder.append(getMessage("relative.time.one.month.ago", request, str));
+        } else if(relativeTimeEnum.equals(RelativeTimeEnum.ONE_YEAR_AGO)) {
+            builder.append(getMessage("relative.time.one.year.ago", request, str));
+        } else if(relativeTimeEnum.equals(RelativeTimeEnum.YEARS_AGO)) {
+            builder.append(getMessage("relative.time.one.years.ago", request, str));
+        }
+        return builder.toString();
+    }
+
     /**
      * Getter.
      * @return {@link MessageSourceFactoryBean}
                 .getMessage(propertieId, null, null);
     }
 
+    private Locale getLocale(final HttpServletRequest request){
+        return RequestContextUtils.getLocale(request);
+    }
+
+    public String getMessage(final String message,
+            final HttpServletRequest request, Object[] args) {
+        String stringValue = "";
+        try {
+            stringValue = getMessageSourceFactoryBean().getMessage(
+                    message, args, getLocale(request));
+        } catch (Exception e) {
+            log.error(e);
+            e.printStackTrace(); //TODO: ENCUESTAME-223 - OPEN
+        }
+        return stringValue;
+    }
+
     /**
      * Create Email List.
      * @param unitLists

encuestame-business/src/main/java/org/encuestame/business/service/AbstractSurveyService.java

 import org.encuestame.core.social.LinkedInAPIOperations;
 import org.encuestame.core.util.ConvertDomainBean;
 import org.encuestame.core.util.InternetUtils;
-import org.encuestame.core.util.MD5Utils;
 import org.encuestame.core.util.SocialUtils;
 import org.encuestame.persistence.dao.IHashTagDao;
 import org.encuestame.persistence.dao.ITweetPoll;
 import org.encuestame.persistence.exception.EnMeExpcetion;
 import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
 import org.encuestame.persistence.exception.EnmeFailOperation;
+import org.encuestame.utils.MD5Utils;
 import org.encuestame.utils.RestFullUtil;
 import org.encuestame.utils.ShortUrlProvider;
 import org.encuestame.utils.TweetPublishedMetadata;

encuestame-business/src/main/java/org/encuestame/business/service/FrontEndService.java

 package org.encuestame.business.service;
 
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 
+import javax.servlet.http.HttpServletRequest;
+
 import org.apache.log4j.Logger;
 import org.encuestame.business.service.imp.IFrontEndService;
 import org.encuestame.core.util.ConvertDomainBean;
 import org.encuestame.persistence.domain.tweetpoll.TweetPoll;
 import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
 import org.encuestame.persistence.exception.EnMeSearchException;
-import org.encuestame.utils.DateUtil;
-import org.encuestame.utils.RelativeTimeEnum;
 import org.encuestame.utils.web.HashTagBean;
 import org.encuestame.utils.web.TweetPollBean;
 import org.encuestame.utils.web.UnitPoll;
      */
     public List<TweetPollBean> searchItemsByTweetPoll(
                 final String period,
-                Integer maxResults)
+                final Integer start,
+                Integer maxResults,
+                final HttpServletRequest request)
                 throws EnMeSearchException{
         final List<TweetPollBean> results = new ArrayList<TweetPollBean>();
         if(maxResults == null){
         }
         log.debug("Max Results "+maxResults);
         final List<TweetPoll> items = new ArrayList<TweetPoll>();
-        if(period == null ){
+        if (period == null ) {
             throw new EnMeSearchException("search params required.");
         } else {
             final SearchPeriods periodSelected = SearchPeriods.getPeriodString(period);
             if(periodSelected.equals(SearchPeriods.TWENTYFOURHOURS)){
-                items.addAll(getFrontEndDao().getTweetPollFrontEndLast24(maxResults));
+                items.addAll(getFrontEndDao().getTweetPollFrontEndLast24(start, maxResults));
             } else if(periodSelected.equals(SearchPeriods.TWENTYFOURHOURS)){
-                items.addAll(getFrontEndDao().getTweetPollFrontEndLast24(maxResults));
+                items.addAll(getFrontEndDao().getTweetPollFrontEndLast24(start, maxResults));
             } else if(periodSelected.equals(SearchPeriods.SEVENDAYS)){
-                items.addAll(getFrontEndDao().getTweetPollFrontEndLast7Days(maxResults));
+                items.addAll(getFrontEndDao().getTweetPollFrontEndLast7Days(start, maxResults));
             } else if(periodSelected.equals(SearchPeriods.THIRTYDAYS)){
-                items.addAll(getFrontEndDao().getTweetPollFrontEndLast30Days(maxResults));
+                items.addAll(getFrontEndDao().getTweetPollFrontEndLast30Days(start, maxResults));
             } else if(periodSelected.equals(SearchPeriods.ALLTIME)){
-                items.addAll(getFrontEndDao().getTweetPollFrontEndAllTime(maxResults));
+                items.addAll(getFrontEndDao().getTweetPollFrontEndAllTime(start, maxResults));
             }
             log.debug("TweetPoll "+items.size());
             results.addAll(ConvertDomainBean.convertListToTweetPollBean(items));
+            for (TweetPollBean tweetPoll : results) {
+                tweetPoll = convertTweetPollRelativeTime(tweetPoll, request);
+            }
+
         }
         return results;
     }
      */
     public List<UnitPoll> searchItemsByPoll(
             final String period,
+            final Integer start,
             Integer maxResults)
             throws EnMeSearchException{
     final List<UnitPoll> results = new ArrayList<UnitPoll>();
     } else {
         final SearchPeriods periodSelected = SearchPeriods.getPeriodString(period);
         if(periodSelected.equals(SearchPeriods.TWENTYFOURHOURS)){
-            items.addAll(getFrontEndDao().getPollFrontEndLast24(maxResults));
+            items.addAll(getFrontEndDao().getPollFrontEndLast24(start, maxResults));
         } else if(periodSelected.equals(SearchPeriods.TWENTYFOURHOURS)){
-            items.addAll(getFrontEndDao().getPollFrontEndLast24(maxResults));
+            items.addAll(getFrontEndDao().getPollFrontEndLast24(start, maxResults));
         } else if(periodSelected.equals(SearchPeriods.SEVENDAYS)){
-            items.addAll(getFrontEndDao().getPollFrontEndLast7Days(maxResults));
+            items.addAll(getFrontEndDao().getPollFrontEndLast7Days(start, maxResults));
         } else if(periodSelected.equals(SearchPeriods.THIRTYDAYS)){
-            items.addAll(getFrontEndDao().getPollFrontEndLast30Days(maxResults));
+            items.addAll(getFrontEndDao().getPollFrontEndLast30Days(start, maxResults));
         } else if(periodSelected.equals(SearchPeriods.ALLTIME)){
-            items.addAll(getFrontEndDao().getPollFrontEndAllTime(maxResults));
+            items.addAll(getFrontEndDao().getPollFrontEndAllTime(start, maxResults));
         }
         log.debug("Poll "+items.size());
         results.addAll(ConvertDomainBean.convertListToPollBean((items)));
      */
     public List<HashTagBean> getHashTags(
               Integer maxResults,
-              final Integer start){
+              final Integer start,
+              final String tagCriteria){
         final List<HashTagBean> hashBean = new ArrayList<HashTagBean>();
         if(maxResults == null){
             maxResults = this.MAX_RESULTS;
         }
         log.debug("Max Results HashTag -----> "+maxResults);
         List<HashTag> tags = new ArrayList<HashTag>();
-        tags.addAll(getHashTagDao().getHashTags(maxResults, start));
+        tags.addAll(getHashTagDao().getHashTags(maxResults, start, tagCriteria));
         log.debug("Hashtag total size ---> "+tags.size());
         hashBean.addAll(ConvertDomainBean.convertListHashTagsToBean(tags));
+
         return hashBean;
     }
 
      * @return
      */
     @SuppressWarnings("unchecked")
-    public List<TweetPollBean> getTweetPollsbyHashTagId(final Long hashTagId, final Integer limit){
-        String relativeTime;
-        final List<TweetPoll> tweetPolls = getTweetPollDao().getTweetpollByHashTagId(hashTagId, limit);
+    public List<TweetPollBean> getTweetPollsbyHashTagId(
+            final Long hashTagId,
+            final Integer limit,
+            final String filter,
+            final HttpServletRequest request){
+        final List<TweetPoll> tweetPolls = getTweetPollDao().getTweetpollByHashTagId(hashTagId, limit, filter);
         log.debug("TweetPoll by HashTagId total size ---> "+tweetPolls.size());
         final List<TweetPollBean> tweetPollBean = ConvertDomainBean.convertListToTweetPollBean(tweetPolls);
-        for (TweetPollBean tweetPollBean2 : tweetPollBean) {
-            relativeTime = tweetPollBean2.getRelativeTime().toLowerCase();
-            relativeTime = relativeTime.replace("*", " ").replace("=", " ").replace("_", " ");
-            tweetPollBean2.setRelativeTime(relativeTime);
+        for (TweetPollBean tweetPoll : tweetPollBean) {
+            tweetPoll = convertTweetPollRelativeTime(tweetPoll, request);
         }
+        return tweetPollBean;
+    }
 
+    /**
+     * Get tweetPoll by top rated.
+     * @param hashTagId
+     * @param limit
+     * @param request
+     * @return
+     */
+  /*  public List<TweetPollBean> getTweetPollsbyTopRated(
+            final Long hashTagId,
+            final Integer limit,
+            final HttpServletRequest request){
+        final List<TweetPoll> tweetPolls = getTweetPollDao().getTweetpollByTopRated(hashTagId, limit);
+        log.debug("TweetPoll by TopRated total size ---> "+tweetPolls.size());
+        final List<TweetPollBean> tweetPollBean = ConvertDomainBean.convertListToTweetPollBean(tweetPolls);
+        for (TweetPollBean tweetPoll : tweetPollBean) {
+            tweetPoll = convertTweetPollRelativeTime(tweetPoll, request);
+        }
         return tweetPollBean;
     }
+*/
+    /**
+     * Get hashTag relevance.
+     * @param hashTagId
+     * @param limit
+     * @return
+     */
+    public Integer getHashTagRelevance(final Long hashTagId, final Integer limit){
+        final Integer totalRelTweetPoll;
+        final Integer relevance;
+        final List<TweetPoll> tweetPolls = getTweetPollDao().getTweetpollByHashTagId(hashTagId, limit, "");
+        totalRelTweetPoll = tweetPolls.size();
+        relevance = totalRelTweetPoll;
+        //TODO:Pending count relevance hashtags for polls and surveys.
+        return relevance;
+    }
 }

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

 
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 
 import org.encuestame.core.files.PathUtil;
 import org.encuestame.persistence.domain.security.Account;
 import org.encuestame.persistence.domain.security.UserAccount;
+import org.encuestame.persistence.domain.security.UserAccount.PictureSource;
 import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
+import org.encuestame.utils.PictureUtils;
+import org.encuestame.utils.exception.EnMeGenericException;
 import org.springframework.stereotype.Service;
 
+import com.sun.java.swing.plaf.gtk.GTKConstants.WidgetType;
+
 /**
  * Picture / Image Service.
  * @author Picado, Juan juanATencuestame.org
     }
 
     /**
-     * Get Profile Picture.
-     * @param id
-     * @param username
-     * @param pictureType
+     * Return a gravatar picture url.
+     * @param email
+     * @param size
+     * @return
+     * @throws EnMeGenericException
+     */
+    private byte[] getGravatarPicture(final String email, final PictureType size) throws EnMeGenericException {
+        log.debug("getGravatarPicture "+size);
+        log.debug("getGravatarPicture "+email);
+        return PictureUtils.downloadGravatar(email, size.toInt());
+    }
+
+    /**
+     *
+     * @param size
+     * @param account
      * @return
      * @throws IOException
-     * @throws EnMeNoResultsFoundException
      */
-    public byte[] getProfilePicture(
-            final String username,
-            final PictureType pictureType) throws IOException, EnMeNoResultsFoundException{
-        final StringBuilder url = new StringBuilder(getAccountUserPicturePath(username));
+    private byte[] getProfilePicture(final PictureType size, final UserAccount account) throws IOException{
+        final StringBuilder url = new StringBuilder(this.getPicturePath(account.getAccount()));
         url.append("/file");
-        url.append(pictureType.toString());
+        url.append(size.toInt().toString());
         url.append(".jpg");
         log.debug("getProfileURl "+url);
         final File file = new File(url.toString());
         is.close();
         log.debug("getProfileURl "+bytes);
         return bytes;
-
     }
 
     /**
-     * Return real path folder for user account.
+     * Get Profile Picture.
+     * @param id
+     * @param username
+     * @param pictureType
      * @return
-     * @throws EnMeNoResultsFoundException
+     * @throws IOException
+     * @throws EnMeGenericException
      */
-    public String getAccountUserPicturePath(final String username)
-           throws EnMeNoResultsFoundException{
+    public byte[] getProfilePicture(
+            final String username,
+            final PictureType pictureType) throws IOException, EnMeGenericException {
+        log.debug("getProfilePicture "+username);
+        log.debug("getProfilePicture "+pictureType.toString());
         final UserAccount user = getUserAccount(username);
-        log.debug("getAccountUserPicturePath "+user);
-        return this.getPicturePath(user.getAccount());
+        if (user.getPictureSource().equals(PictureSource.UPLOADED)) {
+            return this.getProfilePicture(pictureType, user);
+        } else if (user.getPictureSource().equals(PictureSource.GRAVATAR)) {
+            return this.getGravatarPicture(user.getUserEmail(), pictureType);
+        } else {
+            return this.getGravatarPicture(user.getUserEmail(), pictureType);
+        }
     }
 
+
+    /**
+     * Picture Type.
+     * @author Picado, Juan juanATencuestame.org
+     * @since Jul 3, 2011
+     */
     public enum PictureType {
         ICON,
         THUMBNAIL,
         DEFAULT,
+        PROFILE,
         PREVIEW,
         WEB;
 
             if (this == ICON) { pictureSize = "_22"; }
             else if (this == THUMBNAIL) { pictureSize = "_64"; }
             else if (this == DEFAULT) { pictureSize = "_128"; }
+            else if (this == PROFILE) { pictureSize = "_256"; }
             else if (this == PREVIEW) { pictureSize = "_375"; }
             else if (this == WEB) { pictureSize = "_900"; }
             return pictureSize;
         }
+
+        /**
+         * To integer.
+         * @return
+         */
+        public Integer toInt() {
+            Integer pictureSize = 64;
+            if (this == ICON) { pictureSize = 22; }
+            else if (this == THUMBNAIL) { pictureSize = 64; }
+            else if (this == DEFAULT) { pictureSize = 128; }
+            else if (this == PROFILE) { pictureSize = 256; }
+            else if (this == PREVIEW) { pictureSize = 375; }
+            else if (this == WEB) { pictureSize = 900; }
+            return pictureSize;
+        }
     }
 }

encuestame-business/src/main/java/org/encuestame/business/service/PollService.java

 import org.apache.commons.logging.LogFactory;
 import org.encuestame.business.service.imp.IPollService;
 import org.encuestame.core.util.ConvertDomainBean;
-import org.encuestame.core.util.MD5Utils;
 import org.encuestame.persistence.dao.IFolder;
 import org.encuestame.persistence.domain.Email;
 import org.encuestame.persistence.domain.question.Question;
 import org.encuestame.persistence.exception.EnMeExpcetion;
 import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
 import org.encuestame.persistence.exception.EnMePollNotFoundException;
+import org.encuestame.utils.MD5Utils;
 import org.encuestame.utils.web.FolderBean;
 import org.encuestame.utils.web.QuestionBean;
 import org.encuestame.utils.web.UnitLists;

encuestame-business/src/main/java/org/encuestame/business/service/SecurityService.java

 import org.apache.log4j.Logger;
 import org.encuestame.business.service.imp.SecurityOperations;
 import org.encuestame.business.service.social.signin.SocialSignInOperations;
+import org.encuestame.core.files.PathUtil;
 import org.encuestame.core.security.SecurityUtils;
 import org.encuestame.core.security.util.EnMePasswordUtils;
 import org.encuestame.core.security.util.PasswordGenerator;
 import org.encuestame.core.util.ConvertDomainBean;
 import org.encuestame.core.util.ConvertDomainsToSecurityContext;
+import org.encuestame.core.util.SocialUtils;
 import org.encuestame.persistence.domain.EnMePermission;
 import org.encuestame.persistence.domain.notifications.Notification;
 import org.encuestame.persistence.domain.security.Account;
 @Service
 public class SecurityService extends AbstractBaseService implements SecurityOperations {
 
+    /**
+     * Log.
+     */
     private Logger log = Logger.getLogger(this.getClass());
 
     /** Default User Permission **/
     private static final EnMePermission DEFAULT = EnMePermission.ENCUESTAME_USER;
 
-    /** Default User Permission **/
-    private static final EnMePermission ADMIN = EnMePermission.ENCUESTAME_ADMIN;
-
-    /** Default User Permission **/
-    private static final EnMePermission EDITOR = EnMePermission.ENCUESTAME_EDITOR;
-
-    /** Default User Permission **/
-    private static final EnMePermission OWNER = EnMePermission.ENCUESTAME_OWNER;
-
-    /** Default User Permission **/
-    private static final EnMePermission PUBLISHER = EnMePermission.ENCUESTAME_PUBLISHER;
-
-
-    private final Integer DEFAULT_LENGTH_PASSWORD = 8;
-
-    private static int TWITTER_AUTH_ERROR = 401;
-
+    /**
+     * Dashboard path.
+     */
     private final String DASHBOARD_REDIRECT = "redirect:/user/dashboard";
 
     /**
         // SecUsers userD = getUser(user.getUsername());
         // SecPermission perD = loadPermission(permission.getPermission());
         //assingGroup(user, group);
+        //TODO: ????/ emtpy??
     }
 
 
         final UserAccount userAccount = new UserAccount();
         userAccount.setUsername(singUpBean.getUsername());
         //generate password.
-        final String password = EnMePasswordUtils.createRandomPassword(this.DEFAULT_LENGTH_PASSWORD);
+        final String password = EnMePasswordUtils.createRandomPassword(EnMePasswordUtils.DEFAULT_LENGTH_PASSWORD);
         userAccount.setPassword(encodingPassword(password));
         singUpBean.setPassword(password);
         //invite code
             }
         } catch (TwitterException te) {
             log.error("Twitter Error "+te.getMessage());
-            if (SecurityService.TWITTER_AUTH_ERROR == te.getStatusCode()) {
+            if (SocialUtils.TWITTER_AUTH_ERROR == te.getStatusCode()) {
                 log.error("Twitter Error "+te.getStatusCode());
                 verified = false;
             } else {
             //getAccountDao().saveOrUpdate(connection.getSocialAccount());
             getAccountDao().saveOrUpdate(socialAccount);
             SecurityUtils.socialAuthentication(socialAccount); //TODO: only with OWNER UserAccount.
-            return DASHBOARD_REDIRECT;
+            return PathUtil.DASHBOARD_REDIRECT;
         } else {
             //if user has been never connected, we check if the user exist with the social account email.
             log.info("Connecting: Creating new connection");

encuestame-business/src/main/java/org/encuestame/business/service/SurveyService.java

 import org.encuestame.business.service.imp.ISurveyService;
 import org.encuestame.business.service.social.api.TwitterAPITemplate;
 import org.encuestame.core.util.ConvertDomainBean;
-import org.encuestame.core.util.MD5Utils;
 import org.encuestame.persistence.domain.question.Question;
 import org.encuestame.persistence.domain.question.QuestionAnswer;
 import org.encuestame.persistence.domain.question.QuestionPattern;
 import org.encuestame.persistence.domain.survey.Survey;
 import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
 import org.encuestame.persistence.exception.EnMeExpcetion;
+import org.encuestame.utils.MD5Utils;
 import org.encuestame.utils.RestFullUtil;
 import org.encuestame.utils.web.QuestionAnswerBean;
 import org.encuestame.utils.web.FolderBean;

encuestame-business/src/main/java/org/encuestame/business/service/TweetPollService.java

      * @see org.encuestame.business.service.imp.ITweetPollService#getTweetPollById(java.lang.Long, org.encuestame.persistence.domain.security.UserAccount)
      */
     public TweetPoll getTweetPollById(final Long tweetPollId) throws EnMeNoResultsFoundException{
-        final TweetPoll tweetPoll = getTweetPollDao()
-                .getTweetPollByIdandUserId(
-                        tweetPollId,
-                        getUserAccount(getUserPrincipalUsername()).getAccount().getUid()
-                                );
+        return this.getTweetPollById(tweetPollId, getUserPrincipalUsername());
+    }
+
+    /*
+     *
+     */
+    public TweetPoll getTweetPollById(final Long tweetPollId, final String username) throws EnMeNoResultsFoundException {
+        TweetPoll tweetPoll = null;
+        if (username != null) {
+            tweetPoll = getTweetPollDao()
+                    .getTweetPollByIdandUserId(tweetPollId,
+                            getUserAccount(username).getAccount().getUid());
+        } else {
+            tweetPoll = getTweetPollDao().getTweetPollById(tweetPollId);
+        }
         if (tweetPoll == null) {
             log.error("tweet poll invalid with this id "+tweetPollId);
             throw new EnMeTweetPollNotFoundException("tweet poll invalid with this id "+tweetPollId);
      * @throws EnMeNoResultsFoundException
      */
     private TweetPoll getTweetPoll(final Long tweetPollId, final String username) throws EnMeNoResultsFoundException{
-        return getTweetPollById(tweetPollId);
+        return this.getTweetPollById(tweetPollId, username);
     }
 
     /**

encuestame-business/src/main/java/org/encuestame/business/service/imp/IFrontEndService.java

 
 import java.util.List;
 
+import javax.servlet.http.HttpServletRequest;
+
 import org.encuestame.core.service.ServiceOperations;
 import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
 import org.encuestame.persistence.exception.EnMeSearchException;
      */
      List<TweetPollBean> searchItemsByTweetPoll(
             final String period,
-            Integer maxResults)
+            final Integer start,
+            Integer maxResults,
+            final HttpServletRequest request)
             throws EnMeSearchException;
 
      /**
       */
     List<UnitPoll> searchItemsByPoll(
              final String period,
+             final Integer start,
              Integer maxResults)
              throws EnMeSearchException;
 
      * List Hash tags
      * @param maxResults
      * @param start
+     * @param tagCriteria
      * @return
      */
     List<HashTagBean> getHashTags(
             Integer maxResults,
-            final Integer start);
+            final Integer start,
+            final String tagCriteria);
 
     /**
      * Get hashTag item.
      * Get TweetPolls by hashTag id.
      * @param hashTagId
      * @param limit
+     * @param request
+     * @return
+     */
+    List<TweetPollBean> getTweetPollsbyHashTagId(final Long hashTagId, final Integer limit, final String filter, final HttpServletRequest request);
+
+    /**
+     * Get TweetPolls by top rated.
+     * @param hashTagId
+     * @param limit
+     * @param request
      * @return
      */
-    List<TweetPollBean> getTweetPollsbyHashTagId(final Long hashTagId, final Integer limit);
+    //List<TweetPollBean> getTweetPollsbyTopRated(final Long hashTagId, final Integer limit, final HttpServletRequest request);
 }

encuestame-business/src/main/java/org/encuestame/business/service/imp/IPictureService.java

 
 import org.encuestame.business.service.PictureService.PictureType;
 import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
+import org.encuestame.utils.exception.EnMeGenericException;
 
 /**
  * Picture Service.
  */
 public interface IPictureService {
 
-
-    /**
-     * Return real path folder for user account.
-     * @return
-     * @throws EnMeNoResultsFoundException
-     */
-    String getAccountUserPicturePath(final String account)
-                                    throws EnMeNoResultsFoundException;
-
     /**
      * Get Profile Picture.
      * @param id
      * @throws FileNotFoundException
      * @throws IOException
      * @throws EnMeNoResultsFoundException
+     * @throws EnMeGenericException
      */
     byte[] getProfilePicture(
             final String username,
-            final PictureType pictureType) throws FileNotFoundException, IOException, EnMeNoResultsFoundException;
+            final PictureType pictureType) throws FileNotFoundException, IOException, EnMeNoResultsFoundException, EnMeGenericException;
 }

encuestame-business/src/main/java/org/encuestame/business/service/imp/ITweetPollService.java

     TweetPoll getTweetPollById(final Long tweetPollId) throws EnMeTweetPollNotFoundException, EnMeNoResultsFoundException;
 
     /**
+     * Get tweetpoll by id and username
+     * @param tweetPollId tweetpoll id
+     * @param username username
+     * @return {@link TweetPoll}
+     * @throws EnMeNoResultsFoundException
+     */
+    public TweetPoll getTweetPollById(final Long tweetPollId, final String username) throws EnMeNoResultsFoundException;
+
+    /**
      * Get complete list of {@link TweetPollSwitch}/
      * @param tweetPoll {@link TweetPoll}.
      * @return resutls.

encuestame-business/src/test/java/org/encuestame/test/business/service/TestSecurityService.java

     @Test
     @Ignore
     public void testupdateOAuthTokenSocialAccount() throws EnMeExpcetion{
-        SocialAccount account = createDefaultSettedTwitterAccount(this.userPrimary);
+        SocialAccount account = createDefaultSettedSocialAccount(this.secUserSecondary);
         //this.securityService.updateOAuthTokenSocialAccount(account.getId(), "12345", "fakeTokenSecret", this.secUserSecondary.getUsername());
         account = getAccountDao().getSocialAccountById(account.getId());
         assertEquals(account.getSecretToken(), "fakeTokenSecret");

encuestame-business/src/test/java/org/encuestame/test/business/service/TestTweetPollService.java

 
     @Test
     public void testPublicMultiplesTweetAccounts(){
-            createDefaultSettedTwitterAccount(this.userAccount.getAccount());
+            createDefaultSettedSocialAccount(this.userAccount);
             final List<SocialAccount> list = getAccountDao().getSocialAccountByAccount(this.userAccount.getAccount(), SocialProvider.TWITTER);
             final List<SocialAccountBean> listUnitTwitterAccount = ConvertDomainBean.convertListSocialAccountsToBean(list);
              final String tweetText = RandomStringUtils.randomAlphabetic(5);

encuestame-business/src/test/java/org/encuestame/test/business/service/TestTwitterService.java

 import org.encuestame.business.service.social.api.TwitterAPITemplate;
 import org.encuestame.persistence.domain.security.Account;
 import org.encuestame.persistence.domain.security.SocialAccount;
+import org.encuestame.persistence.domain.security.UserAccount;
 import org.encuestame.test.business.service.config.AbstractServiceBase;
 import org.encuestame.test.config.AbstractBaseUnitBeans;
 import org.encuestame.utils.TweetPublishedMetadata;
     /** {@link Account}. **/
     private Account user;
 
+    private UserAccount userAccount;
+
     private SocialAccount socialTwitterAccount;
 
     /**
     @Before
     public void before(){
         this.user = createAccount();
-        this.socialTwitterAccount = createDefaultSettedTwitterAccount(this.user);
+        this.userAccount = createUserAccount("jota", this.user);
+        this.socialTwitterAccount = createDefaultSettedSocialAccount(this.userAccount);
         this.twitterService = new TwitterAPITemplate("", "","", "");
     }
 

encuestame-core/src/main/java/org/encuestame/core/files/PathUtil.java

      *
      */
     public static final String profileUserImage = "/user/picture/profile";
+
+    public static final String DASHBOARD_REDIRECT = "redirect:/user/dashboard";
 }

encuestame-core/src/main/java/org/encuestame/core/security/util/EnMePasswordUtils.java

 
 package org.encuestame.core.security.util;
 
-import java.util.Random;
-
-import org.apache.commons.lang.RandomStringUtils;
 import org.jasypt.util.password.StrongPasswordEncryptor;
 
 /**
 public class EnMePasswordUtils {
 
     /**
+     * Default lenght password.
+     */
+    public static final Integer DEFAULT_LENGTH_PASSWORD = 8;
+
+    /**
      * Create Random Password.
      * @param length
      * @return

encuestame-core/src/main/java/org/encuestame/core/util/ConvertDomainBean.java

 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Set;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.encuestame.persistence.dao.IFolder;
 import org.encuestame.persistence.domain.tweetpoll.TweetPoll;
 import org.encuestame.persistence.domain.tweetpoll.TweetPollSwitch;
 import org.encuestame.utils.DateUtil;
-import org.encuestame.utils.RelativeTimeEnum;
 import org.encuestame.utils.security.ProfileUserAccount;
 import org.encuestame.utils.security.SignUpBean;
 import org.encuestame.utils.security.SocialAccountBean;
      */
     public static final TweetPollBean convertTweetPollToBean(final TweetPoll tweetPoll){
         final TweetPollBean unitTweetPoll = new TweetPollBean();
-        final HashMap<Integer, RelativeTimeEnum> relative;
         unitTweetPoll.setId(tweetPoll.getTweetPollId());
         unitTweetPoll.setScheduleDate(tweetPoll.getScheduleDate());
         unitTweetPoll.setCreateDate(DateUtil.getFormatDate(tweetPoll.getCreateDate()));
         unitTweetPoll.setSchedule(tweetPoll.getScheduleTweetPoll() == null ? false : tweetPoll.getScheduleTweetPoll());
         unitTweetPoll.setResultNotification(tweetPoll.getResultNotification() == null ? false : tweetPoll.getResultNotification());
         unitTweetPoll.setUserId(tweetPoll.getTweetOwner().getUid());
-        unitTweetPoll.setOwnerUsername(tweetPoll.getEditorOwner().getUsername());
+        unitTweetPoll.setOwnerUsername(tweetPoll.getEditorOwner() == null ? null : tweetPoll.getEditorOwner().getUsername());
         unitTweetPoll.setCaptcha(tweetPoll.getCaptcha() == null ? false : tweetPoll.getCaptcha());
         unitTweetPoll.setCloseNotification(tweetPoll.getCloseNotification() == null ? false : tweetPoll.getCloseNotification());
         unitTweetPoll.setFavourites(tweetPoll.getFavourites() == null ? false : tweetPoll.getFavourites());
         unitTweetPoll.setCompleted(tweetPoll.getCompleted() == null ? false : tweetPoll.getCompleted());
         unitTweetPoll.setQuestionBean(convertQuestionsToBean(tweetPoll.getQuestion()));
         unitTweetPoll.setAllowRepeatedVotes(tweetPoll.getAllowRepatedVotes() == null ? false : tweetPoll.getAllowRepatedVotes());
-        relative = DateUtil.getRelativeTime(tweetPoll.getCreateDate());
-        unitTweetPoll.setRelativeTime(relative.toString());
+        //unitTweetPoll.setRelativeTime(tweetPoll.get);
         unitTweetPoll.setHashTags(ConvertDomainBean.convertListHashTagsToBean(new ArrayList<HashTag>(tweetPoll.getHashTags())));
+        unitTweetPoll.setTotalVotes(tweetPoll.getNumbervotes() == null ? 0L : Long.valueOf(tweetPoll.getNumbervotes()));
+        unitTweetPoll.setCreatedDateAt(tweetPoll.getCreateDate());
         return unitTweetPoll;
     }
 

encuestame-core/src/main/java/org/encuestame/core/util/JSONUtils.java

 import org.codehaus.jackson.JsonFactory;
 import org.codehaus.jackson.JsonGenerator;
 import org.codehaus.jackson.map.ObjectMapper;
-import org.encuestame.core.social.BuzzProfile;
 
 /**
  * Helper to JSON.

encuestame-core/src/main/java/org/encuestame/core/util/MD5Utils.java

-/*
- ************************************************************************************
- * Copyright (C) 2001-2010 encuestame: system online surveys Copyright (C) 2010
- * encuestame Development Team.
- * Licensed under the Apache Software License version 2.0
- * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to  in writing,  software  distributed
- * under the License is distributed  on  an  "AS IS"  BASIS,  WITHOUT  WARRANTIES  OR
- * CONDITIONS OF ANY KIND, either  express  or  implied.  See  the  License  for  the
- * specific language governing permissions and limitations under the License.
- ************************************************************************************
- */
-
-package org.encuestame.core.util;
-
-import java.io.UnsupportedEncodingException;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-
-/**
- * MD5 Utils.
- * @author Picado, Juan juan@encuestame.org
- * @since Mar 12, 2010 11:37:48 PM
- * @version $Id: $
- * Taked from shrtlnk project http://tinyurl.com/yfwocal
- */
-public class MD5Utils {
-
-    /**
-     * Convert md5 bytes into hex values
-     * @param data Byte data to be hex'ed
-     * @return Returns the hex representation of the md5sum
-     */
-    private static String convertToHex(byte[] data) {
-        final StringBuffer buf = new StringBuffer();
-        for (byte aData : data) {
-            int halfbyte = (aData >>> 4) & 0x0F;
-            int twoHalfs = 0;
-            do {
-                if ((0 <= halfbyte) && (halfbyte <= 9)) {
-                    buf.append((char) ('0' + halfbyte));
-                }
-                else {
-                    buf.append((char) ('a' + (halfbyte - 10)));
-                }
-                halfbyte = aData & 0x0F;
-            } while (twoHalfs++ < 1);
-        }
-        return buf.toString();
-    }
-
-    /**
-     * Creates an MD5 sum for a text string
-     * @param text The string you want to sum
-     * @return The md5sum
-     * @throws NoSuchAlgorithmException If md5 isn't available
-     * @throws UnsupportedEncodingException If the character encoding isn't available
-     */
-    public static String md5(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException  {
-        MessageDigest md;
-        md = MessageDigest.getInstance("MD5");
-        byte[] md5hash;
-        md.update(text.getBytes("iso-8859-1"), 0, text.length());
-        md5hash = md.digest();
-        return convertToHex(md5hash);
-    }
-
-    /**
-     * Cut off the MD5sum, limit to 6 characters. Will still result in 16777216 possible combinations, 2^128 isn't needed
-     * @param text The sum you want shortened
-     * @return The shortened md5sum
-     */
-    public static String shortMD5(String text) {
-        try {
-            return md5(text).substring(0, 6);
-        } catch (NoSuchAlgorithmException e) {
-        } catch (UnsupportedEncodingException e) {
-        }
-        return "";
-    }
-
-    /**
-     * This will sort the URL parameter by parameter.
-     * @param url The URL we want to sort
-     * @return Returns the sorted URL
-     */
-    public static String sortURL(String url) {
-        String[] urlArgs = url.split("&");
-        java.util.Arrays.sort(urlArgs);
-        String ret = "";
-
-        for (String urlArg : urlArgs) {
-            ret = ret + urlArg;
-        }
-        return ret  ;
-    }
-
-    /**
-     * Hex.
-     * @param array
-     * @return
-     */
-    public static String hex(byte[] array) {
-        StringBuffer sb = new StringBuffer();
-        for (int i = 0; i < array.length; ++i) {
-        sb.append(Integer.toHexString((array[i]
-            & 0xFF) | 0x100).substring(1,3));
-        }
-        return sb.toString();
-    }
-
-    /**
-     * Md5 Hex.
-     * @param message
-     * @return
-     */
-    public static String md5Hex (String message) {
-        try {
-        MessageDigest md = MessageDigest.getInstance("MD5");
-        return hex (md.digest(message.getBytes("CP1252")));
-        }
-        catch (NoSuchAlgorithmException e) {
-        }
-        catch (UnsupportedEncodingException e) {
-        }
-        return null;
-    }
-}

encuestame-core/src/main/java/org/encuestame/core/util/SocialUtils.java

     public final static Integer TWITTER_LIMIT = 140;
 
     /**
+     * Twitter authentictation error.
+     * TODO: move to {@link SocialUtils}.
+     */
+    public final static int TWITTER_AUTH_ERROR = 401;
+
+    /**
      * Get Google Stats from google short url.
      * @param googleShortUrl
      * @return

encuestame-mvc/src/main/java/org/encuestame/mvc/controller/AbstractBaseOperations.java

 import java.util.Collection;
 import java.util.Date;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
+import java.util.Map;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
      * @param date
      * @return
      */
+    @Deprecated
     protected  HashMap<Integer, RelativeTimeEnum> getRelativeTime(final Date date){
          return DateUtil.getRelativeTime(date);
     }
 
+
+    @Deprecated
+    public void convertRelativeTime(final TweetPollBean tpbean, final HttpServletRequest request){
+        final HashMap<Integer, RelativeTimeEnum> relativeTime = getRelativeTime(tpbean.getCreatedDateAt());
+        final Iterator it = relativeTime.entrySet().iterator();
+        while (it.hasNext()) {
+            final Map.Entry<Integer, RelativeTimeEnum> e = (Map.Entry<Integer, RelativeTimeEnum>)it.next();
+            log.debug("--"+e.getKey() + "**" + e.getValue());
+            tpbean.setRelativeTime(convertRelativeTimeMessage(e.getValue(), e.getKey(), request));
+        }
+    }
+
    /**
     * Convert Relative Time Message.
     * @param relativeTimeEnum
     * @param objects
     * @return
     */
+    @Deprecated
    public String convertRelativeTimeMessage(final RelativeTimeEnum relativeTimeEnum, final Integer number,
            final HttpServletRequest request){
        final StringBuilder builder = new StringBuilder();
      * @param args
      * @return
      */
+   @Deprecated
     public String getMessage(final String message,
             final HttpServletRequest request, Object[] args) {
         String stringValue = "";
      * @param args
      * @return
      */
+    @Deprecated
     public String getMessage(final String message, Object[] args){
         return getMessage(message, null, args);
     }
      * @param message
      * @return
      */
+    @Deprecated
     public String getMessage(final String message){
         return getMessage(message, null, null);
     }
      * @param request
      * @return
      */
+    @Deprecated
     private Locale getLocale(final HttpServletRequest request){
         return RequestContextUtils.getLocale(request);
     }

encuestame-mvc/src/main/java/org/encuestame/mvc/controller/FileUploadController.java

             String filePath = null;
             try {
                 log.debug("getting file path for this user");
-                filePath = getPictureService().getAccountUserPicturePath(getUserPrincipalUsername());
+                //filePath = getPictureService().getAccountUserPicturePath(getUserPrincipalUsername());
                 InputStream stream = multipartFile.getInputStream();
                 try {
                     //generate thumbnails
             } catch (IOException e) {
                 e.printStackTrace();
                 log.error("File uploaded failed:" + orgName);
-            } catch (EnMeNoResultsFoundException e) {
-                // TODO Auto-generated catch block
-                e.printStackTrace();
             }
             // Save the file here
             mav.addObject("status", "saved");

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

+/*
+ ************************************************************************************
+ * Copyright (C) 2001-2010 encuestame: system online surveys Copyright (C) 2009
+ * encuestame Development Team.
+ * Licensed under the Apache Software License version 2.0
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to  in writing,  software  distributed
+ * under the License is distributed  on  an  "AS IS"  BASIS,  WITHOUT  WARRANTIES  OR
+ * CONDITIONS OF ANY KIND, either  express  or  implied.  See  the  License  for  the
+ * specific language governing permissions and limitations under the License.
+ ************************************************************************************
+ */
+package org.encuestame.mvc.controller.json;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.collections.ListUtils;
+import org.apache.log4j.Logger;
+import org.codehaus.jackson.JsonGenerationException;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.encuestame.core.util.ConvertDomainBean;
+import org.encuestame.mvc.controller.AbstractJsonController;
+import org.encuestame.persistence.dao.SearchPeriods;
+import org.encuestame.persistence.domain.tweetpoll.TweetPoll;
+import org.encuestame.persistence.exception.EnMeSearchException;
+import org.encuestame.utils.web.HashTagBean;
+import org.encuestame.utils.web.TweetPollBean;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+
+/**
+ * Frontend json controller.
+ * @author Morales, Diana Paola paolaATencuestame.org
+ * @since July 04, 2011
+ */
+
+@Controller
+public class FrontEndJsonController extends AbstractJsonController{
+
+
+    /** Log. **/
+    private Logger log = Logger.getLogger(this.getClass());
+
+    /**
+     * Get frontend items.
+     * @param period
+     * @param maxResults
+     * @param request
+     * @param response
+     * @return
+     * @throws JsonGenerationException
+     * @throws JsonMappingException
+     * @throws IOException
+     */
+    @RequestMapping(value = "/api/common/frontend/stream.json", method = RequestMethod.GET)
+    public ModelMap getFrontendItems(
+            @RequestParam(value = "period", required = false) String period,
+            @RequestParam(value = "maxResults", required = false) Integer maxResults,
+            @RequestParam(value = "start", required = false) Integer start,
+            HttpServletRequest request,
+            HttpServletResponse response) throws JsonGenerationException, JsonMappingException, IOException {
+            try {
+                final Map<String, Object> jsonResponse = new HashMap<String, Object>();
+                if(period == null ){
+                    throw new EnMeSearchException("search params required.");
+                } else {
+                    final  List<TweetPollBean> itemList = getFrontService().searchItemsByTweetPoll(period, start, maxResults, request);
+                    jsonResponse.put("frontendItems", itemList);
+                    setItemResponse(jsonResponse);
+                   }
+            } catch (Exception e) {
+                 log.error(e);
+                 e.printStackTrace();
+            }
+            return returnData();
+        }
+}

encuestame-mvc/src/main/java/org/encuestame/mvc/controller/json/HashTagsJsonController.java

              final IFrontEndService service = getFrontService();
              final List<HashTagBean> hashTagList;
              if(limit == null){
-                 hashTagList = service.getHashTags(20, 0); // TODO: Add to file properties limit to show hashtags.
+                 hashTagList = service.getHashTags(20, 0, "hashTagsCloud"); // TODO: Add to file properties limit to show hashtags.
              }
              else {
-                hashTagList = service.getHashTags(limit, 0);
+                hashTagList = service.getHashTags(limit, 0, "hashTagsCloud");
              }
              jsonResponse.put("cloud", hashTagList);
              setItemResponse(jsonResponse);

encuestame-mvc/src/main/java/org/encuestame/mvc/controller/json/UrlShortAddressController.java

 import org.bouncycastle.jce.provider.JCEMac.MD5;
 import org.codehaus.jackson.JsonGenerationException;
 import org.codehaus.jackson.map.JsonMappingException;
-import org.encuestame.core.util.MD5Utils;
 import org.encuestame.mvc.controller.AbstractJsonController;
+import org.encuestame.utils.MD5Utils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.stereotype.Controller;

encuestame-mvc/src/main/java/org/encuestame/mvc/controller/social/AbstractAccountConnect.java

  */
 package org.encuestame.mvc.controller.social;
 
-import org.apache.commons.lang.RandomStringUtils;
 import org.apache.log4j.Logger;
 import org.encuestame.business.service.imp.TwitterAPIOperations;
 import org.encuestame.business.service.social.OAuth1RequestFlow;
 import org.encuestame.core.exception.EnMeExistPreviousConnectionException;
 import org.encuestame.core.social.BuzzAPIOperations;
 import org.encuestame.core.social.FacebookAPIOperations;
-import org.encuestame.core.social.FacebookProfile;
 import org.encuestame.core.social.IdentiCaProfile;
 import org.encuestame.core.social.IdenticaAPIOperations;
 import org.encuestame.core.social.LinkedInAPIOperations;
                     log.warn("This account already exist");
                     throw new EnMeExistPreviousConnectionException(getMessage("social.repeated.account"));
                 }
-            } else if (socialProvider.equals(SocialProvider.MYSPACE)) {
                 //FUTURE - Issues with OAuth1 request.
             } else if (socialProvider.equals(SocialProvider.YAHOO)) {
                 //FUTURE - Only valid on defined domain.
+                log.debug("Yahoo provider is disabled");
             }
             log.info("Saved New Social Account");
             return actionToDo;

encuestame-mvc/src/main/java/org/encuestame/mvc/util/WidgetUtil.java

 import javax.servlet.http.HttpServletRequest;
 
 import org.encuestame.core.files.PathUtil;
-import org.encuestame.core.util.MD5Utils;
+import org.encuestame.utils.MD5Utils;
+import org.encuestame.utils.PictureUtils;
 import org.jfree.util.Log;
 
 /**
  */
 public class WidgetUtil {
 
-    private static final String GRAVATAR_URL = "http://www.gravatar.com/avatar/";
-
     private static final String URL = "http://";
 
     private static final Integer REQUEST_SERVER_PORT = 80;
      * @param email
      * @param size
      * @return
+     * @deprecated moved to {@link PictureUtils}
      */
+    @Deprecated
     public final String getGravatar(final String email, Integer size) {
         final String hash = MD5Utils.md5Hex(email);
         StringBuilder gravatarUl = new StringBuilder();
-        gravatarUl.append(WidgetUtil.GRAVATAR_URL);
+        gravatarUl.append(PictureUtils.GRAVATAR_URL);
         gravatarUl.append(hash);
         gravatarUl.append("?s=");
         gravatarUl.append(size);

encuestame-mvc/src/main/java/org/encuestame/mvc/view/HashTagController.java

     /** Log. **/
         private Log log = LogFactory.getLog(this.getClass());
 
+        /** HashTag max results. **/
+        private final Integer MAX_HASHTAG = 80;
+
+        /** HashTag max results. **/
+        private final Integer LIMIT_HASHTAG = 15;
     /**
      * HashTag List.
      * @param model
     public String hashTagController(ModelMap model, HttpServletRequest request,
                   HttpServletResponse response) {
         final IFrontEndService service = getFrontService();
-        final List<HashTagBean> hashTagList = service.getHashTags(20, 0); //TODO: Add to file properties number 20
+        final List<HashTagBean> hashTagList = service.getHashTags(MAX_HASHTAG, 0, "hashTagsCloud"); //TODO: Add to file properties number 20
         log.debug("Tag list size ---> "+ hashTagList.size());
         model.addAttribute("hashtags", hashTagList);
         return "cloud";
         try {
             final HashTagBean tag = service.getHashTagItem(name);
             log.debug("hashTag Id ---> "+ tag.getId());
-            final List<TweetPollBean> tweetPoll = service.getTweetPollsbyHashTagId(tag.getId(), 10);
-            log.debug("TweetPolls by HashTag Id ---> "+ tweetPoll.size());
+            final List<TweetPollBean> tweetPollbyTags = service.getTweetPollsbyHashTagId(tag.getId(), LIMIT_HASHTAG, "hashtag", request);
+            log.debug("TweetPolls by HashTag Id ---> "+ tweetPollbyTags.size());
+
+            final List<TweetPollBean> tweetPollbyRated = service.getTweetPollsbyHashTagId(tag.getId(), LIMIT_HASHTAG, "hashtagRated", request);
+            log.debug("TweetPolls by Top rated ---> "+ tweetPollbyTags.size());
             if (tag == null) {
                 return "pageNotFound";
             } else {
                 model.addAttribute("tagName", service.getHashTagItem(name));
-                model.addAttribute("tweetPolls", service.getTweetPollsbyHashTagId(tag.getId(), 10));
+                model.addAttribute("tweetPolls", tweetPollbyTags);
+                model.addAttribute("tweetPollrated", tweetPollbyRated);
             }
-        }catch (Exception e) {
+        } catch (Exception e) {
+            log.error(e);
+            e.printStackTrace();
             return "pageNotFound";
         }
         return "tag/detail";

encuestame-mvc/src/main/java/org/encuestame/mvc/view/HomeController.java

     */
     private Log log = LogFactory.getLog(this.getClass());
 
+    /** HashTag max results. **/
+    private final Integer MAX_HASHTAG = 80;
+
+    /** Items max results. **/
+    private final Integer MAX_ITEMS = 10;
     /**
     * Home Controller.
     *
             final IFrontEndService service = getFrontService();
             try {
                 if (view.isEmpty()) {
-                    model.addAttribute("items", service.searchItemsByTweetPoll(period, 20));
+                    model.addAttribute("items", service.searchItemsByTweetPoll(period, 0 ,MAX_ITEMS, request));
                 } else {
                     if ("tweetpoll".equals(view)){
-                        model.addAttribute("items", service.searchItemsByTweetPoll(period, 20));
+                        model.addAttribute("items", service.searchItemsByTweetPoll(period, 0 ,MAX_ITEMS, request));
                     } else if("poll".equals(view)){
-                        model.addAttribute("items", service.searchItemsByPoll(period, 20));
+                        model.addAttribute("items", service.searchItemsByPoll(period, 0 ,MAX_ITEMS));
                     } else if("survey".equals(view)){
-                        model.addAttribute("items", service.searchItemsByTweetPoll(period, 20));
+                        model.addAttribute("items", service.searchItemsByTweetPoll(period, 0 ,MAX_ITEMS, request));
                     }
                 }
-                model.addAttribute("hashTags", service.getHashTags(30, 0));
+                model.addAttribute("hashTags", service.getHashTags(MAX_HASHTAG, 0, ""));
                 //TODO: search hashtags and other information.
             } catch (EnMeSearchException e) {
                 return "error";

encuestame-mvc/src/main/java/org/encuestame/mvc/view/PictureProfileFactoryController.java

 import java.io.FileNotFoundException;
 import java.io.IOException;
 
+import org.apache.log4j.Logger;
 import org.encuestame.business.service.PictureService.PictureType;
 import org.encuestame.mvc.controller.AbstractBaseOperations;
 import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
+import org.encuestame.utils.exception.EnMeGenericException;
 import org.springframework.stereotype.Controller;
-import org.springframework.ui.ModelMap;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 public class PictureProfileFactoryController extends AbstractBaseOperations {
 
     /**
-     * Returns the byte[] that contains the requested thumbnail image (128x128 constrained).
-     * @param id The identifier of the image
-     * @return A byte[] that contains the requested image
-     * @throws EnMeNoResultsFoundException
+     * Log.
      */
-    @RequestMapping( value = "/picture/profile/{username}/thumbnail", method = RequestMethod.GET )
-    @ResponseBody
-    public byte[] getPictureThumbnail(
-            @PathVariable String username ) throws EnMeNoResultsFoundException{
+    private Logger log = Logger.getLogger(this.getClass());
+
+
+    /**
+     *
+     * @param username
+     * @param pictureType
+     * @return
+     */
+    private byte[] getPicture(String username, final PictureType pictureType){
         byte[] bytes = {};
+        username = filterValue(username);
         try {
-            bytes = getPictureService().getProfilePicture(username, PictureType.THUMBNAIL);
+            bytes = getPictureService().getProfilePicture(username, pictureType);
         } catch (FileNotFoundException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
+            log.error("file not found "+e);
         } catch (IOException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
+            log.error("IOException "+e);
+        } catch (EnMeGenericException e) {
+            log.error("EnMeGenericException "+e);
         }
         return bytes;
     }
 
     /**
-     * Returns the byte[] that contains the requested master image.
-     * @param id The identifier of the image
+     * Returns the byte[] that contains the requested thumbnail image (128x128 constrained).
+     * @return A byte[] that contains the requested image
+     * @throws EnMeNoResultsFoundException
+     */
+    @RequestMapping( value = "/picture/profile/{username}/thumbnail", method = RequestMethod.GET )
+    @ResponseBody
+    public byte[] getPictureThumbnail(
+            @PathVariable String username){
+        return this.getPicture(username, PictureType.THUMBNAIL);
+    }
+
+    /**
+     * Returns the byte[] that contains the requested default image.
      * @return A byte[] that contains the requested image
      * @throws EnMeNoResultsFoundException
      */
     @RequestMapping( value = "/picture/profile/{username}/default", method = RequestMethod.GET )
     @ResponseBody
     public byte[] getPictureMaster(
-            @PathVariable String username ) throws EnMeNoResultsFoundException{
-        byte[] bytes = {};
-        try {
-            bytes = getPictureService().getProfilePicture(username, PictureType.DEFAULT);
-        } catch (FileNotFoundException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        } catch (IOException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
-        return bytes;
+            @PathVariable String username ) {
+        return this.getPicture(username, PictureType.DEFAULT);
     }
 
     /**
-     * Returns the byte[] that contains the requested preview image (800x800 constrained)
-     * @param id The identifier of the image
+     * Returns the byte[] that contains the requested preview image (256x256 constrained)
+     * @param username
+     * @return
+     */
+    @RequestMapping( value = "/picture/profile/{username}/profile", method = RequestMethod.GET )
+    @ResponseBody
+    public byte[] getPictureProfile(
+            @PathVariable String username ) {
+        return this.getPicture(username, PictureType.PROFILE);
+    }
+
+    /**
+     * Returns the byte[] that contains the requested preview image (375x375 constrained)
      * @return A byte[] that contains the requested image
      * @throws EnMeNoResultsFoundException
      */
     @RequestMapping( value = "/picture/profile/{username}/preview", method = RequestMethod.GET)
     @ResponseBody
     public byte[] getPicturePreview(
-            @PathVariable String username ) throws EnMeNoResultsFoundException{
-        byte[] bytes = {};
-        try {
-            bytes = getPictureService().getProfilePicture(username,  PictureType.PREVIEW);
-        } catch (FileNotFoundException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        } catch (IOException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
-        return bytes;
+            @PathVariable String username ){
+          return this.getPicture(username, PictureType.PREVIEW);
+    }
+
+    /**
+     * Returns the byte[] that contains the requested preview image (900x900 constrained)