roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r394784 - in /incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate: HibernatePlanetManagerImpl.java HibernateRollerImpl.java HibernateRollerPlanetManagerImpl.java
Date Mon, 17 Apr 2006 22:03:06 GMT
Author: agilliland
Date: Mon Apr 17 15:03:04 2006
New Revision: 394784

URL: http://svn.apache.org/viewcvs?rev=394784&view=rev
Log:
reorganizing the planet local feed fetching which had been broken by new backend.

renamed getNewEntriesRemote to just getNewEntries() in planet manager.
defined a new RollerPlanetManager which overloads the default getNewEntries() method in planet
manager with local fetching strategy.
made RollerPlanetManager the default planet manager impl.


Added:
    incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernateRollerPlanetManagerImpl.java
Modified:
    incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernatePlanetManagerImpl.java
    incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernateRollerImpl.java

Modified: incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernatePlanetManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernatePlanetManagerImpl.java?rev=394784&r1=394783&r2=394784&view=diff
==============================================================================
--- incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernatePlanetManagerImpl.java
(original)
+++ incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernatePlanetManagerImpl.java
Mon Apr 17 15:03:04 2006
@@ -34,7 +34,6 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
-import org.apache.commons.lang.StringUtils;
 import org.hibernate.Criteria;
 import org.hibernate.HibernateException;
 import org.hibernate.Query;
@@ -43,22 +42,17 @@
 import org.hibernate.criterion.Order;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.velocity.VelocityContext;
 import org.roller.RollerException;
 import org.roller.config.RollerConfig;
 import org.roller.config.RollerRuntimeConfig;
-import org.roller.model.PagePluginManager;
 import org.roller.model.PlanetManager;
 import org.roller.model.Roller;
-import org.roller.model.UserManager;
-import org.roller.model.WeblogManager;
+import org.roller.model.RollerFactory;
 import org.roller.pojos.PlanetConfigData;
 import org.roller.pojos.PlanetEntryData;
 import org.roller.pojos.PlanetGroupData;
 import org.roller.pojos.PlanetGroupSubscriptionAssoc;
 import org.roller.pojos.PlanetSubscriptionData;
-import org.roller.pojos.WeblogEntryData;
-import org.roller.pojos.WebsiteData;
 import org.roller.util.rome.DiskFeedInfoCache;
 
 
@@ -71,15 +65,15 @@
     
     protected static final String NO_GROUP = "zzz_nogroup_zzz";
     
-    private Roller roller = null;
     private HibernatePersistenceStrategy strategy = null;
     private String localURL = null;
     private Map lastUpdatedByGroup = new HashMap();
     
     
