Commits

Anonymous committed 91b31d1

merge

  • Participants
  • Parent commits 0aedc62

Comments (0)

Files changed (41)

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

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

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/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/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

         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.setAllowRepeatedVotes(tweetPoll.getAllowRepatedVotes() == null ? false : tweetPoll.getAllowRepatedVotes());
         //unitTweetPoll.setRelativeTime(tweetPoll.get);
         unitTweetPoll.setHashTags(ConvertDomainBean.convertListHashTagsToBean(new ArrayList<HashTag>(tweetPoll.getHashTags())));
-        if(tweetPoll.getNumbervotes() != null){
-            unitTweetPoll.setTotalVotes(Long.valueOf(tweetPoll.getNumbervotes()));
-        }
+        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/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/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/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)
+     * @param id The identifier of the image
+     * @return A byte[] that contains the requested image
+     * @throws EnMeNoResultsFoundException
+     */
+    @RequestMapping( value = "/picture/profile/{username}/web", method = RequestMethod.GET)
+    @ResponseBody
+    public byte[] getPictureWeb(
+            @PathVariable String username ){
+          return this.getPicture(username, PictureType.WEB);
     }
 }

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

         try {
             //id = filterValue(id);
             slug = filterValue(slug);
-            final TweetPoll tp = getTweetPollService().getTweetPollById(id); //TODO: add slug param.
+            final TweetPoll tp = getTweetPollService().getTweetPollById(id, null); //TODO: add slug param.
             model.addAttribute("tweetpoll", ConvertDomainBean.convertTweetPollToBean(tp));
             final List<TweetPollSwitch> answers = getTweetPollService().getTweetPollSwitch(tp);
             model.addAttribute("answers", answers);

encuestame-mvc/src/main/java/org/encuestame/mvc/view/UserProfileController.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.mvc.view;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.encuestame.mvc.controller.AbstractBaseOperations;
+import org.encuestame.utils.web.UserAccountBean;
+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;
+
+/**
+ * User profile view controller.
+ *
+ * @author Picado, Juan juanATencuestame.org
+ * @since Jul 2, 2011
+ */
+@Controller
+public class UserProfileController extends AbstractBaseOperations {
+
+    private Log log = LogFactory.getLog(this.getClass());
+
+    @RequestMapping(value = "/profile/{username}", method = RequestMethod.GET)
+    public String tweetPollController(
+            final ModelMap model,
+            @PathVariable String username) {
+        username = filterValue(username);
+        final UserAccountBean accountBean = getSecurityService().searchUserByUsername(username);
+        if (accountBean == null) {
+            return "404";
+        } else {
+            log.debug("user "+accountBean);
+            model.put("profile", accountBean);
+            return "profile/view";
+        }
+    }
+}

encuestame-mvc/src/test/java/org/encuestame/mvc/test/json/SocialAccountsJsonControllerTestCase.java

 import org.encuestame.mvc.test.config.AbstractJsonMvcUnitBeans;
 import org.encuestame.persistence.domain.security.Account;
 import org.encuestame.persistence.domain.security.SocialAccount;
+import org.encuestame.persistence.domain.security.UserAccount;
 import org.junit.Before;
 import org.junit.Ignore;
 
       @Before
       public void beforeSocialTest(){
           this.user = createAccount();
-          this.socialTwitterAccount = createDefaultSettedTwitterAccount(this.user);
+          final UserAccount account = createUserAccount("jota 1", user);
+          this.socialTwitterAccount = createDefaultSettedSocialAccount(account);
       }
 }

encuestame-persistence/src/main/java/org/encuestame/persistence/dao/imp/AbstractSocialAccount.java

             //OAuth1
             //connection.setSecretToken(token.getSecret());
             //TODO: pending OAUTH1.
+            log.debug("pending OAUTH1 - OAuth 1 social connection is not available right now.");
         } else if(SocialProvider.getTypeAuth(currentSocialAccount.getAccounType()).equals(TypeAuth.OAUTH2)) {
             //OAuth2
             currentSocialAccount.setAccessToken(accessGrant.getAccessToken());

encuestame-persistence/src/main/java/org/encuestame/persistence/domain/security/UserAccount.java

 import javax.persistence.CascadeType;
 import javax.persistence.Column;
 import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
 import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
      */
     private boolean credentialsNonExpired = true;
 
+    /**
+     *
+     */
     private Set<Project> projects = new HashSet<Project>();
 
+    /**
+     *
+     */
     private Set<Permission> secUserPermissions = new HashSet<Permission>();
 
+
+    /**
+     *  Type of Picture.
+     */
+    private PictureSource pictureSource = PictureSource.GRAVATAR;
+
     /**
      * {@link Group}
      */
         this.sharedProfile = sharedProfile;
     }
 
