Commits

Anonymous committed 58f444f

Metrics - Remove duplications code

Comments (0)

Files changed (8)

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

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

      * @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-core/src/main/java/org/encuestame/core/util/ConvertDomainBean.java

         unitTweetPoll.setAllowRepeatedVotes(tweetPoll.getAllowRepatedVotes() == null ? false : tweetPoll.getAllowRepatedVotes());
         //unitTweetPoll.setRelativeTime(tweetPoll.get);
         unitTweetPoll.setHashTags(ConvertDomainBean.convertListHashTagsToBean(new ArrayList<HashTag>(tweetPoll.getHashTags())));
-        unitTweetPoll.setTotalVotes(Long.valueOf(tweetPoll.getNumbervotes()));
+        if(tweetPoll.getNumbervotes() != null){
+            unitTweetPoll.setTotalVotes(Long.valueOf(tweetPoll.getNumbervotes()));
+        }
         unitTweetPoll.setCreatedDateAt(tweetPoll.getCreateDate());
         return unitTweetPoll;
     }

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

         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(), 10, "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(), 10, "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-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/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/test/java/org/encuestame/test/config/AbstractBase.java

 import org.encuestame.persistence.domain.question.QuestionColettion;
 import org.encuestame.persistence.domain.question.QuestionPattern;
 import org.encuestame.persistence.domain.security.Account;
-import org.encuestame.persistence.domain.security.AccountConnection;
 import org.encuestame.persistence.domain.security.Group;
 import org.encuestame.persistence.domain.security.Group.Type;
 import org.encuestame.persistence.domain.security.Permission;
 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/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) {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.