-    public HibernatePlanetManagerImpl(HibernatePersistenceStrategy strat, Roller roller)
{
+    public HibernatePlanetManagerImpl(HibernatePersistenceStrategy strat) {
+        
         this.strategy = strat;
-        this.roller = roller;
+        
         // TODO: this is bad.  this property should be in the planet config.
         localURL = RollerRuntimeConfig.getProperty("site.absoluteurl");
     }
@@ -346,6 +340,8 @@
     
     public void refreshEntries() throws RollerException {
         
+        Roller roller = RollerFactory.getRoller();
+        
         Date now = new Date();
         long startTime = System.currentTimeMillis();
         PlanetConfigData config = getConfiguration();
@@ -410,14 +406,15 @@
             sub = this.getSubscriptionById(sub.getId());
             
             // Fetch latest entries for each subscription
-            Set newEntries = null;
-            int count = 0;
-            if (!StringUtils.isEmpty(localURL) && sub.getFeedUrl().startsWith(localURL))
{
-                newEntries = getNewEntriesLocal(sub, feedFetcher, feedInfoCache);
-            } else {
-                newEntries = getNewEntriesRemote(sub, feedFetcher, feedInfoCache);
-            }
-            count = newEntries.size();
+//            Set newEntries = null;
+//            int count = 0;
+//            if (!StringUtils.isEmpty(localURL) && sub.getFeedUrl().startsWith(localURL))
{
+//                newEntries = getNewEntriesLocal(sub, feedFetcher, feedInfoCache);
+//            } else {
+//                newEntries = getNewEntriesRemote(sub, feedFetcher, feedInfoCache);
+//            }
+            Set newEntries = this.getNewEntries(sub, feedFetcher, feedInfoCache);
+            int count = newEntries.size();
             
             log.debug("   Entry count: " + count);
             if (count > 0) {
@@ -441,105 +438,9 @@
     }
     
     
-    protected Set getNewEntriesLocal(PlanetSubscriptionData sub,
-            FeedFetcher feedFetcher, FeedFetcherCache feedInfoCache)
-            throws RollerException {
-        
-        Set newEntries = new TreeSet();
-        try {
-            // for local feeds, sub.author = website.handle
-            if (sub.getAuthor()!=null && sub.getFeedUrl().endsWith(sub.getAuthor()))
{
-                
-                log.debug("Getting LOCAL feed "+sub.getFeedUrl());
-                
-                // get corresponding website object
-                UserManager usermgr = roller.getUserManager();
-                WebsiteData website = usermgr.getWebsiteByHandle(sub.getAuthor());
-                if (website == null) return newEntries;
-                
-                // figure website last update time
-                WeblogManager blogmgr = roller.getWeblogManager();
-                
-                Date siteUpdated = blogmgr.getWeblogLastPublishTime(website);
-                if (siteUpdated == null) { // Site never updated, skip it
-                    log.warn("Last-publish time null, skipping local feed ["
-                            + website.getHandle() + "]");
-                    return newEntries;
-                }
-                
-                // if website last update time > subsciption last update time
-                List entries = new ArrayList();
-                if (sub.getLastUpdated()==null || siteUpdated.after(sub.getLastUpdated()))
{
-                    int entryCount = RollerRuntimeConfig.getIntProperty(
-                            "site.newsfeeds.defaultEntries");
-                    entries = blogmgr.getWeblogEntries(
-                            website,
-                            null,                        // startDate
-                            new Date(),                  // endDate
-                            null,                        // catName
-                            WeblogEntryData.PUBLISHED,   // status
-                            null,                        // sortby (null means pubTime)
-                            new Integer(entryCount));    // maxEntries
-                    
-                    sub.setLastUpdated(siteUpdated);
-                    saveSubscription(sub);
-                    
-                } else {
-                    if (log.isDebugEnabled()) {
-                        String msg = MessageFormat.format(
-                                "   Skipping ({0} / {1})", new Object[] {
-                            siteUpdated, sub.getLastUpdated()});
-                        log.debug(msg);
-                    }
-                }
-                // Populate subscription object with new entries
-                PagePluginManager ppmgr = roller.getPagePluginManager();
-                Map pagePlugins = ppmgr.createAndInitPagePlugins(
-                        website,
-                        null,
-                        RollerRuntimeConfig.getProperty("site.absoluteurl"),
-                        new VelocityContext());
-                Iterator entryIter = entries.iterator();
-                while (entryIter.hasNext()) {
-                    try {
-                        WeblogEntryData rollerEntry =
-                                (WeblogEntryData)entryIter.next();
-                        PlanetEntryData entry =
-                                new PlanetEntryData(rollerEntry, sub, pagePlugins);
-                        saveEntry(entry);
-                        newEntries.add(entry);
-                    } catch (Exception e) {
-                        log.error("ERROR processing subscription entry", e);
-                    }
-                }
-                return newEntries;
-            }
-        } catch (Exception e) {
-            log.warn("Problem reading local feed", e);
-        }
-        return getNewEntriesRemote(sub, feedFetcher, feedInfoCache);
-    }
-    
-    
-    /**
-     * Override this if you have local feeds (i.e. feeds that you don't
-     * have to fetch via HTTP and parse with ROME).
-     */
-    // TODO: broken by backend refactoring
-    //       this should probably be handled by providing a special RollerPlanetManager
-    //       which overrides some normal planet behavior to be Roller specific
-    //       another example of why planet should be separated out
-//    protected Set getNewEntriesLocal(PlanetSubscriptionData sub,
-//            FeedFetcher feedFetcher, FeedFetcherCache feedInfoCache)
-//            throws RollerException {
-//
-//        // If you don't override, local feeds will be treated as remote feeds
-//        return getNewEntriesRemote(sub, feedFetcher, feedInfoCache);
-//    }
-    
-    
-    protected Set getNewEntriesRemote(PlanetSubscriptionData sub,
-            FeedFetcher feedFetcher, FeedFetcherCache feedInfoCache)
+    protected Set getNewEntries(PlanetSubscriptionData sub,
+                                FeedFetcher feedFetcher,
+                                FeedFetcherCache feedInfoCache)
             throws RollerException {
         
         Set newEntries = new TreeSet();
@@ -622,6 +523,10 @@
             }
         }
         return newEntries;
+    }
+
+    protected String getLocalURL() {
+        return localURL;
     }
     
 }

