Commits

Juan Carlos Picado Herrera  committed 2128149 Merge

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

  • Participants
  • Parent commits 206a06a, 206a06a 1
    1. 4d950b5

Comments (0)

Files changed (81)

File 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.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.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

File 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)
+                Integer maxResults,
+                final HttpServletRequest request)
                 throws EnMeSearchException{
         final List<TweetPollBean> results = new ArrayList<TweetPollBean>();
         if(maxResults == null){
             }
             log.debug("TweetPoll "+items.size());
             results.addAll(ConvertDomainBean.convertListToTweetPollBean(items));
+            for (TweetPollBean tweetPoll : results) {
+                tweetPoll = convertTweetPollRelativeTime(tweetPoll, request);
+            }
+
         }
         return results;
     }
         tags.addAll(getHashTagDao().getHashTags(maxResults, start));
         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;
+    public List<TweetPollBean> getTweetPollsbyHashTagId(
+            final Long hashTagId,
+            final Integer limit,
+            final HttpServletRequest request){
         final List<TweetPoll> tweetPolls = getTweetPollDao().getTweetpollByHashTagId(hashTagId, limit);
         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;
+    }
+
+
+    public List<TweetPollBean> searchItemsByTweetPollTopRated(
+            final String period,
+            Integer maxResults,
+            final HttpServletRequest request)
+            throws EnMeSearchException{
+    final List<TweetPollBean> results = new ArrayList<TweetPollBean>();
+    if(maxResults == null){
+        maxResults = this.MAX_RESULTS;
+    }
+    log.debug("Max Results "+maxResults);
+    final List<TweetPoll> items = new ArrayList<TweetPoll>();
+    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));
+        } else if(periodSelected.equals(SearchPeriods.TWENTYFOURHOURS)){
+            items.addAll(getFrontEndDao().getTweetPollFrontEndLast24(maxResults));
+        } else if(periodSelected.equals(SearchPeriods.SEVENDAYS)){
+            items.addAll(getFrontEndDao().getTweetPollFrontEndLast7Days(maxResults));
+        } else if(periodSelected.equals(SearchPeriods.THIRTYDAYS)){
+            items.addAll(getFrontEndDao().getTweetPollFrontEndLast30Days(maxResults));
+        } else if(periodSelected.equals(SearchPeriods.ALLTIME)){
+            items.addAll(getFrontEndDao().getTweetPollFrontEndAllTime(maxResults));
+        }
+        log.debug("TweetPoll "+items.size());
+        results.addAll(ConvertDomainBean.convertListToTweetPollBean(items));
+        for (TweetPollBean tweetPoll : results) {
+            tweetPoll = convertTweetPollRelativeTime(tweetPoll, request);
         }
 
