Package talkfeed.data

Examples of talkfeed.data.Blog


   
    //get user
    User user = dataManager.getUserFromId(pm , id);
   
    //check if blog exists
    Blog blog = blogManager.getOrCreateSource(link);
   
    if (blog == null){
      //blog not found or not avaiable
      TalkService.sendMessage(user.getId(),"blog not found ! :(");
      return;
    }
   
    //check subscription
    Subscription sub = dataManager.getSubscription(pm , user, blog);
   
    //create new subscription
    if (sub == null){
      sub = new Subscription();
      sub.setBlogKey(blog.getKey());
      sub.setPriority(0);
      sub.setUserKey(user.getKey());
      sub.setLastProcessDate(new Date());
      sub.setLatestEntryNotifiedDate(new Date());
     
View Full Code Here


      @SuppressWarnings("unchecked")
      List<Subscription> subs = (List<Subscription>) qSub.execute(key);

      for (Subscription sub : subs) {
        try {
          Blog b = pm.getObjectById(Blog.class, sub.getBlogKey());

          blogs.add(b);

        } catch (JDOObjectNotFoundException ex) {
          // blog deleted ! bad !!
View Full Code Here

    q.setFilter("blogKey == bk");
    q.declareParameters("com.google.appengine.api.datastore.Key bk");

    List<BlogEntry> list = new ArrayList<BlogEntry>(15);

    Blog blog = pm.getObjectById(Blog.class, blogId);

    @SuppressWarnings("unchecked")
    Collection<BlogEntry> col = (Collection<BlogEntry>) q.execute(blog
        .getKey());

    for (BlogEntry be : col) {
      list.add(be);
    }
View Full Code Here

   
    DataManager dm = DataManagerFactory.getInstance();
    PersistenceManager pm = dm.newPersistenceManager();
   
    //find if blog already exists in database
    Blog blog = dm.getBlogFromLink(pm , link);

    if (blog == null) {
      //blog does not exist : load content to parse it
      String content = DocumentLoader.loadPage(link);
      String rss = null;
     
      //test if given link is already RSS or Atom FEED
      if (FeedManager.isFeed(content)){
        rss = link;
      }else {
        //extract RSS link from page content
        rss = TextTools.extractRssFromPage(content);
      }

      //test if rss information hase been found
      if (rss != null){
        //check again if blog exists with given link
        blog = dm.getBlogFromLink(pm , rss);
        //actually create new blog in database
        if (blog == null){
          blog = new Blog();
          blog.setLatestEntry(calLongTime.getTime());
          blog.setNextUpdate(now);
          blog.setLink(link);
          blog.setRss(rss);
          pm.currentTransaction().begin();
          pm.makePersistent(blog);
          pm.currentTransaction().commit();
        }
      } else {
View Full Code Here

   
    DataManager dm = DataManagerFactory.getInstance();
    PersistenceManager pm = dm.newPersistenceManager();
   
    //find blog
    Blog blog = pm.getObjectById(Blog.class,id);
   
    //check if blog has any updates
    BlogUpdateResult result = null;
   
    //fetch channel on the web via RSS
    Channel chan = FeedManager.loadRss(blog.getRss());
   
    if (chan != null){
      //update blog. Returns true if new items were added
      result = updateBlog(pm, blog, chan);
     
      //test url and title and correct if worng
      if (chan.getLink() != null && !chan.getLink().equalsIgnoreCase(blog.getLink())){
        blog.setLink(chan.getLink());
      }
     
      if (chan.getTitle() != null && !chan.getTitle().equalsIgnoreCase(blog.getTitle())){
        blog.setTitle(chan.getTitle());
      }
    }
   
    //Set last post entry date to blog
    if (result != null && result.isUpdate())
      blog.setLatestEntry(result.getLastestEntryDate());
   
    String messageLog = "";
   
    //build nextUpdate
    //if no new update : increase interval
    int newInterval = blog.getRefreshInterval();
    if (result != null && result.isUpdate()){
      newInterval = newInterval / 2;
      messageLog = "Blog updated [" + blog.getTitle() + "]";
    } else {
      newInterval = newInterval * 2;
      messageLog = "No new update [" + blog.getTitle() + "]";
    }
   
    if (newInterval <= MIN_INTERVAL) newInterval = MIN_INTERVAL;
    if (newInterval > MAX_INTERVAL) newInterval = MAX_INTERVAL;
   
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.MINUTE, newInterval);
   
    blog.setRefreshInterval(newInterval);
    blog.setNextUpdate(cal.getTime());
   
    pm.flush();
    pm.close();
   
    BlogCache.setNextUpdate(blog.getKey().getId(), newInterval);
   
    Logger.getLogger("updateBlog").log(Level.INFO,
        messageLog);
  }
View Full Code Here

      for (Subscription sub : subs) {
        // update is done ?
        boolean updateDone = false;

        // fetch blog
        Blog blog = (Blog) this.currentManager.getObjectById(
            Blog.class, sub.getBlogKey());

        // compare dates bet blog last entry and subscription update
        if (blog.getLatestEntry().after(sub.getLatestEntryNotifiedDate())) {
          Logger.getLogger("UserService").info(
              "user " + user.getId() + " present. Try notify : "
                  + blog.getTitle());

          // find next entry
          BlogEntry nextEntry = this.findNextEntry(sub);

          if (nextEntry == null) {
View Full Code Here

    if (user == null) {
      qUser.closeAll();
      return false;
    }

    Blog blog = pm.getObjectById(Blog.class, new Long(blogId));

    Query q = pm.newQuery(Subscription.class);
    q.setFilter("userKey == uid && blogKey == bid");
    q.declareParameters("com.google.appengine.api.datastore.Key uid, com.google.appengine.api.datastore.Key bid");
    q.setRange(0, 1);

    @SuppressWarnings("unchecked")
    List<Subscription> list = (List<Subscription>) q.execute(user.getKey(),
        blog.getKey());

    if (list.size() > 0) {
      pm.currentTransaction().begin();
      pm.deletePersistent(list.get(0));
      pm.currentTransaction().commit();
View Full Code Here

    String key = "title" + String.valueOf(k.getId());

    Object title = CacheService.get(key);

    if (title == null) {
      Blog b = this.currentManager.getObjectById(Blog.class, k);
      title = b.getTitle();
      if (title != null)
        CacheService.put(key, title);
      else
        return "";
    }
View Full Code Here

   * @return
   */
  public static Blog getBlog(long id){
    String key = "BLOG_" + id;
   
    Blog blog = (Blog) CacheService.get(key);
   
    if (blog == null){
      PersistenceManager pm = DataManagerFactory.getInstance().newPersistenceManager();
     
      blog = pm.getObjectById(Blog.class , id);
View Full Code Here

    List<Subscription> subs = (List<Subscription>) q.execute(u.getKey());
   
    int n = 0;
    StringBuilder sb = new StringBuilder();
    for(Subscription s : subs){
      Blog b = pm.getObjectById(Blog.class, s.getBlogKey());
     
      sb.append(++n);
      if(b.getTitle() != null){
        sb.append(" -[");
        sb.append(b.getTitle());
        sb.append("] ");
      } else {
        sb.append(" - ");
      }
      sb.append(b.getLink());
      sb.append("\r\n");
      //list.add(sb.toString());
    }
   
    pm.close();
View Full Code Here

TOP

Related Classes of talkfeed.data.Blog

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.