+
+    /**
+     * @return the pictureSource
+     */
+    @Column(name="picture_source")
+    @Enumerated(EnumType.ORDINAL)
+    public PictureSource getPictureSource() {
+        return this.pictureSource == null ? PictureSource.GRAVATAR : this.pictureSource;
+    }
+
+    /**
+     * @param pictureSource the pictureSource to set
+     */
+    public void setPictureSource(final PictureSource pictureSource) {
+        this.pictureSource = pictureSource;
+    }
+
     /* (non-Javadoc)
      * @see java.lang.Object#toString()
      */
                 + ", userProfilePicture=" + userProfilePicture + ", enabled="
                 + enabled + "]";
     }
+
+    /**
+     * Type of picture.
+     * @author Picado, Juan juanATencuestame.org
+     * @since Jul 3, 2011
+     */
+    public enum PictureSource {
+        GRAVATAR,
+        UPLOADED;
+
+        private PictureSource() {
+        }
+
+        /**
+         * To String.
+         */
+        public String toString() {
+            String pictureSize = "_64";
+            if (this == UPLOADED) { pictureSize = "UPLOADED"; }
+            else if (this == GRAVATAR) { pictureSize = "GRAVATAR"; }
+            return pictureSize;
+        }
+    }
  }

encuestame-persistence/src/main/java/org/encuestame/persistence/exception/EnMeExpcetion.java

 /*
  ************************************************************************************
- * Copyright (C) 2001-2009 encuestame: system online surveys Copyright (C) 2009
+ * Copyright (C) 2001-2011 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
  ************************************************************************************
  */
 package org.encuestame.persistence.exception;
+
+import org.encuestame.utils.exception.EnMeGenericException;
  /**
  * Encuestame Exception.
  * @author Picado, Juan juan@encuestame.org
  * @since May 07, 2009
- * @version $Id$
  */