+    }
+    return results;
+}
+
+
+
+    /**
+     * 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;
     }
+
+    /**
+     *
+     * @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;
+    }
 }

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

 import java.util.Set;
 import java.util.UUID;
 
-import javax.servlet.http.HttpServletRequest;
-
 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.social.SocialUserProfile;
 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;
-import org.encuestame.persistence.domain.security.AccountConnection;
 import org.encuestame.persistence.domain.security.Group;
 import org.encuestame.persistence.domain.security.Permission;
 import org.encuestame.persistence.domain.security.SocialAccount;
 import org.encuestame.utils.oauth.AccessGrant;
 import org.encuestame.utils.security.SignUpBean;
 import org.encuestame.utils.security.SocialAccountBean;
+import org.encuestame.utils.social.SocialUserProfile;
 import org.encuestame.utils.web.UnitGroupBean;
 import org.encuestame.utils.web.UnitLists;
 import org.encuestame.utils.web.UnitPermission;
 import org.encuestame.utils.web.UserAccountBean;
-import org.encuestame.utils.web.notification.UtilNotification;
 import org.jasypt.util.password.StrongPasswordEncryptor;
 import org.springframework.mail.MailSendException;
 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
 import org.springframework.security.core.GrantedAuthority;
 import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.stereotype.Service;
+import org.springframework.util.Assert;
 
 import twitter4j.Twitter;
 import twitter4j.TwitterException;
 @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 {
         return verified;
     }
 
-
-    /*
-     * (non-Javadoc)
-     * @see org.encuestame.business.service.imp.SecurityOperations#addNewSocialAccount(java.lang.Long, java.lang.String, java.lang.String, java.lang.String, org.encuestame.persistence.domain.security.UserAccount, org.encuestame.persistence.domain.social.SocialProvider)
-     */
-    public SocialAccount addNewSocialAccount(
-            final String socialAccountId,
-            final String token,
-            final String tokenSecret,
-            final String username,
-            final SocialProvider socialProvider) throws EnMeNoResultsFoundException{
-        return getAccountDao().createSocialAccount(socialAccountId,
-                token,
-                tokenSecret, username, socialProvider,
-                getUserAccount(username).getAccount());
-    }
-
     /*
      * (non-Javadoc)
      * @see org.encuestame.business.service.imp.SecurityOperations#addNewSocialAccount(java.lang.String, java.lang.String, org.encuestame.core.social.SocialUserProfile, org.encuestame.persistence.domain.social.SocialProvider)
             final String tokenSecret,
             final String expiresToken,
             final SocialUserProfile socialUserProfile,
-            final SocialProvider socialProvider) throws EnMeNoResultsFoundException{
-        final SocialAccount socialAccount = new SocialAccount();
-        socialAccount.setAccessToken(token);
-        socialAccount.setSecretToken(tokenSecret);
-        socialAccount.setAccount(getUserAccount(getUserPrincipalUsername()).getAccount());
-        socialAccount.setExpires(expiresToken);
-        socialAccount.setAccounType(socialProvider);
-        socialAccount.setAddedAccount(new Date());
-        socialAccount.setVerfied(Boolean.TRUE);
-        socialAccount.setSocialAccountName(socialUserProfile.getUsername());
-        socialAccount.setType(SocialProvider.getTypeAuth(socialProvider));
-        socialAccount.setUpgradedCredentials(new Date());
-        socialAccount.setSocialProfileId(socialUserProfile.getId());
-        socialAccount.setPrictureUrl(socialUserProfile.getProfileImageUrl()); //TODO: repeated
-        socialAccount.setProfilePictureUrl(socialUserProfile.getProfileImageUrl());
-        socialAccount.setEmail(socialUserProfile.getEmail());
-        socialAccount.setProfileThumbnailPictureUrl(socialUserProfile.getProfileImageUrl());
-        socialAccount.setRealName(socialUserProfile.getRealName());
-        getAccountDao().saveOrUpdate(socialAccount);
-        return socialAccount;
+            final SocialProvider socialProvider,
+            final UserAccount userAccount){
+        return getAccountDao().createSocialAccount(socialUserProfile.getId(), token,
+                tokenSecret, expiresToken, socialUserProfile.getUsername(), socialUserProfile,
+                socialProvider, userAccount);
     }
 
     /**
        return singUpBean;
    }
 
+   /**
+    *
+    * @param accessGrant
+    * @param socialAccountId
+    * @param userAccount
+    * @param providerProfileUrl
+    * @param currentSocialAccount
+    * @return
+    */
+   public SocialAccount updateSocialAccountConnection(
+           final AccessGrant accessGrant, //OAuth2
+           final String socialAccountId,
+           final SocialAccount currentSocialAccount){
+       return getAccountDao().updateSocialAccountConnection(accessGrant, socialAccountId, currentSocialAccount);
+   }
+
     /* Social Account SignIn Connect. * */
 
