Commits

Paola Morales  committed 43529dc

Progress in ENCUESTAME-187

  • Participants
  • Parent commits 468cad7

Comments (0)

Files changed (6)

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

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

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

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

     private final Integer MAX_HASHTAG = 80;
 
     /** Items max results. **/
-    private final Integer MAX_ITEMS = 80;
+    private final Integer MAX_ITEMS = 10;
     /**
     * Home Controller.
     *
             final IFrontEndService service = getFrontService();
             try {
                 if (view.isEmpty()) {
-                    model.addAttribute("items", service.searchItemsByTweetPoll(period, MAX_ITEMS, request));
+                    model.addAttribute("items", service.searchItemsByTweetPoll(period, 0 ,MAX_ITEMS, request));
                 } else {
                     if ("tweetpoll".equals(view)){
-                        model.addAttribute("items", service.searchItemsByTweetPoll(period, MAX_ITEMS, request));
+                        model.addAttribute("items", service.searchItemsByTweetPoll(period, 0 ,MAX_ITEMS, request));
                     } else if("poll".equals(view)){
-                        model.addAttribute("items", service.searchItemsByPoll(period, MAX_ITEMS));
+                        model.addAttribute("items", service.searchItemsByPoll(period, 0 ,MAX_ITEMS));
                     } else if("survey".equals(view)){
-                        model.addAttribute("items", service.searchItemsByTweetPoll(period, MAX_ITEMS, request));
+                        model.addAttribute("items", service.searchItemsByTweetPoll(period, 0 ,MAX_ITEMS, request));
                     }
                 }
                 model.addAttribute("hashTags", service.getHashTags(MAX_HASHTAG, 0, ""));

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

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