Package it.twiskex.dal.entities

Examples of it.twiskex.dal.entities.SearchNTT


   * another burst of search "pushes" the new search with the updated status
   */
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    SearchNTT currentSearch = null;

    /*
     * if (req.getParameterMap().containsKey(CURRENT_SEARCH)) { Long id =
     * Long.parseLong(req.getParameter(CURRENT_SEARCH)); currentSearch =
     * DALService.ofy().get(SearchNTT.class, id); } else { String hashtag =
     * req.getParameter(HASHTAG); currentSearch = new SearchNTT(hashtag); }
     */
    currentSearch = popSearch();

    if (currentSearch != null) {
      logger.warning("-- Searching for " + currentSearch.getHashtag());
      Twitter twitter = TwitterFactory.getSingleton();
      Query query = new Query(currentSearch.getHashtag());
      query.setCount(100);
      //max o since?
      //that is
      //older than or newer than?
      if (currentSearch.isFirstScan())
        query.setMaxId(currentSearch.getMaxID());
      else
        query.setSinceId(currentSearch.getSinceID());
      QueryResult result;
      try {
        result = twitter.search(query);
        int size = result.getTweets().size();
        logger.warning("-- Going to iterate on "+ size + " tweets");
        if (size==0) {
          logger.warning("-- REACHED "+ size + " tweets");
          return;
        }
        else if(size==1)
        {
          logger.warning("-- REACHED "+ size + " tweets");
          currentSearch.setFirstScan(false);
          pushSearch(currentSearch);
          return;
        }
        List<Status> tweets = result.getTweets();
        for (Status tweet : tweets) {
         
          System.out.println("@" + tweet.getUser().getScreenName()
              + " - " + tweet.getText());
          logger.warning("--  "+ tweet.getText());
          TweetNTT t = new TweetNTT(tweet);
          DALService.ofy().put(t);

          // need to keep track of minimum and maximum id
          long tweetid = tweet.getId();
          if (tweetid < currentSearch.getMaxID())
            currentSearch.setMaxID(tweetid);
          if (tweetid >= currentSearch.getSinceID())
            currentSearch.setSinceID(tweetid);
        }
        logger.warning("-- Storing search "+currentSearch.getHashtag());
        pushSearch(currentSearch);

      } catch (TwitterException e) {
        e.printStackTrace();
      } catch (Exception e) {
View Full Code Here


  }

  private SearchNTT popSearch() {
    com.googlecode.objectify.Query<SearchNTT> s = DALService.ofy()
        .query(SearchNTT.class).order("-lastUpdate").limit(1);
    SearchNTT result = s.get();
    DALService.ofy().delete(result);
    return result;
  }
View Full Code Here

    if (user != null) {
      resp.setContentType("text/plain");
      resp.getWriter().println("Hello, " + user.getNickname());

      if (req.getParameterMap().containsKey("hashtagTxtBox")) {
        SearchNTT currentSearch = null;

        currentSearch = new SearchNTT("#"
            + req.getParameter("hashtagTxtBox"));
        currentSearch.setLastUpdate(new Date());
        Key<SearchNTT> k = DALService.ofy().put(currentSearch);

        resp.setContentType("text/plain");
        resp.getWriter().println(k.getName());
      }
View Full Code Here

  private void doTest() {
    try {
      helper.setUp();
     
      SearchNTT s1 = new SearchNTT("1");
      s1.setLastUpdate(new Date());
      Thread.sleep(2000);
      SearchNTT s2 = new SearchNTT("2");
      s2.setLastUpdate(new Date());
      Thread.sleep(2500);
      SearchNTT s3 = new SearchNTT("3");
      s3.setLastUpdate(new Date());

      DALService.ofy().put(s1);
      DALService.ofy().put(s2);
      DALService.ofy().put(s3);
View Full Code Here

TOP

Related Classes of it.twiskex.dal.entities.SearchNTT

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.