-    /*
-     *
+    /**
+     * Start the process to sign in with social account.
+     * @param SocialSignInOperations sign in social support.
      */
     public String connectSignInAccount(final SocialSignInOperations social) throws EnMeExpcetion {
         // first, we check if this social account already exist as previous connection.
         log.info("Sign In with Social Account");
-        social.setAccountDaoImp(getAccountDao());
-
         //if user account is previously connected
-        if (social.isConnected(social.getSocialUserProfile().getId())) {
+        SocialAccount socialAccount = social.isConnected(social.getSocialUserProfile().getId());
+        if (socialAccount != null) {
             log.info("Connecting: Exist previously connection");
             //if exist, we update credentials on account connect store.
-            final AccountConnection connection = social.reConnect(social.getSocialUserProfile().getId(), social.getAccessGrant());
-            getAccountDao().saveOrUpdate(connection.getSocialAccount());
-            getAccountDao().saveOrUpdate(connection);
-            SecurityUtils.socialAuthentication(connection);
-            return DASHBOARD_REDIRECT;
+            social.reConnect(social.getSocialUserProfile().getId(), social.getAccessGrant(), socialAccount);
+            //getAccountDao().saveOrUpdate(connection.getSocialAccount());
+            getAccountDao().saveOrUpdate(socialAccount);
+            SecurityUtils.socialAuthentication(socialAccount); //TODO: only with OWNER UserAccount.
+            return PathUtil.DASHBOARD_REDIRECT;
         } else {
-            //if user has been never connected
+            //if user has been never connected, we check if the user exist with the social account email.
             log.info("Connecting: Creating new connection");
             //get email from social profile.
             final String email = this.convertSocialConnectedAccountToBean(social.getSocialUserProfile()).getEmail();
+            log.info("sign in social account email -->"+email);
             String redirectPath =  "signin/provider/register";
-            org.springframework.util.Assert.notNull(email);
+            Assert.notNull(email);
             //user account by email
-            UserAccount accountEmail = getAccountDao().getUserByEmail(email);
-            //if the user account is new, we create new account quickly.
+            final UserAccount accountEmail = getAccountDao().getUserByEmail(email);
+            //if the user account is new, we create new account.
             if (accountEmail == null) {
+                log.debug("This email ["+email+"] never has been used.");
                 //create fist connection and social account.
-                final AccountConnection accountConnection = this.signUpSocial(social.getSocialUserProfile(), social.getAccessGrant(), social.getProvider());
+                final SocialAccount accountConnection = this.signUpSocial(
+                        social.getSocialUserProfile(), social.getAccessGrant(),
+                        social.getProvider(), null);
                 SecurityUtils.socialAuthentication(accountConnection);
             } else {
                 //if user exist, we create new account connection
-                final AccountConnection accountConnection = this.signUpSocial(
-                        social.getSocialUserProfile(), social.getAccessGrant(),
-                        social.getProvider());
-                //sign in programmatically in the app
+                final SocialAccount accountConnection = addNewSocialAccount(
+                        social.getAccessGrant().getAccessToken(),
+                        social.getAccessGrant().getRefreshToken(),
+                        social.getAccessGrant().getExpires(),
+                        social.getSocialUserProfile(),
+                        social.getProvider(),
+                        accountEmail);
                 SecurityUtils.socialAuthentication(accountConnection);
                 redirectPath = DASHBOARD_REDIRECT;
             }
     }
 
     /**
-     *
+     * Default sign up social account.
      * @param profile
      * @param accessGrant
      * @param provider
      * @return
      * @throws EnMeNoResultsFoundException
      */
-    private AccountConnection signUpSocial(final SocialUserProfile profile, final AccessGrant accessGrant,
-            final SocialProvider provider) throws EnMeNoResultsFoundException{
-        UserAccount accountEmail = this.singupUser(this.convertSocialConnectedAccountToBean(profile));
-        final SocialAccount socialAccount = this.addNewSocialAccount(
-                profile.getId(),
+    private SocialAccount signUpSocial(
+            final SocialUserProfile profile,
+            final AccessGrant accessGrant,
+            final SocialProvider provider,
+            final UserAccount account) throws EnMeNoResultsFoundException{
+        UserAccount accountEmail;
+        if (account == null) {
+            //create new account.
+            accountEmail = this.singupUser(this.convertSocialConnectedAccountToBean(profile));
+        } else {
+            //use the current account.
+            accountEmail = account;
+        }
+        final SocialAccount accountConnection = addNewSocialAccount(
                 accessGrant.getAccessToken(),
                 accessGrant.getRefreshToken(),
-                profile.getUsername(),
-                provider);
-        log.info("Connecting: Creating social account "+socialAccount.getId());
-        final AccountConnection accountConnection = this.getAccountDao().addConnection(
+                accessGrant.getExpires(),
+                profile,
                 provider,
-                accessGrant,
-                profile.getId(),
-                accountEmail,
-                profile.getProfileImageUrl(),
-                socialAccount);
-        getAccountDao().saveOrUpdate(accountConnection);
+                accountEmail);
         return accountConnection;
     }
 
 
     }
 
-   /**
-    * Update Twitter Account.
-    * @param accountBean account
-    * @param password password
-    * TODO: this method is close to be deprecated, twitter don't allow password login.
- * @throws EnMeNoResultsFoundException
-    */
-   @Deprecated
-   public void updateTwitterAccount(
-           final SocialAccountBean accountBean,
-           final String password,
-           final Boolean verify) throws EnMeNoResultsFoundException{
-       if(accountBean.accountId != null){
-           final SocialAccount twitterAccount = getSocialAccount(accountBean.accountId);
-           if(twitterAccount != null){
-               twitterAccount.setVerfied(verify);
-               log.debug("Updating twitter password account");
-               getAccountDao().saveOrUpdate(twitterAccount);
-           }
-       }
-       log.info("update Twitter Account");
-   }
+    /*
+     * (non-Javadoc)
+     * @see org.encuestame.business.service.imp.SecurityOperations#findAccountConnectionBySocialProfileId(org.encuestame.persistence.domain.social.SocialProvider, java.lang.String)
+     */
+    public final SocialAccount findAccountConnectionBySocialProfileId(
+            final SocialProvider provider,
+            final String socialProfileId) {
+        return getAccountDao().findAccountConnectionBySocialProfileId(provider, socialProfileId);
+    }
 
    /**
     *

File 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);
     }
 
     /**

File 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)
+            Integer maxResults,
+            final HttpServletRequest request)
             throws EnMeSearchException;
 
      /**
      * Get TweetPolls by hashTag id.
      * @param hashTagId
      * @param limit
+     * @param request
+     * @return
+     */
+    List<TweetPollBean> getTweetPollsbyHashTagId(final Long hashTagId, final Integer limit, 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);
 }

File 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.

File encuestame-business/src/main/java/org/encuestame/business/service/imp/SecurityOperations.java

 import org.encuestame.business.service.social.signin.SocialSignInOperations;
 import org.encuestame.core.exception.EnMeExistPreviousConnectionException;
 import org.encuestame.core.service.ServiceOperations;
-import org.encuestame.core.social.SocialUserProfile;
 import org.encuestame.persistence.domain.EnMePermission;
 import org.encuestame.persistence.domain.notifications.Notification;
 import org.encuestame.persistence.domain.security.Group;
 import org.encuestame.persistence.exception.EnMeExpcetion;
 import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
 import org.encuestame.persistence.exception.EnmeFailOperation;
+import org.encuestame.utils.oauth.AccessGrant;
 import org.encuestame.utils.security.SignUpBean;
 import org.encuestame.utils.security.SocialAccountBean;
+import org.encuestame.utils.social.SocialUserProfile;
 import org.encuestame.utils.web.UnitGroupBean;
 import org.encuestame.utils.web.UnitLists;
 import org.encuestame.utils.web.UnitPermission;
      * @throws EnMeExpcetion
      */
     SocialAccount addNewSocialAccount(
-            final String socialAccountId,
-            final String token,
-            final String tokenSecret,
-            final String username,
-            final SocialProvider socialProvider) throws EnMeNoResultsFoundException;
-
-    /**
-     *
-     * @param token
-     * @param tokenSecret
-     * @param socialUserProfile
-     * @param socialProvider
-     * @return
-     * @throws EnMeNoResultsFoundException
-     */
-    SocialAccount addNewSocialAccount(
             final String token,
             final String tokenSecret,
             final String expiresToken,
             final SocialUserProfile socialUserProfile,
-            final SocialProvider socialProvider) throws EnMeNoResultsFoundException;
+            final SocialProvider socialProvider,
+            final UserAccount userAccount);
 
     /**
      *
      */
     UserAccountBean getUserAccountbyCode(final String inviteCode) throws EnMeNoResultsFoundException;
 
