Commits

Juan Carlos Picado Herrera committed 1b5b594 Merge

Merge

Comments (0)

Files changed (35)

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/FrontEndService.java

      */
     public List<TweetPollBean> searchItemsByTweetPoll(
                 final String period,
+                final Integer start,
                 Integer maxResults,
                 final HttpServletRequest request)
                 throws EnMeSearchException{
         } else {
             final SearchPeriods periodSelected = SearchPeriods.getPeriodString(period);
             if(periodSelected.equals(SearchPeriods.TWENTYFOURHOURS)){
-                items.addAll(getFrontEndDao().getTweetPollFrontEndLast24(maxResults));
+                items.addAll(getFrontEndDao().getTweetPollFrontEndLast24(start, maxResults));
             } else if(periodSelected.equals(SearchPeriods.TWENTYFOURHOURS)){
-                items.addAll(getFrontEndDao().getTweetPollFrontEndLast24(maxResults));
+                items.addAll(getFrontEndDao().getTweetPollFrontEndLast24(start, maxResults));
             } else if(periodSelected.equals(SearchPeriods.SEVENDAYS)){
-                items.addAll(getFrontEndDao().getTweetPollFrontEndLast7Days(maxResults));
+                items.addAll(getFrontEndDao().getTweetPollFrontEndLast7Days(start, maxResults));
             } else if(periodSelected.equals(SearchPeriods.THIRTYDAYS)){
-                items.addAll(getFrontEndDao().getTweetPollFrontEndLast30Days(maxResults));
+                items.addAll(getFrontEndDao().getTweetPollFrontEndLast30Days(start, maxResults));
             } else if(periodSelected.equals(SearchPeriods.ALLTIME)){
-                items.addAll(getFrontEndDao().getTweetPollFrontEndAllTime(maxResults));
+                items.addAll(getFrontEndDao().getTweetPollFrontEndAllTime(start, maxResults));
             }
             log.debug("TweetPoll "+items.size());
             results.addAll(ConvertDomainBean.convertListToTweetPollBean(items));
      */
     public List<UnitPoll> searchItemsByPoll(
             final String period,
+            final Integer start,
             Integer maxResults)
             throws EnMeSearchException{
     final List<UnitPoll> results = new ArrayList<UnitPoll>();
     } else {
         final SearchPeriods periodSelected = SearchPeriods.getPeriodString(period);
         if(periodSelected.equals(SearchPeriods.TWENTYFOURHOURS)){
-            items.addAll(getFrontEndDao().getPollFrontEndLast24(maxResults));
+            items.addAll(getFrontEndDao().getPollFrontEndLast24(start, maxResults));
         } else if(periodSelected.equals(SearchPeriods.TWENTYFOURHOURS)){
-            items.addAll(getFrontEndDao().getPollFrontEndLast24(maxResults));
+            items.addAll(getFrontEndDao().getPollFrontEndLast24(start, maxResults));
         } else if(periodSelected.equals(SearchPeriods.SEVENDAYS)){
-            items.addAll(getFrontEndDao().getPollFrontEndLast7Days(maxResults));
+            items.addAll(getFrontEndDao().getPollFrontEndLast7Days(start, maxResults));
         } else if(periodSelected.equals(SearchPeriods.THIRTYDAYS)){
-            items.addAll(getFrontEndDao().getPollFrontEndLast30Days(maxResults));
+            items.addAll(getFrontEndDao().getPollFrontEndLast30Days(start, maxResults));
         } else if(periodSelected.equals(SearchPeriods.ALLTIME)){
-            items.addAll(getFrontEndDao().getPollFrontEndAllTime(maxResults));
+            items.addAll(getFrontEndDao().getPollFrontEndAllTime(start, maxResults));
         }
         log.debug("Poll "+items.size());
         results.addAll(ConvertDomainBean.convertListToPollBean((items)));
      */
     public List<HashTagBean> getHashTags(
               Integer maxResults,
-              final Integer start){
+              final Integer start,
+              final String tagCriteria){
         final List<HashTagBean> hashBean = new ArrayList<HashTagBean>();
         if(maxResults == null){
             maxResults = this.MAX_RESULTS;
         }
         log.debug("Max Results HashTag -----> "+maxResults);
         List<HashTag> tags = new ArrayList<HashTag>();
-        tags.addAll(getHashTagDao().getHashTags(maxResults, start));
+        tags.addAll(getHashTagDao().getHashTags(maxResults, start, tagCriteria));
         log.debug("Hashtag total size ---> "+tags.size());
         hashBean.addAll(ConvertDomainBean.convertListHashTagsToBean(tags));
 
     public List<TweetPollBean> getTweetPollsbyHashTagId(
             final Long hashTagId,
             final Integer limit,
+            final String filter,
             final HttpServletRequest request){
-        final List<TweetPoll> tweetPolls = getTweetPollDao().getTweetpollByHashTagId(hashTagId, limit);
+        final List<TweetPoll> tweetPolls = getTweetPollDao().getTweetpollByHashTagId(hashTagId, limit, filter);
         log.debug("TweetPoll by HashTagId total size ---> "+tweetPolls.size());
         final List<TweetPollBean> tweetPollBean = ConvertDomainBean.convertListToTweetPollBean(tweetPolls);
         for (TweetPollBean tweetPoll : tweetPollBean) {
         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 request
      * @return
      */
-    public List<TweetPollBean> getTweetPollsbyTopRated(
+  /*  public List<TweetPollBean> getTweetPollsbyTopRated(
             final Long hashTagId,
             final Integer limit,
             final HttpServletRequest request){
         }
         return tweetPollBean;
     }
-
+*/
     /**
-     *
+     * Get hashTag relevance.
      * @param hashTagId
      * @param limit
      * @return
     public Integer getHashTagRelevance(final Long hashTagId, final Integer limit){
         final Integer totalRelTweetPoll;
         final Integer relevance;
-        final List<TweetPoll> tweetPolls = getTweetPollDao().getTweetpollByHashTagId(hashTagId, limit);
+        final List<TweetPoll> tweetPolls = getTweetPollDao().getTweetpollByHashTagId(hashTagId, limit, "");
         totalRelTweetPoll = tweetPolls.size();
         relevance = totalRelTweetPoll;
         //TODO:Pending count relevance hashtags for polls and surveys.

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/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/imp/IFrontEndService.java

      */
      List<TweetPollBean> searchItemsByTweetPoll(
             final String period,
+            final Integer start,
             Integer maxResults,
             final HttpServletRequest request)
             throws EnMeSearchException;
       */
     List<UnitPoll> searchItemsByPoll(
              final String period,
+             final Integer start,
              Integer maxResults)
              throws EnMeSearchException;
 
      * List Hash tags
      * @param maxResults
      * @param start
+     * @param tagCriteria
      * @return
      */
     List<HashTagBean> getHashTags(
             Integer maxResults,
-            final Integer start);
+            final Integer start,
+            final String tagCriteria);
 
     /**
      * Get hashTag item.
      * @param request
      * @return
      */
-    List<TweetPollBean> getTweetPollsbyHashTagId(final Long hashTagId, final Integer limit, final HttpServletRequest request);
+    List<TweetPollBean> getTweetPollsbyHashTagId(final Long hashTagId, final Integer limit, final String filter, final HttpServletRequest request);
 
     /**
      * Get TweetPolls by top rated.
      * @param request
      * @return
      */
-    List<TweetPollBean> getTweetPollsbyTopRated(final Long hashTagId, final Integer limit, final HttpServletRequest request);
+    //List<TweetPollBean> getTweetPollsbyTopRated(final Long hashTagId, final Integer limit, final HttpServletRequest request);
 }

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

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

encuestame-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-mvc/src/main/java/org/encuestame/mvc/controller/FileUploadController.java

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

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

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

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

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

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

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

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

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

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

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

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

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

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

 import java.io.FileNotFoundException;
 import java.io.IOException;
 
+import org.apache.log4j.Logger;
 import org.encuestame.business.service.PictureService.PictureType;
 import org.encuestame.mvc.controller.AbstractBaseOperations;
 import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
+import org.encuestame.utils.exception.EnMeGenericException;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 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.
      */
+<<<<<<< .merge_file_Ucb9vq
     @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){
+>>>>>>> .merge_file_B7Gwiq
         byte[] bytes = {};
         username = filterValue(username);
         try {
-            bytes = getPictureService().getProfilePicture(username, PictureType.THUMBNAIL);
+            bytes = getPictureService().getProfilePicture(username, pictureType);
         } catch (FileNotFoundException e) {
+<<<<<<< .merge_file_Ucb9vq
             // if the user doesn't have picture.
 
+=======
+            log.error("file not found "+e);
+>>>>>>> .merge_file_B7Gwiq
         } 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-persistence/src/main/java/org/encuestame/persistence/dao/IFrontEndDao.java

      * @param maxResults max results
      * @return list of tweetPoll.
      */
-    List<TweetPoll> getTweetPollFrontEndLast30Days(final Integer maxResults);
+    List<TweetPoll> getTweetPollFrontEndLast30Days(final Integer start, final Integer maxResults);
 
     /**
      * Get TweetPoll Last 7 Days
      * @param maxResults max results
      * @return list of tweetPoll.
      */
-    List<TweetPoll> getTweetPollFrontEndLast7Days(final Integer maxResults);
+    List<TweetPoll> getTweetPollFrontEndLast7Days(final Integer start, final Integer maxResults);
 
     /**
      * Get TweetPoll Last 24 Hours.
      * @param maxResults max results
      * @return list of tweetPoll.
      */
-    List<TweetPoll> getTweetPollFrontEndLast24(final Integer maxResults);
+    List<TweetPoll> getTweetPollFrontEndLast24(final Integer start, final Integer maxResults);
 
     /**
      * Get Poll Last 24 Hours.
      * @param maxResults max results
      * @return list of tweetPoll.
      */
-    List<Poll> getPollFrontEndLast24(final Integer maxResults);
+    List<Poll> getPollFrontEndLast24(final Integer start, final Integer maxResults);
 
     /**
      * Get Poll Last 7 Days
      * @param maxResults max results
      * @return list of tweetPoll.
      */
-    List<Poll> getPollFrontEndLast7Days(final Integer maxResults);
+    List<Poll> getPollFrontEndLast7Days(final Integer start, final Integer maxResults);
 
     /**
      * Get Poll Last 30 Days
      * @param maxResults max results
      * @return list of tweetPoll.
      */
-    List<Poll> getPollFrontEndLast30Days(final Integer maxResults);
+    List<Poll> getPollFrontEndLast30Days(final Integer start, final Integer maxResults);
 
     /**
      * Get Poll on All Time.
      * @param maxResults max results
      * @return list of tweetPoll.
      */
-    List<Poll> getPollFrontEndAllTime(final Integer maxResults);
+    List<Poll> getPollFrontEndAllTime(final Integer start, final Integer maxResults);
 
     /**
      * Get TweetPoll all time.
      * @param maxResults max results
      * @return list of tweetPoll.
      */
-    List<TweetPoll> getTweetPollFrontEndAllTime(final Integer maxResults);
+    List<TweetPoll> getTweetPollFrontEndAllTime(final Integer start, final Integer maxResults);
 
 }

encuestame-persistence/src/main/java/org/encuestame/persistence/dao/IHashTagDao.java

      * Get hashTags.
      * @param maxResults
      * @param start
+     * @param tagCriteria
      * @return
      */
-    List<HashTag> getHashTags( final Integer maxResults,final Integer start);
+    List<HashTag> getHashTags( final Integer maxResults,final Integer start, final String tagCriteria);
 }

encuestame-persistence/src/main/java/org/encuestame/persistence/dao/ITweetPoll.java

      */
     List<TweetPollSwitch> getAnswerTweetSwitch(final QuestionAnswer questionAnswer);
 
-    /**
-     * Get TweetPoll by hashTag id.
-     * @param hashTag
-     * @param limit
-     * @return
-     */
-    List getTweetpollByHashTagId(final Long hashTag,  final Integer limit);
-
-    /**
+     /**
      * Get tweetPoll by top rated.
      * @param hashTagId
      * @param limit
+     * @param limit
      * @return
      */
-    List<TweetPoll> getTweetpollByTopRated(final Long hashTagId, final Integer limit);
+   List<TweetPoll> getTweetpollByHashTagId(final Long hashTagId, final Integer limit, final String filterby);
 
 }

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

      * @return list of tweetPoll.
      */
     @SuppressWarnings("unchecked")
-    public final List<TweetPoll> getTweetPollFrontEnd(Integer period, final Integer maxResults, final Integer firstResult){
+    public final List<TweetPoll> getTweetPollFrontEnd(Integer period, final Integer start, final Integer maxResults, final Integer firstResult){
         final DetachedCriteria criteria = DetachedCriteria.forClass(TweetPoll.class);
             criteria.createAlias("question", "question");
         if (period != null) {
             criteria.add(Restrictions.between("createDate", startDate, endDate));
         }
         criteria.add(Restrictions.eq("publishTweetPoll", Boolean.TRUE)); //should be published
-        return getHibernateTemplate().findByCriteria(criteria, firstResult, maxResults);
+        return (List<TweetPoll>) filterByMaxorStart(criteria, maxResults, start);
+        //return getHibernateTemplate().findByCriteria(criteria, firstResult, maxResults);
     }
 
     /**
      * @return list of poll.
      */
     @SuppressWarnings("unchecked")
-    public final List<Poll> getPollFrontEnd(final Integer period, final Integer maxResults, final Integer firstResult){
+    public final List<Poll> getPollFrontEnd(final Integer period, final Integer start, final Integer maxResults, final Integer firstResult){
         final DetachedCriteria criteria = DetachedCriteria.forClass(Poll.class);
         criteria.createAlias("question", "question");
         if(period != null){
             criteria.add(Restrictions.between("createdAt", Calendar.getInstance().getTime(), hi.getTime()));
         }
         criteria.add(Restrictions.eq("publish", Boolean.TRUE)); //should be published
-        return getHibernateTemplate().findByCriteria(criteria, firstResult, maxResults);
+        return (List<Poll>) filterByMaxorStart(criteria, maxResults, start);
+        //return getHibernateTemplate().findByCriteria(criteria, firstResult, maxResults);
     }
 
     /**
      * @param maxResults max results
      * @return list of tweetPoll.
      */
-    public final List<TweetPoll> getTweetPollFrontEndLast24(final Integer maxResults){
-        return this.getTweetPollFrontEnd(this.PERIOD_24, maxResults, this.WITHOUT_FIRST_RESULTS);
+    public final List<TweetPoll> getTweetPollFrontEndLast24(final Integer start, final Integer maxResults){
+        return this.getTweetPollFrontEnd(this.PERIOD_24, start, maxResults, this.WITHOUT_FIRST_RESULTS);
     }
 
     /**
      * @param maxResults max results
      * @return list of tweetPoll.
      */
-    public final List<TweetPoll> getTweetPollFrontEndLast7Days(final Integer maxResults) {
-        return this.getTweetPollFrontEnd(this.PERIOD_7_DAYS , maxResults, this.WITHOUT_FIRST_RESULTS);
+    public final List<TweetPoll> getTweetPollFrontEndLast7Days(final Integer start, final Integer maxResults) {
+        return this.getTweetPollFrontEnd(this.PERIOD_7_DAYS , start, maxResults, this.WITHOUT_FIRST_RESULTS);
     }
 
     /**
      * @param maxResults max results
      * @return list of tweetPoll.
      */
-    public final List<TweetPoll> getTweetPollFrontEndLast30Days(final Integer maxResults){
-        return this.getTweetPollFrontEnd(this.PERIOD_30_DAYS , maxResults, this.WITHOUT_FIRST_RESULTS);
+    public final List<TweetPoll> getTweetPollFrontEndLast30Days(final Integer start, final Integer maxResults){
+        return this.getTweetPollFrontEnd(this.PERIOD_30_DAYS , start, maxResults, this.WITHOUT_FIRST_RESULTS);
     }
 
     /**
      * @param maxResults max results
      * @return list of tweetPoll.
      */
-    public final List<TweetPoll> getTweetPollFrontEndAllTime(final Integer maxResults){
-        return this.getTweetPollFrontEnd(this.PERIOD_ALL , maxResults, this.WITHOUT_FIRST_RESULTS);
+    public final List<TweetPoll> getTweetPollFrontEndAllTime(final Integer start, final Integer maxResults){
+        return this.getTweetPollFrontEnd(this.PERIOD_ALL , start, maxResults, this.WITHOUT_FIRST_RESULTS);
     }
 
     /**
      * @param maxResults max results
      * @return list of tweetPoll.
      */
-    public final  List<Poll> getPollFrontEndLast24(final Integer maxResults){
-        return this.getPollFrontEnd(this.PERIOD_24, maxResults, this.WITHOUT_FIRST_RESULTS);
+    public final  List<Poll> getPollFrontEndLast24(final Integer start, final Integer maxResults){
+        return this.getPollFrontEnd(this.PERIOD_24, start, maxResults, this.WITHOUT_FIRST_RESULTS);
     }
 
     /**
      * @param maxResults max results
      * @return list of tweetPoll.
      */
-    public List<Poll> getPollFrontEndLast7Days(final Integer maxResults){
-        return this.getPollFrontEnd(this.PERIOD_7_DAYS , maxResults, this.WITHOUT_FIRST_RESULTS);
+    public List<Poll> getPollFrontEndLast7Days(final Integer start, final Integer maxResults){
+        return this.getPollFrontEnd(this.PERIOD_7_DAYS ,start, maxResults, this.WITHOUT_FIRST_RESULTS);
     }
 
     /**
      * @param maxResults max results
      * @return list of tweetPoll.
      */
-    public final List<Poll> getPollFrontEndLast30Days(final Integer maxResults){
-        return this.getPollFrontEnd(this.PERIOD_30_DAYS , maxResults, this.WITHOUT_FIRST_RESULTS);
+    public final List<Poll> getPollFrontEndLast30Days(final Integer start, final Integer maxResults){
+        return this.getPollFrontEnd(this.PERIOD_30_DAYS , start, maxResults, this.WITHOUT_FIRST_RESULTS);
     }
 
     /**
      * @param maxResults max results
      * @return list of tweetPoll.
      */
-    public final List<Poll> getPollFrontEndAllTime(final Integer maxResults){
-        return this.getPollFrontEnd(this.PERIOD_ALL , maxResults, this.WITHOUT_FIRST_RESULTS);
+    public final List<Poll> getPollFrontEndAllTime(final Integer start, final Integer maxResults){
+        return this.getPollFrontEnd(this.PERIOD_ALL , start, maxResults, this.WITHOUT_FIRST_RESULTS);
     }
 
     /**

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

     */
     @SuppressWarnings("unchecked")
     public List<HashTag> getHashTags( final Integer maxResults,
-                    final Integer start){
+                    final Integer start,
+                    final String tagCriteria){
         final DetachedCriteria criteria = DetachedCriteria.forClass(HashTag.class);
-        criteria.add(Restrictions.gt("hits", 0L));//review
-        criteria.addOrder(Order.desc("hits"));
-        criteria.addOrder(Order.asc("hashTag"));
+        if(tagCriteria.equals("hashTagsCloud")){
+            criteria.add(Restrictions.gt("hits", 0L));//review
+        }
+        else {
+            criteria.addOrder(Order.desc("hits"));
+            criteria.addOrder(Order.asc("hashTag"));
+        }
         return (List<HashTag>) filterByMaxorStart(criteria, maxResults, start);
     }
 

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

 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.encuestame.persistence.dao.ITweetPoll;
+import org.encuestame.persistence.dao.SearchPeriods;
 
 import org.encuestame.persistence.domain.HashTag;
 import org.encuestame.persistence.domain.question.QuestionAnswer;
      * @see org.encuestame.persistence.dao.ITweetPoll#getTweetpollByHashTagName(java.lang.String)
      */
     @SuppressWarnings("unchecked")
-    public List<TweetPoll> getTweetpollByHashTagId(final Long hashTagId, final Integer limit){
+    public List<TweetPoll> getTweetpollByHashTagId(final Long hashTagId, final Integer limit, final String filterby){
          final DetachedCriteria detached = DetachedCriteria.forClass(TweetPoll.class)
         .createAlias("hashTags", "hashTags")
         .setProjection(Projections.id())
               .add(Restrictions.in("hash.hashTagId", new Long[] {hashTagId}))));
         final DetachedCriteria criteria = DetachedCriteria.forClass(TweetPoll.class, "tweetPoll");
         criteria.add(Subqueries.propertyIn("tweetPoll.tweetPollId", detached));
-        criteria.addOrder(Order.desc("tweetPoll.createDate"));
+        if(filterby.equals("hashtag")){
+            criteria.addOrder(Order.desc("tweetPoll.createDate"));
+        }
+        else if (filterby.equals("hashtagRated")){
+            criteria.addOrder(Order.desc("numbervotes"));
+        }
         return getHibernateTemplate().findByCriteria(criteria, 0, limit);
     }
-
-
-    @SuppressWarnings("unchecked")
-       public List<TweetPoll> getTweetpollByTopRated(final Long hashTagId, final Integer limit){
-           final DetachedCriteria detached = DetachedCriteria.forClass(TweetPoll.class)
-           .createAlias("hashTags", "hashTags")
-           .setProjection(Projections.id())
-           .add(Subqueries.propertyIn("hashTags.hashTagId",
-           DetachedCriteria.forClass(HashTag.class, "hash")
-                 .setProjection(Projections.id())
-                 .add(Restrictions.in("hash.hashTagId", new Long[] {hashTagId}))));
-           final DetachedCriteria criteria = DetachedCriteria.forClass(TweetPoll.class, "tweetPoll");
-           criteria.add(Subqueries.propertyIn("tweetPoll.tweetPollId", detached));
-           criteria.addOrder(Order.desc("numbervotes"));
-           return getHibernateTemplate().findByCriteria(criteria, 0, limit);
-       }
-
-
-    /**
-     *
-     * @return
-     */
-    public TweetPoll getNumberVotes(final Long tweetPollId){
-        final DetachedCriteria criteria = DetachedCriteria.forClass(TweetPoll.class);
-        criteria.add(Restrictions.eq("tweetPollId", tweetPollId));
-        return (TweetPoll) DataAccessUtils.uniqueResult(getHibernateTemplate().findByCriteria(criteria));
-    }
 }

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

 import org.encuestame.persistence.domain.tweetpoll.TweetPollResult;
 import org.encuestame.persistence.domain.tweetpoll.TweetPollSwitch;
 import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
-import org.encuestame.utils.oauth.AccessGrant;
-import org.encuestame.utils.oauth.OAuth1Token;
 import org.hibernate.search.FullTextSession;
 import org.hibernate.search.Search;
 import org.springframework.beans.factory.annotation.Autowired;

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

 
         final int limit = 20;
         final int start = 0;
-        final List<HashTag> results = getHashTagDao().getHashTags(limit, start);
+        final List<HashTag> results = getHashTagDao().getHashTags(limit, start, "");
         Assert.assertNotNull(results);
         assertEquals("Should be equals", 4, results.size());
 

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

         final Calendar calendar2 = Calendar.getInstance();
         System.out.println("SECOND CALENDAR--"+ calendar2.getTime());
 
-        final List<TweetPoll> tweetPolls = getTweetPoll().getTweetpollByHashTagId(this.hashTag1.getHashTagId(), limit);
+        final List<TweetPoll> tweetPolls = getTweetPoll().getTweetpollByHashTagId(this.hashTag1.getHashTagId(), limit, "hashtag");
         assertEquals("Should be equals", 1, tweetPolls.size());
         final HashTag hashtag2 = createHashTag("paola");
         final HashTag hashtag3 = createHashTag("juan");
         final HashMap<Integer, RelativeTimeEnum> hm3 = DateUtil.getRelativeTime(tweetPoll1.getCreateDate());
         System.out.println("HM 3 ---------->"+hm3);
 
-        final List<TweetPoll> tweetPolls2 = getTweetPoll().getTweetpollByHashTagId(this.hashTag1.getHashTagId(), limit);
+        final List<TweetPoll> tweetPolls2 = getTweetPoll().getTweetpollByHashTagId(this.hashTag1.getHashTagId(), limit, "hashtag");
         System.out.println("------------- HASH TAG NAME---------> " + this.hashTag1.getHashTag());
 
 
 
 
 
-        final List<TweetPoll> tweetPolls2 = getTweetPoll().getTweetpollByTopRated(this.hashTag1.getHashTagId(), limit);
+        final List<TweetPoll> tweetPolls2 = getTweetPoll().getTweetpollByHashTagId(this.hashTag1.getHashTagId(), limit, "hashtagRated");
         System.out.println("------------- HASH TAG NAME---------> " + this.hashTag1.getHashTag());
 
         for (TweetPoll tweetPoll : tweetPolls2) {

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)) {