Modified: incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernateRollerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernateRollerImpl.java?rev=394784&r1=394783&r2=394784&view=diff
==============================================================================
--- incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernateRollerImpl.java
(original)
+++ incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernateRollerImpl.java
Mon Apr 17 15:03:04 2006
@@ -186,7 +186,7 @@
      */
     public PlanetManager getPlanetManager() throws RollerException {
         if ( planetManager == null ) {
-            planetManager = new HibernatePlanetManagerImpl(strategy,this);
+            planetManager = new HibernateRollerPlanetManagerImpl(strategy);
         }
         return planetManager;
     }

Added: incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernateRollerPlanetManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernateRollerPlanetManagerImpl.java?rev=394784&view=auto
==============================================================================
--- incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernateRollerPlanetManagerImpl.java
(added)
+++ incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernateRollerPlanetManagerImpl.java
Mon Apr 17 15:03:04 2006
@@ -0,0 +1,152 @@
+/*
+ * HibernateRollerPlanetManagerImpl.java
+ *
+ * Created on April 17, 2006, 1:53 PM
+ */
+
+package org.roller.business.hibernate;
+
+import com.sun.syndication.fetcher.FeedFetcher;
+import com.sun.syndication.fetcher.impl.FeedFetcherCache;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.velocity.VelocityContext;
+import org.roller.RollerException;
+import org.roller.config.RollerRuntimeConfig;
+import org.roller.model.PagePluginManager;
+import org.roller.model.Roller;
+import org.roller.model.RollerFactory;
+import org.roller.model.UserManager;
+import org.roller.model.WeblogManager;
+import org.roller.pojos.PlanetEntryData;
+import org.roller.pojos.PlanetSubscriptionData;
+import org.roller.pojos.WeblogEntryData;
+import org.roller.pojos.WebsiteData;
+import org.roller.util.StringUtils;
+
+
+/**
+ * An extended version of the base PlanetManager implementation.
+ * 
+ * This is meant for use by Roller installations that are running the planet
+ * aggregator in the same application instance and want to fetch feeds from
+ * their local Roller blogs in a more efficient manner.
+ */
+public class HibernateRollerPlanetManagerImpl extends HibernatePlanetManagerImpl {
+    
+    private static Log log = LogFactory.getLog(HibernateRollerPlanetManagerImpl.class);
+    
+    
+    public HibernateRollerPlanetManagerImpl(HibernatePersistenceStrategy strat) {
+        
+        super(strat);
+        
+        log.info("Instantiating Hibernate Roller Planet Manager");
+    }
+    
+    
+    protected Set getNewEntries(PlanetSubscriptionData sub,
+                                FeedFetcher feedFetcher,
+                                FeedFetcherCache feedInfoCache)
+            throws RollerException {
+        
+        String localURL = RollerRuntimeConfig.getProperty("site.absoluteurl");
+        
+        // if this is not a local url then let parent deal with it
+        if (StringUtils.isEmpty(localURL) || !sub.getFeedUrl().startsWith(localURL)) {
+            
+            log.debug("Feed is remote, letting parent handle it "+sub.getFeedUrl());
+            
+            return super.getNewEntries(sub, feedFetcher, feedInfoCache);
+        }
+        
+        // url must be local, lets deal with it
+        Set newEntries = new TreeSet();
+        try {
+            // for local feeds, sub.author = website.handle
+            if (sub.getAuthor()!=null && sub.getFeedUrl().endsWith(sub.getAuthor()))
{
+                
+                log.debug("Getting LOCAL feed "+sub.getFeedUrl());
+                
+                // get corresponding website object
+                UserManager usermgr = RollerFactory.getRoller().getUserManager();
+                WebsiteData website = usermgr.getWebsiteByHandle(sub.getAuthor());
+                if (website == null) return newEntries;
+                
+                // figure website last update time
+                WeblogManager blogmgr = RollerFactory.getRoller().getWeblogManager();
+                
+                Date siteUpdated = blogmgr.getWeblogLastPublishTime(website);
+                if (siteUpdated == null) { // Site never updated, skip it
+                    log.warn("Last-publish time null, skipping local feed ["
+                            + website.getHandle() + "]");
+                    return newEntries;
+                }
+                
+                // if website last update time > subsciption last update time
+                List entries = new ArrayList();
+                if (sub.getLastUpdated()==null || siteUpdated.after(sub.getLastUpdated()))
{
+                    int entryCount = RollerRuntimeConfig.getIntProperty(
+                            "site.newsfeeds.defaultEntries");
+                    entries = blogmgr.getWeblogEntries(
+                            website,
+                            null,                        // startDate
+                            new Date(),                  // endDate
+                            null,                        // catName
+                            WeblogEntryData.PUBLISHED,   // status
+                            null,                        // sortby (null means pubTime)
+                            new Integer(entryCount));    // maxEntries
+                    
+                    sub.setLastUpdated(siteUpdated);
+                    saveSubscription(sub);
+                    
+                } else {
+                    if (log.isDebugEnabled()) {
+                        String msg = MessageFormat.format(
+                                "   Skipping ({0} / {1})", new Object[] {
+                            siteUpdated, sub.getLastUpdated()});
+                        log.debug(msg);
+                    }
+                }
+                
+                // Populate subscription object with new entries
+                PagePluginManager ppmgr = RollerFactory.getRoller().getPagePluginManager();
+                Map pagePlugins = ppmgr.createAndInitPagePlugins(
+                        website,
+                        null,
+                        RollerRuntimeConfig.getProperty("site.absoluteurl"),
+                        new VelocityContext());
+                Iterator entryIter = entries.iterator();
+                while (entryIter.hasNext()) {
+                    try {
+                        WeblogEntryData rollerEntry =
+                                (WeblogEntryData)entryIter.next();
+                        PlanetEntryData entry =
+                                new PlanetEntryData(rollerEntry, sub, pagePlugins);
+                        saveEntry(entry);
+                        newEntries.add(entry);
+                    } catch (Exception e) {
+                        log.error("ERROR processing subscription entry", e);
+                    }
+                }
+                return newEntries;
+            }
+        } catch (Exception e) {
+            log.warn("Problem reading local feed", e);
+        }
+        
+        log.debug("Failed to fetch locally, trying remote "+sub.getFeedUrl());
+        
+        // if there was an error then try normal planet method
+        return super.getNewEntries(sub, feedFetcher, feedInfoCache);
+    }
+    
+}



Mime
View raw message