+
+    /**
+     *
+     * @param accessGrant
+     * @param socialAccountId
+     * @param userAccount
+     * @param providerProfileUrl
+     * @param currentSocialAccount
+     * @return
+     */
+    SocialAccount updateSocialAccountConnection(
+            final AccessGrant accessGrant,
+            final String socialAccountId,
+            final SocialAccount currentSocialAccount);
+
     /**
      *
      * @param limit
     List<Notification> loadNotificationByUserAndLimit(final Integer limit, final Integer start,
             final Boolean onlyUnread);
 
+
+    /**
+     *
+     * @param provider
+     * @param socialProfileId
+     * @return
+     */
+    SocialAccount findAccountConnectionBySocialProfileId(
+            final SocialProvider provider,
+            final String socialProfileId);
 }

File encuestame-business/src/main/java/org/encuestame/business/service/social/api/BuzzAPITemplate.java

 import org.encuestame.core.config.EnMePlaceHolderConfigurer;
 import org.encuestame.core.social.BuzzAPIOperations;
 import org.encuestame.core.social.BuzzProfile;
-import org.encuestame.core.social.SocialUserProfile;
 import org.encuestame.core.social.oauth2.ProtectedResourceClientFactory;
 import org.encuestame.persistence.domain.security.SocialAccount;
 import org.encuestame.utils.TweetPublishedMetadata;