-public class EnMeExpcetion extends Exception{
+public class EnMeExpcetion extends EnMeGenericException {
 
     /** serial. */
     private static final long serialVersionUID = 7631058192250904935L;

encuestame-persistence/src/test/java/org/encuestame/test/config/AbstractBase.java

      * @param consumerKey
      * @param consumerSecret
      * @param secretToken
-     * @param secUsers
-     * @param twitterAccount
+     * @param userAccount
+     * @param socialProfileUsername
      * @return
      */
     public SocialAccount createSocialAccount(
             final String token,
             final String secretToken,
-            final Account secUsers,
-            final String twitterAccount,
+            final UserAccount userAccount,
+            final String socialProfileUsername,
             final Boolean verified,
             final SocialProvider provider){
-        final SocialAccount socialTwitterAccounts = new SocialAccount();
-        socialTwitterAccounts.setAccessToken(token);
-        socialTwitterAccounts.setSecretToken(secretToken);
-        socialTwitterAccounts.setAccount(secUsers);
+        final SocialAccount socialAccount = new SocialAccount();
+        socialAccount.setAccessToken(token);
+        socialAccount.setSecretToken(secretToken);
+        socialAccount.setAccount(userAccount.getAccount());
+        socialAccount.setUserOwner(userAccount);
         long randomNum = 100 + (int)(Math.random()* 4000);
-        socialTwitterAccounts.setSocialProfileId(String.valueOf(randomNum));
-        socialTwitterAccounts.setVerfied(verified);
-        socialTwitterAccounts.setAccounType(provider);
-        socialTwitterAccounts.setSocialAccountName(twitterAccount+RandomStringUtils.randomAlphanumeric(10));
-        socialTwitterAccounts.setUpgradedCredentials(new Date());
-        socialTwitterAccounts.setAddedAccount(new Date());
-        socialTwitterAccounts.setEmail("email");
-        socialTwitterAccounts.setProfileUrl("urll");
-        socialTwitterAccounts.setRealName("real name");
-        socialTwitterAccounts.setApplicationKey(RandomUtils.nextLong(new Random(50)));
-        socialTwitterAccounts.setRefreshToken("refresh_token_"+RandomStringUtils.randomAlphanumeric(10));
-        socialTwitterAccounts.setType(TypeAuth.OAUTH1);
-        getAccountDao().saveOrUpdate(socialTwitterAccounts);
-        return socialTwitterAccounts;
+        socialAccount.setSocialProfileId(String.valueOf(randomNum)+RandomStringUtils.randomAlphanumeric(10));
+        socialAccount.setVerfied(verified);
+        socialAccount.setAccounType(provider);
+        socialAccount.setSocialAccountName(socialProfileUsername+RandomStringUtils.randomAlphanumeric(10));
+        socialAccount.setUpgradedCredentials(new Date());
+        socialAccount.setAddedAccount(new Date());
+        socialAccount.setEmail("email"+String.valueOf(randomNum));
+        socialAccount.setProfileUrl("url"+String.valueOf(randomNum));
+        socialAccount.setRealName("real name"+String.valueOf(randomNum));
+        socialAccount.setApplicationKey(RandomUtils.nextLong(new Random(50)));
+        socialAccount.setRefreshToken("refresh_token_"+RandomStringUtils.randomAlphanumeric(10));
+        socialAccount.setType(TypeAuth.OAUTH1);
+        getAccountDao().saveOrUpdate(socialAccount);
+        return socialAccount;
      }
 
     /**
      * @param account {@link Account}.
      * @return {@link SocialAccount}.
      */
-    public SocialAccount createDefaultSettedTwitterAccount(final Account account){
+    public SocialAccount createDefaultSettedSocialAccount(final UserAccount account){
         return this.createSocialAccount(
                 getProperty("twitter.test.token"),
                 getProperty("twitter.test.tokenSecret"),
      * @param provider {@link SocialProvider}
      * @return {@link SocialAccount}.
      */
-    public SocialAccount createSocialProviderAccount(final Account account, final SocialProvider provider){
+    public SocialAccount createSocialProviderAccount(final UserAccount account, final SocialProvider provider){
         return this.createSocialAccount(
                 getProperty("twitter.test.token"),
                 getProperty("twitter.test.tokenSecret"),
      * @param account
      * @return
      */
-    public SocialAccount createDefaultSettedVerifiedTwitterAccount(final Account account){
+    public SocialAccount createDefaultSettedVerifiedSocialAccount(final UserAccount account){
         return this.createSocialAccount(
                 getProperty("twitter.test.token"),
                 getProperty("twitter.test.tokenSecret"),

encuestame-persistence/src/test/java/org/encuestame/test/persistence/dao/TestUserDao.java

         this.account = createAccount();
         this.userAccount = createUserAccount("user 1", this.account);
         this.userAccount.setInviteCode(this.inviteCode);
-        this.socialAccount = createDefaultSettedVerifiedTwitterAccount(this.account);
+        this.socialAccount = createDefaultSettedVerifiedSocialAccount(this.userAccount);
         this.question = createQuestion("What day is today?", "");
     }
 
      */
     //@Test
     public void testgetSocialAccount(){
-        final SocialAccount ac = createSocialProviderAccount(this.account, SocialProvider.GOOGLE);
+        final SocialAccount ac = createSocialProviderAccount(this.userAccount, SocialProvider.GOOGLE);
         final SocialAccount ex = getAccountDao().getSocialAccount(ac.getId(), this.account);
         assertEquals("Should be equals", ac.getId(),ex.getId());
         final SocialAccount ex2 = getAccountDao().getSocialAccount(SocialProvider.GOOGLE, ex.getSocialProfileId());

encuestame-utils/pom.xml

                 </configuration>
             </plugin>
             <plugin>
-               <groupId>org.apache.maven.plugins</groupId>
-               <artifactId>maven-jar-plugin</artifactId>
-               <executions>
-                 <execution>
-                   <goals>
-                       <goal>test-jar</goal>
-                    </goals>
-                  </execution>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>test-jar</goal>
+                        </goals>
+                    </execution>
                 </executions>
             </plugin>
         </plugins>
         <resources>
             <resource>
-              <directory>src/main/resources/</directory>
-              <includes>
-                <include>*.*</include>
-              </includes>
-              <filtering>true</filtering>
+                <directory>src/main/resources/</directory>
+                <includes>
+                    <include>*.*</include>
+                </includes>
+                <filtering>true</filtering>
             </resource>
         </resources>
     </build>
             <artifactId>jsr250-api</artifactId>
         </dependency>
         <dependency>
-             <groupId>joda-time</groupId>
-             <artifactId>joda-time</artifactId>
+            <groupId>joda-time</groupId>
+            <artifactId>joda-time</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.codehaus.jackson</groupId>
+            <artifactId>jackson-mapper-asl</artifactId>
         </dependency>
         <dependency>
-           <groupId>org.codehaus.jackson</groupId>
-           <artifactId>jackson-mapper-asl</artifactId>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
         </dependency>
     </dependencies>
 </project>

encuestame-utils/src/main/java/org/encuestame/utils/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.utils;
+
+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-utils/src/main/java/org/encuestame/utils/PictureUtils.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.utils;
+
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.Validate;
+import org.encuestame.utils.exception.EnMeGenericException;
+
+/**
+ * Picture Utils.
+ * @author Picado, Juan juanATencuestame.org
+ * @since Jul 3, 2011
+ */
+public class PictureUtils {
+
+    /**
+     * Gravatar Url.
+     */
+    public static final String GRAVATAR_URL = "http://www.gravatar.com/avatar/";
+
+
+    /**
+     * Get Gravatar.
+     *
+     * @param email
+     * @param size
+     * @return
+     */
+    public static final String getGravatar(final String email, Integer size) {
+        return getUrl(email, size);
+    }
+
+    /**
+     * Get Gravatar URL
+     * @param email
+     * @return
+     */
+    public static String getUrl(final String email, int size) {
+        Validate.notNull(email, "email");
+        final String hash = MD5Utils.md5Hex(email);
+        String params = formatUrlParameters(size);
+        final StringBuffer str = new StringBuffer(PictureUtils.GRAVATAR_URL);
+        str.append(hash);
+        str.append(params);
+        return str.toString();
+    }
+
+    /**
+     * Build gravatar params.
+     * @return
+     */
+    private static String formatUrlParameters(final int size) {
+        final List<String> params = new ArrayList<String>();
+            params.add("s=" + size);
+            params.add("r=" +  Rating.GENERAL_AUDIENCES.getCode());
+        if (params.isEmpty()) {
+            return "";
+        } else {
+            return "?" + StringUtils.join(params.iterator(), "&");
+        }
+    }
+
+    /**
+     * Download the generated gravatar image.
+     * @param email
+     * @return
+     * @throws EnMeGenericException
+     */
+    public static byte[] downloadGravatar(final String email, int size) throws EnMeGenericException {
+        InputStream stream = null;
+        try {
+            URL url = new URL(getUrl(email, size));
+            stream = url.openStream();
+            return IOUtils.toByteArray(stream);
+        } catch (FileNotFoundException e) {
+            return null;
+        } catch (Exception e) {
+            throw new EnMeGenericException(e);
+        } finally {
+            IOUtils.closeQuietly(stream);
+        }
+    }
+
+    /**
+     * Gravatar Rating.
+     * @author Picado, Juan juanATencuestame.org
+     * @since Jul 3, 2011
+     */
+    private enum Rating {
+        GENERAL_AUDIENCES("g"),
+        PARENTAL_GUIDANCE_SUGGESTED("pg"),
+        RESTRICTED("r"),
+        XPLICIT("x");
+        private String code;
+
+        private Rating(String code) {
+            this.code = code;
+        }
+
+        public String getCode() {
+            return code;
+        }
+    }
+}

encuestame-utils/src/main/java/org/encuestame/utils/exception/EnMeGenericException.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.utils.exception;
+
+/**
+ * EnMe generic exception.
+ * @author Picado, Juan juanATencuestame.org
+ * @since Jul 3, 2011
+ */
+public class EnMeGenericException extends Exception {
+
+    /**
+     *
+     */
+    private static final long serialVersionUID = 4773692936156441054L;
+
+    /**
+     * Constructor.
+     */
+    public EnMeGenericException() {
+        super();
+    }
+
+    /**
+    * Exception.
+    * @param message message
+    * @param cause cause
+    */
+   public EnMeGenericException(final String message, final Throwable cause) {
+       super(message, cause);
+
+   }
+   /**
+    * Exception.
+    * @param message message
+    */
+   public EnMeGenericException(final String message) {
+       super(message);
+
+   }
+
+   /**
+    * Exception.
+    * @param cause cause
+    */
+   public EnMeGenericException(final Throwable cause) {
+       super(cause);
+   }
+}

encuestame-war/src/main/webapp/WEB-INF/layouts/standard/header.jsp

 <%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
 <div id="publicLineHeader">
         <div class="logo">
-            <a href="<%=request.getContextPath()%>">
+            <a href="<%=request.getContextPath()%>/">
                 <img alt="logo" src="<%=request.getContextPath()%>/resources/${logo}">
             </a>
         </div>

encuestame-war/src/main/webapp/WEB-INF/views/home/mobile/profile.jsp

+<%@ include file="/WEB-INF/jsp/includes/taglibs.jsp"%>
+<div>Cloud Page</div>
+ <c:forEach items="${hashtags}" var="cloud">
+     <span class="item" style="font-size: ${cloud.size}px;">
+         <a href="<%=request.getContextPath()%>/tag/${cloud.hashTagNa