Commits

Anonymous committed 468cad7

Remove duplicate code

  • Participants
  • Parent commits 91b31d1

Comments (0)

Files changed (8)

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

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

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

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

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

File 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> tweetPollbyTags = service.getTweetPollsbyHashTagId(tag.getId(), 10, "hashtag", request);
+            final List<TweetPollBean> tweetPollbyTags = service.getTweetPollsbyHashTagId(tag.getId(), LIMIT_HASHTAG, "hashtag", request);
             log.debug("TweetPolls by HashTag Id ---> "+ tweetPollbyTags.size());
 
-            final List<TweetPollBean> tweetPollbyRated = service.getTweetPollsbyHashTagId(tag.getId(), 10, "hashtagRated", request);
+            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";

File 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 = 80;
     /**
     * Home Controller.
     *
             final IFrontEndService service = getFrontService();
             try {
                 if (view.isEmpty()) {
-                    model.addAttribute("items", service.searchItemsByTweetPoll(period, 100, request));
+                    model.addAttribute("items", service.searchItemsByTweetPoll(period, MAX_ITEMS, request));
                 } else {
                     if ("tweetpoll".equals(view)){
-                        model.addAttribute("items", service.searchItemsByTweetPoll(period, 100, request));
+                        model.addAttribute("items", service.searchItemsByTweetPoll(period, MAX_ITEMS, request));
                     } else if("poll".equals(view)){
-                        model.addAttribute("items", service.searchItemsByPoll(period, 20));
+                        model.addAttribute("items", service.searchItemsByPoll(period, MAX_ITEMS));
                     } else if("survey".equals(view)){
-                        model.addAttribute("items", service.searchItemsByTweetPoll(period, 100, request));
+                        model.addAttribute("items", service.searchItemsByTweetPoll(period, 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";

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

File 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"));
-        return (List<HashTag>) filterByMaxorStart(criteria, maxResults, start);
-    }
-
-    @SuppressWarnings("unchecked")
-    public List<HashTag> getHashTagsCloud( final Integer maxResults,
-                    final Integer start){
-        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);
     }
 

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