+import org.encuestame.utils.social.SocialUserProfile;
 
 /**
  * Google Buzz

File encuestame-business/src/main/java/org/encuestame/business/service/social/api/FacebookAPITemplate.java

 import java.util.List;
 import java.util.Map;
 
-import org.apache.commons.httpclient.URI;
 import org.apache.log4j.Logger;
 import org.encuestame.business.service.social.AbstractSocialAPISupport;
 import org.encuestame.core.social.FacebookAPIOperations;
 import org.encuestame.core.social.FacebookLink;
 import org.encuestame.core.social.FacebookProfile;
-import org.encuestame.core.social.SocialUserProfile;
 import org.encuestame.core.social.oauth2.ProtectedResourceClientFactory;
 import org.encuestame.utils.TweetPublishedMetadata;
+import org.encuestame.utils.social.SocialUserProfile;
 import org.jfree.util.Log;
 import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;

File encuestame-business/src/main/java/org/encuestame/business/service/social/api/IdenticaAPITemplate.java

 import org.encuestame.core.social.IdentiCaProfile;
 import org.encuestame.core.social.IdenticaAPIOperations;
 import org.encuestame.core.social.IdenticaStatusDetails;
-import org.encuestame.core.social.SocialUserProfile;
 import org.encuestame.utils.TweetPublishedMetadata;
+import org.encuestame.utils.social.SocialUserProfile;
 import org.springframework.http.ResponseEntity;
 import org.springframework.util.LinkedMultiValueMap;
 import org.springframework.util.MultiValueMap;

File encuestame-business/src/main/java/org/encuestame/business/service/social/api/LinkedInAPITemplate.java

 import org.encuestame.core.social.LinkedInAPIOperations;
 import org.encuestame.core.social.LinkedInConnections;
 import org.encuestame.core.social.LinkedInProfile;
-import org.encuestame.core.social.SocialUserProfile;
 import org.encuestame.utils.TweetPublishedMetadata;
+import org.encuestame.utils.social.SocialUserProfile;
 
 public class LinkedInAPITemplate extends AbstractSocialAPISupport implements LinkedInAPIOperations {
 

File encuestame-business/src/main/java/org/encuestame/business/service/social/api/TwitterAPITemplate.java

 import org.apache.commons.logging.LogFactory;
 import org.encuestame.business.service.imp.TwitterAPIOperations;
 import org.encuestame.business.service.social.AbstractSocialAPISupport;
-import org.encuestame.core.social.SocialUserProfile;
 import org.encuestame.persistence.domain.security.SocialAccount;
 import org.encuestame.persistence.domain.social.SocialProvider;
 import org.encuestame.utils.TweetPublishedMetadata;
+import org.encuestame.utils.social.SocialUserProfile;
 import org.springframework.util.Assert;
 
 import twitter4j.Status;

File encuestame-business/src/main/java/org/encuestame/business/service/social/signin/AbstractSocialSignInConnect.java

 package org.encuestame.business.service.social.signin;
 
 import org.apache.commons.logging.LogFactory;
+import org.encuestame.business.service.imp.SecurityOperations;
 import org.encuestame.core.exception.EnMeExistPreviousConnectionException;
-import org.encuestame.core.social.SocialUserProfile;
-import org.encuestame.persistence.dao.IAccountDao;
-import org.encuestame.persistence.domain.security.AccountConnection;
 import org.encuestame.persistence.domain.security.SocialAccount;
-import org.encuestame.persistence.domain.security.UserAccount;
 import org.encuestame.persistence.domain.social.SocialProvider;
 import org.encuestame.persistence.exception.EnMeExpcetion;
 import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
 import org.encuestame.utils.oauth.AccessGrant;
+import org.encuestame.utils.social.SocialUserProfile;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.Assert;
 
 /**
  * Abstract Social Provider.
     protected org.apache.commons.logging.Log log = LogFactory.getLog(this.getClass());
 
     /**
-     * Account Dao.
+     * {@link SecurityOperations}
      */
-    private IAccountDao accountDaoImp;
+    @Autowired
+    private SecurityOperations securityOperations;
 
     /**
      * OAuth access grant.
     abstract org.encuestame.core.social.SocialAPIOperations getAPISocialProvider();
 
     /**
-     *
+     * {@link SocialUserProfile}.
      */
     private SocialUserProfile socialUserProfile;
 
     /**
-     *
+     * Constructor.
      * @param accountDaoImpAccountDao
      * @throws Exception
      */
     public AbstractSocialSignInConnect(
-            final AccessGrant accessGrant) throws Exception {
+            final AccessGrant accessGrant,
+            final SecurityOperations securityOperations) throws Exception {
             this.accessGrant = accessGrant;
+            this.securityOperations = securityOperations;
             this.setSocialUserProfile(this.getAPISocialProvider().getProfile());
     }
 
     /*
      * (non-Javadoc)
-     * @see org.encuestame.business.service.social.signin.SocialSignInOperations#connect(java.lang.String, org.encuestame.utils.oauth.AccessGrant)
-     */
-    public AccountConnection reConnect(String accountId, AccessGrant accesGrant) throws EnMeExistPreviousConnectionException, EnMeNoResultsFoundException {
-            log.info("reConnect ..."+accountId);
-            log.info("reConnect ..."+accesGrant.toString());
-            final AccountConnection accountConnection = this.findAccountByConnection(accountId);
-            log.info("Connect restuls: "+accountConnection);
-            if (accountConnection != null) {
-                log.debug("adding new connection");
-                log.info("Updating connection .... "+accountConnection.getAccountConnectionId());
-                accountConnection.setAccessToken(accesGrant.getAccessToken());
-                accountConnection.setRefreshToken(accesGrant.getRefreshToken());
-                accountConnection.setExpires(accesGrant.getExpires());
-                accountConnection.getSocialAccount().setAccessToken(accesGrant.getAccessToken());
-                accountConnection.getSocialAccount().setRefreshToken(accesGrant.getRefreshToken());
-                accountConnection.getSocialAccount().setExpires(accesGrant.getExpires());
-                return accountConnection;
-            } else {
-                log.fatal("There is already a connection created");
-                throw new EnMeExistPreviousConnectionException("There is already a connection created");
-            }
+     *
+     * @see
+     * org.encuestame.business.service.social.signin.SocialSignInOperations#
+     * connect(java.lang.String, org.encuestame.utils.oauth.AccessGrant)
+     */
+    public SocialAccount reConnect(
+            final String accountId,
+            final AccessGrant accesGrant,
+            final SocialAccount socialAccount)
+            throws EnMeExistPreviousConnectionException,
+            EnMeNoResultsFoundException {
+        log.info("reConnect ..." + accountId);
+        log.info("reConnect ..." + accesGrant.toString());
+        log.info("reConnect ..." + socialAccount.getSocialAccountName());
+        log.info("Connect restuls: "+socialAccount);
+        log.debug("reconnect the social account");
+        log.info("Updating connection .... "+socialAccount.getId());
+        this.securityOperations.updateSocialAccountConnection(accesGrant, accountId, socialAccount);
+        return socialAccount;
     }
 
-       /**
-        * Records an existing connection between a user account and this service provider.
-        * @return
-        */
-        @Deprecated
-       public AccountConnection addConnection(
-               final UserAccount account,
-               final SocialAccount socialAccount) {
-            log.info("Connecting: Creating new or update connection");
-           return this.accountDaoImp.addConnection(
-                    getProvider(),
-                    this.accessGrant,
-                    getSocialUserProfile().getId(),
-                    account,
-                    getSocialUserProfile().getProfileImageUrl(),
-                    socialAccount);
-        }
-
-
     /*
      *
      */
      * Return if user account have previous account connection.
      * @param accessToken
      * @return
+     * @throws EnMeExpcetion
      */
-    public boolean isConnected(final String profileId){
-        boolean conected = false;
+    public SocialAccount isConnected(final String profileId) throws EnMeExpcetion {
+        Assert.notNull(profileId);
+        SocialAccount social = null;
         try {
             log.debug("Is connected exist? "+profileId);
-            //check if this user is already conected
-            if(this.findAccountByConnection(profileId) != null){
-                conected = true;
-            }
+            //check if this user is previously connected
+            social = this.findAccountByConnection(profileId);
         } catch (EnMeExpcetion e) {
             log.fatal("isConected error :"+e);
+            throw new EnMeExpcetion(e);
         }
-        log.debug("Is connected "+conected);
-        return conected;
+        log.debug("Is connected "+social);
+        return social;
     }
 
     /**
-     * Sever the connection between the member account and this service provider.
-     * Has no effect if no connection is established to begin with.
-     */
-    public void disconnect(String accountId) {
-            try {
-                this.accountDaoImp.disconnect(accountId, getProvider());
-            } catch (EnMeNoResultsFoundException e) {
-               log.fatal("error on disconect user :"+e);
-            }
-    }
-
-    /**
-     *  Find possible open provider account connections.
+     * Find possible open provider account connections.
      * @param profileId the id provided by social network API
-     * @return {@link AccountConnection}
+     * @return {@link SocialAccount}
      * @throws EnMeNoResultsFoundException
      */
-    public AccountConnection findAccountByConnection(final String socialProfileId)
+    public SocialAccount findAccountByConnection(final String socialProfileId)
             throws EnMeNoResultsFoundException {
-        log.info("Connect  by... "+socialProfileId);
-        return this.accountDaoImp.findAccountConnectionBySocialProfileId(
+        log.info("Find connection with...-> "+socialProfileId);
+        log.info("Find connection with...-> "+socialProfileId);
+        return this.securityOperations.findAccountConnectionBySocialProfileId(
                 getProvider(), socialProfileId);
     }
 
     /**
-     * @return the accountDaoImp
-     */
-    public IAccountDao getAccountDaoImp() {
-        return accountDaoImp;
-    }
-
-    /**
-     * @param accountDaoImp the accountDaoImp to set
-     */
-    public void setAccountDaoImp(final IAccountDao accountDaoImp) {
-        this.accountDaoImp = accountDaoImp;
-    }
-
-    /**
      * @return the accessGrant
      */
     public AccessGrant getAccessGrant() {

File encuestame-business/src/main/java/org/encuestame/business/service/social/signin/FacebookSignInSocialSupport.java

  */
 package org.encuestame.business.service.social.signin;
 
+import org.encuestame.business.service.imp.SecurityOperations;
 import org.encuestame.business.service.social.api.FacebookAPITemplate;
 import org.encuestame.core.social.FacebookAPIOperations;
 import org.encuestame.core.social.SocialAPIOperations;
-import org.encuestame.persistence.dao.IAccountDao;
-import org.encuestame.persistence.domain.security.AccountConnection;
 import org.encuestame.persistence.domain.social.SocialProvider;
-import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
 import org.encuestame.utils.oauth.AccessGrant;
+
 /**
  * Facebook. Social Service.
+ *
  * @author Picado, Juan juanATencuestame.org
  * @since Dec 25, 2010 5:57:35 PM
  */
-public class FacebookSignInSocialSupport extends AbstractSocialSignInConnect<FacebookAPIOperations>{
+public class FacebookSignInSocialSupport extends AbstractSocialSignInConnect<FacebookAPIOperations> {
 
     /**
      *
      * @param accountDao
      * @throws Exception
      */
-    public FacebookSignInSocialSupport(final AccessGrant accessToken) throws Exception {
-        super(accessToken);
+    public FacebookSignInSocialSupport(
+            final AccessGrant accessToken,
+            final SecurityOperations securityOperations)
+            throws Exception {
+        super(accessToken, securityOperations);
     }
 
-
     @Override
     public SocialAPIOperations getAPISocialProvider() {
-       return new FacebookAPITemplate(getAccessGrant().getAccessToken());
-    }
-
-
-    @Override
-    public void disconnect(String accountId) {
-        // TODO Auto-generated method stub
+        return new FacebookAPITemplate(getAccessGrant().getAccessToken());
     }
 
     @Override
     public SocialProvider getProvider() {
         return SocialProvider.FACEBOOK;
     }
-
-
-    @Override
-    public void disconnect() {
-        // TODO Auto-generated method stub
-
-    }
 }

File encuestame-business/src/main/java/org/encuestame/business/service/social/signin/GoogleSignInSocialService.java

  */
 package org.encuestame.business.service.social.signin;
 
+import org.encuestame.business.service.imp.SecurityOperations;
 import org.encuestame.business.service.social.api.BuzzAPITemplate;
 import org.encuestame.core.config.EnMePlaceHolderConfigurer;
 import org.encuestame.core.social.BuzzAPIOperations;
-import org.encuestame.persistence.dao.IAccountDao;
 import org.encuestame.persistence.domain.social.SocialProvider;
 import org.encuestame.utils.oauth.AccessGrant;
+
 /**
  * Google SignIn Support.
+ *
  * @author Picado, Juan juanATencuestame.org
  * @since Dec 25, 2010 5:57:35 PM
  */
-public class GoogleSignInSocialService extends AbstractSocialSignInConnect<BuzzAPIOperations>{
+public class GoogleSignInSocialService extends
+        AbstractSocialSignInConnect<BuzzAPIOperations> {
 
     /**
      *
      * @throws Exception
      */
 
-    public GoogleSignInSocialService(final AccessGrant accessToken) throws Exception {
-        super(accessToken);
+    public GoogleSignInSocialService(final AccessGrant accessToken,
+            final SecurityOperations securityOperations) throws Exception {
+        super(accessToken, securityOperations);
     }
 
     /**
 
     @Override
     public BuzzAPIOperations getAPISocialProvider() {
-         return new BuzzAPITemplate(getAccessGrant().getAccessToken(),
-                 EnMePlaceHolderConfigurer.getProperty("google.api.key"));
-    }
-
-    @Override
-    public void disconnect() {
-        // TODO Auto-generated method stub
-
+        return new BuzzAPITemplate(getAccessGrant().getAccessToken(),
+                EnMePlaceHolderConfigurer.getProperty("google.api.key"));
     }
 
 }

File encuestame-business/src/main/java/org/encuestame/business/service/social/signin/SocialSignInOperations.java

 package org.encuestame.business.service.social.signin;
 
 import org.encuestame.core.exception.EnMeExistPreviousConnectionException;
-import org.encuestame.core.social.SocialUserProfile;
-import org.encuestame.persistence.dao.IAccountDao;
-import org.encuestame.persistence.domain.security.AccountConnection;
 import org.encuestame.persistence.domain.security.SocialAccount;
-import org.encuestame.persistence.domain.security.UserAccount;
 import org.encuestame.persistence.domain.social.SocialProvider;
+import org.encuestame.persistence.exception.EnMeExpcetion;
 import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
 import org.encuestame.utils.oauth.AccessGrant;
+import org.encuestame.utils.social.SocialUserProfile;
 
 /**
  * Description Class.
  */
 public interface SocialSignInOperations{
 
+
         /**
          *
          * @param accountId
-         * @param requestToken
+         * @param acessGrant
          * @return
          * @throws EnMeExistPreviousConnectionException
          * @throws EnMeNoResultsFoundException
          */
-        AccountConnection reConnect(String accountId, AccessGrant acessGrant) throws EnMeExistPreviousConnectionException, EnMeNoResultsFoundException;
+        SocialAccount reConnect(
+                final String accountId,
+                final AccessGrant acessGrant,
+                final SocialAccount socialAccount)
+                throws EnMeExistPreviousConnectionException,
+                EnMeNoResultsFoundException;
 
 
         /**
 
         /**
          *
-         * @param accountDaoImp
+         * @return
          */
-        void setAccountDaoImp(final IAccountDao accountDaoImp);
+        SocialProvider getProvider();
 
         /**
          *
-         * @param accountId
-         * @param accessToken
-         * @param providerAccountId
          * @return
          */
-        AccountConnection addConnection(
-                final UserAccount account,
-                final SocialAccount socialAccount);
-
-        SocialProvider getProvider();
-
-
         AccessGrant getAccessGrant();
 
         /**
          * Returns true if the member account is connected to this provider, false otherwise.
+         * @throws EnMeExpcetion
          */
-        boolean isConnected(String accountId);
-
-        /**
-         * Sever the connection between the member account and this service provider.
-         * Has no effect if no connection is established to begin with.
-         */
-        void disconnect();
+        SocialAccount isConnected(String accountId) throws EnMeExpcetion;
 
         /**
          * Authenticate a member Account by a connection established with this service provider.
          * Used to support "Sign in using Facebook"-type scenarios, where the access token identifying a connection is available to client code, typically a cookie managed by JavaScript.
          * @throws NoSuchAccountConnectionException no such connection has been established between a member and this service provider
          */
-        AccountConnection findAccountByConnection(String accessToken) throws EnMeNoResultsFoundException;
+        SocialAccount findAccountByConnection(String accessToken) throws EnMeNoResultsFoundException;
 
 }

File 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");

File 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);

File 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("", "","", "");
     }
 

File 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";
 }

File encuestame-core/src/main/java/org/encuestame/core/security/SecurityUtils.java

 import org.encuestame.core.security.details.SocialAuthenticationToken;
 import org.encuestame.core.util.ConvertDomainsToSecurityContext;
 import org.encuestame.persistence.domain.EnMePermission;
-import org.encuestame.persistence.domain.security.AccountConnection;
+import org.encuestame.persistence.domain.security.SocialAccount;
 import org.encuestame.persistence.domain.security.UserAccount;
 import org.springframework.security.core.Authentication;
 import org.springframework.security.core.GrantedAuthority;
      * @param user
      * @return
      */
-    public static EnMeSocialUserAccount convertUserAccountToUserDetails(final AccountConnection connection) {
-        final UserAccount user = connection.getUserAccout();
+    public static EnMeSocialUserAccount convertUserAccountToUserDetails(final SocialAccount connection) {
+        final UserAccount user = connection.getUserOwner();
         final Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
         authorities.addAll(ConvertDomainsToSecurityContext.convertEnMePermission(user.getSecUserPermissions()));
         final EnMeSocialUserAccount enMeSocialUserAccount = new EnMeSocialUserAccount(user.getUsername(),
      * @param password
      * @param socialSignIn
      */
-    public static void socialAuthentication(final AccountConnection accountConnection) {
-        UserAccount account = accountConnection.getUserAccout();
+    public static void socialAuthentication(final SocialAccount accountConnection) {
+        final UserAccount account = accountConnection.getUserOwner();
         log.info("Register SOCIAL LOGIN USER: " + account.getUsername());
         // building granted authorities
         final Collection<GrantedAuthority> authorities = ConvertDomainsToSecurityContext

File encuestame-core/src/main/java/org/encuestame/core/security/service/EnMeSocialAccountUserService.java

 import org.encuestame.core.security.SecurityUtils;
 import org.encuestame.core.security.SocialAccountConnectionException;
 import org.encuestame.persistence.dao.IAccountDao;
-import org.encuestame.persistence.domain.security.AccountConnection;
 import org.encuestame.persistence.domain.security.UserAccount;
 import org.encuestame.persistence.domain.social.SocialProvider;
 import org.encuestame.persistence.exception.EnMeNoResultsFoundException;

File 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

File encuestame-core/src/main/java/org/encuestame/core/social/SocialAPIOperations.java

 package org.encuestame.core.social;
 
 import org.encuestame.utils.TweetPublishedMetadata;
+import org.encuestame.utils.social.SocialUserProfile;
 
 
 

File encuestame-core/src/main/java/org/encuestame/core/social/SocialUserProfile.java

-/*
- ************************************************************************************
- * Copyright (C) 2001-2011 encuestame: system online surveys Copyright (C) 2011
- * 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.social;
-
-import java.util.Date;
-
-/**
- * Social User Profile.
- * @author Picado, Juan juanATencuestame.org
- * @since Apr 25, 2011
- */
-public class SocialUserProfile {
-
-    private String id;
-    private String name;
-    private String firstName;
-    private String lastName;
-    private String screenName;
-    private String username;
-    private String email;
-    private String industry;
-    private String headline;
-    private String location;
-    private String description;
-    private boolean isContributorsEnabled;
-    private String profileImageUrl;
-    private String url;
-    private String profileUrl;
-    private boolean isProtected;
-    private int followersCount;
-    private String profileBackgroundColor;
-    private String profileTextColor;
-    private String profileLinkColor;
-    private String profileSidebarFillColor;
-    private String profileSidebarBorderColor;
-    private boolean profileUseBackgroundImage;
-    private boolean showAllInlineMedia;
-    private int friendsCount;
-    private Date createdAt;
-    private int favouritesCount;
-    private int utcOffset;
-    private String timeZone;
-    private String profileBackgroundImageUrl;
-    private boolean profileBackgroundTiled;
-    private String lang;
-    private int statusesCount;
-    private boolean isGeoEnabled;
-    private boolean isVerified;
-    private