You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by cl...@apache.org on 2006/12/05 01:26:21 UTC
svn commit: r482428 [1/6] - in /incubator/roller/trunk/sandbox/jdobackend:
src/org/apache/roller/business/datamapper/
src/org/apache/roller/business/jdo/ src/org/apache/roller/business/jpa/
src/org/apache/roller/planet/ src/org/apache/roller/planet/poj...
Author: clr
Date: Mon Dec 4 16:26:15 2006
New Revision: 482428
URL: http://svn.apache.org/viewvc?view=rev&rev=482428
Log:
Updated jdo sandbox with latest jpa and jdo impls
Added:
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperRollerPlanetManagerImpl.java
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/planet/
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/planet/pojos/
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/planet/pojos/PlanetConfigData.orm.xml
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/planet/pojos/PlanetEntryData.orm.xml
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/planet/pojos/PlanetGroupData.orm.xml
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/planet/pojos/PlanetSubscriptionData.orm.xml
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/AutoPingData.orm.xml
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/BookmarkData.orm.xml
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/CommentData.orm.xml
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/EntryAttributeData.orm.xml
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/FolderData.orm.xml
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/HitCountData.orm.xml
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/ObjectAuditData.orm.xml
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/PermissionsData.orm.xml
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/PingCategoryRestrictionData.orm.xml
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/PingQueueEntryData.orm.xml
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/PingTargetData.orm.xml
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/RefererData.orm.xml
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/RoleData.orm.xml
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/RollerConfigData.orm.xml
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/RollerPropertyData.orm.xml
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/UserData.orm.xml
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/WeblogCategoryData.orm.xml
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/WeblogEntryData.orm.xml
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/WeblogEntryTagAggregateData.orm.xml
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/WeblogEntryTagData.orm.xml
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/WeblogTemplate.orm.xml
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/WebsiteData.orm.xml
incubator/roller/trunk/sandbox/jdobackend/web/WEB-INF/classes/persistence.xml
Modified:
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperAutoPingManagerImpl.java
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperBookmarkManagerImpl.java
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperPersistenceStrategy.java
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperPingQueueManagerImpl.java
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperPingTargetManagerImpl.java
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperPlanetManagerImpl.java
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperPropertiesManagerImpl.java
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperQuery.java
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperReferrerManagerImpl.java
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperRemoveQuery.java
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperRollerImpl.java
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperUserManagerImpl.java
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperWeblogManagerImpl.java
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/jdo/JDORollerImpl.java
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/jpa/JPAPersistenceStrategy.java
incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/jpa/JPARollerImpl.java
Modified: incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperAutoPingManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperAutoPingManagerImpl.java?view=diff&rev=482428&r1=482427&r2=482428
==============================================================================
--- incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperAutoPingManagerImpl.java (original)
+++ incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperAutoPingManagerImpl.java Mon Dec 4 16:26:15 2006
@@ -18,19 +18,23 @@
*/
package org.apache.roller.business.datamapper;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.roller.RollerException;
+import org.apache.roller.business.RollerFactory;
+import org.apache.roller.business.pings.AutoPingManager;
+import org.apache.roller.business.pings.PingQueueManager;
import org.apache.roller.config.PingConfig;
-import org.apache.roller.model.AutoPingManager;
import org.apache.roller.pojos.AutoPingData;
import org.apache.roller.pojos.PingTargetData;
import org.apache.roller.pojos.WeblogEntryData;
import org.apache.roller.pojos.WebsiteData;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
/*
* DatamapperAutoPingManagerImpl.java
*
@@ -53,19 +57,21 @@
this.strategy = strategy;
}
- public void saveAutoPing(AutoPingData autoPing)
- throws RollerException {
+ public AutoPingData getAutoPing(String id) throws RollerException {
+ return (AutoPingData)strategy.load(AutoPingData.class, id);
+ }
+
+ public void saveAutoPing(AutoPingData autoPing) throws RollerException {
strategy.store(autoPing);
}
- public void removeAutoPing(AutoPingData autoPing)
- throws RollerException {
+ public void removeAutoPing(AutoPingData autoPing) throws RollerException {
strategy.remove(autoPing);
}
- public void removeAutoPing(PingTargetData pingTarget, WebsiteData website)
+ public void removeAutoPing(PingTargetData pingTarget, WebsiteData website)
throws RollerException {
- strategy.newRemoveQuery(AutoPingData.class, "getByPingTarget&Website")
+ strategy.newRemoveQuery(AutoPingData.class, "AutoPingData.removeByPingTarget&Website")
.removeAll(new Object[]{pingTarget, website});
}
@@ -79,52 +85,51 @@
strategy.removeAll(AutoPingData.class);
}
- public AutoPingData getAutoPing(String id)
+ public void queueApplicableAutoPings(WeblogEntryData changedWeblogEntry)
throws RollerException {
- return (AutoPingData)strategy.load(AutoPingData.class, id);
+ if (PingConfig.getSuspendPingProcessing()) {
+ if (logger.isDebugEnabled())
+ logger.debug("Ping processing is suspended. No auto pings will be queued.");
+ return;
+ }
+
+ PingQueueManager pingQueueMgr = RollerFactory.getRoller().getPingQueueManager();
+ List applicableAutopings = getApplicableAutoPings(changedWeblogEntry);
+ for (Iterator i = applicableAutopings.iterator(); i.hasNext(); ) {
+ AutoPingData autoPing = (AutoPingData) i.next();
+ pingQueueMgr.addQueueEntry(autoPing);
+ }
}
- public List getAutoPingsByWebsite(WebsiteData website)
+ public List getAutoPingsByWebsite(WebsiteData website)
throws RollerException {
- return (List)strategy.newQuery(AutoPingData.class, "getByWebsite")
+ return (List)strategy.newQuery(AutoPingData.class, "AutoPingData.getByWebsite")
.execute(website);
}
public List getAutoPingsByTarget(PingTargetData pingTarget)
throws RollerException {
- return (List)strategy.newQuery(AutoPingData.class, "getByPingTarget")
+ return (List)strategy.newQuery(AutoPingData.class, "AutoPingData.getByPingTarget")
.execute(pingTarget);
}
public List getApplicableAutoPings(WeblogEntryData changedWeblogEntry)
throws RollerException {
- return (List)strategy.newQuery(AutoPingData.class, "getByWebsite")
- .execute(changedWeblogEntry.getWebsite());
- }
-
- public void queueApplicableAutoPings(WeblogEntryData changedWeblogEntry)
- throws RollerException {
- if (PingConfig.getSuspendPingProcessing()) {
- if (logger.isDebugEnabled())
- logger.debug("Ping processing is suspended. " +
- "No auto pings will be queued.");
- return;
- // XXX not implemented
- }
+ return getAutoPingsByWebsite(changedWeblogEntry.getWebsite());
+ // return (List)strategy.newQuery(AutoPingData.class, "AutoPingData.getByWebsite")
+ // .execute(changedWeblogEntry.getWebsite());
}
- public List getCategoryRestrictions(AutoPingData autoPing)
+ public List getCategoryRestrictions(AutoPingData autoPing)
throws RollerException {
- // XXX not implemented
return Collections.EMPTY_LIST;
}
public void setCategoryRestrictions
(AutoPingData autoPing, Collection newCategories) {
- // XXX not implemented
+ // NOT YET IMPLEMENTED
}
- public void release() {
- }
+ public void release() {}
}
Modified: incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperBookmarkManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperBookmarkManagerImpl.java?view=diff&rev=482428&r1=482427&r2=482428
==============================================================================
--- incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperBookmarkManagerImpl.java (original)
+++ incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperBookmarkManagerImpl.java Mon Dec 4 16:26:15 2006
@@ -18,16 +18,23 @@
*/
package org.apache.roller.business.datamapper;
-import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.roller.RollerException;
-import org.apache.roller.model.BookmarkManager;
-import org.apache.roller.model.RollerFactory;
-import org.apache.roller.pojos.Assoc;
+import org.apache.roller.business.BookmarkManager;
+import org.apache.roller.business.RollerFactory;
import org.apache.roller.pojos.BookmarkData;
import org.apache.roller.pojos.FolderData;
import org.apache.roller.pojos.WebsiteData;
+import org.apache.roller.util.Utilities;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.input.SAXBuilder;
+
+import java.io.StringReader;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
/*
* DatamapperBookmarkManagerImpl.java
@@ -42,141 +49,351 @@
/**
* The logger instance for this class.
*/
- private static Log logger = LogFactory
+ private static Log log = LogFactory
.getFactory().getInstance(DatamapperBookmarkManagerImpl.class);
/** Creates a new instance of DatamapperBookmarkManagerImpl */
- public DatamapperBookmarkManagerImpl
- (DatamapperPersistenceStrategy strategy) {
+ public DatamapperBookmarkManagerImpl (DatamapperPersistenceStrategy strategy) {
+ log.debug("Instantiating Datamapper Bookmark Manager");
+
this.strategy = strategy;
}
- public void saveBookmark(BookmarkData bookmark)
- throws RollerException {
+ public void saveBookmark(BookmarkData bookmark) throws RollerException {
this.strategy.store(bookmark);
// update weblog last modified date (date is updated by saveWebsite())
- RollerFactory.getRoller().getUserManager()
- .saveWebsite(bookmark.getWebsite());
- }
-
- public void removeBookmark(BookmarkData bookmark)
- throws RollerException {
- strategy.remove(bookmark);
+ RollerFactory.getRoller().getUserManager().saveWebsite(bookmark.getWebsite());
}
- public BookmarkData getBookmark(String id)
- throws RollerException {
+ public BookmarkData getBookmark(String id) throws RollerException {
return (BookmarkData) strategy.load(BookmarkData.class, id);
}
- public List getBookmarks(FolderData data, boolean subfolders)
- throws RollerException {
- // todo
- return null;
+ public void removeBookmark(BookmarkData bookmark) throws RollerException {
+ strategy.remove(bookmark);
+
+ // update weblog last modified date. date updated by saveWebsite()
+ RollerFactory.getRoller().getUserManager().saveWebsite(bookmark.getWebsite());
}
- public void saveFolder(FolderData folder)
- throws RollerException {
- strategy.store(folder);
+ public void saveFolder(FolderData folder) throws RollerException {
+ if(isDuplicateFolderName(folder)) {
+ throw new RollerException("Duplicate folder name");
+ }
+
+ this.strategy.store(folder);
+
+ // update weblog last modified date. date updated by saveWebsite()
+ RollerFactory.getRoller().getUserManager().saveWebsite(folder.getWebsite());
}
- public void removeFolder(FolderData folder)
+ public void removeFolder(FolderData folder) throws RollerException {
+ this.strategy.remove(folder);
+
+ // update weblog last modified date. date updated by saveWebsite()
+ RollerFactory.getRoller().getUserManager().saveWebsite(folder.getWebsite());
+ }
+
+ public void moveFolder(FolderData srcFolder, FolderData destFolder)
throws RollerException {
- strategy.remove(folder);
+
+ // TODO: this check should be made before calling this method?
+ if (destFolder.descendentOf(srcFolder)) {
+ throw new RollerException(
+ "ERROR cannot move parent folder into it's own child");
+ }
+
+ log.debug("Moving folder "+srcFolder.getPath()+" under "+destFolder.getPath());
+
+ srcFolder.setParent(destFolder);
+ if("/".equals(destFolder.getPath())) {
+ srcFolder.setPath("/"+srcFolder.getName());
+ } else {
+ srcFolder.setPath(destFolder.getPath() + "/" + srcFolder.getName());
+ }
+ saveFolder(srcFolder);
+
+ // the main work to be done for a category move is to update the
+ // path attribute of the category and all descendent categories
+ updatePathTree(srcFolder);
+ }
+
+ // updates the paths of all descendents of the given folder
+ private void updatePathTree(FolderData folder) throws RollerException {
+
+ log.debug("Updating path tree for folder "+folder.getPath());
+
+ FolderData childFolder = null;
+ Iterator childFolders = folder.getFolders().iterator();
+ while(childFolders.hasNext()) {
+ childFolder = (FolderData) childFolders.next();
+
+ log.debug("OLD child folder path was "+childFolder.getPath());
+
+ // update path and save
+ if("/".equals(folder.getPath())) {
+ childFolder.setPath("/" + childFolder.getName());
+ } else {
+ childFolder.setPath(folder.getPath() + "/" + childFolder.getName());
+ }
+ saveFolder(childFolder);
+
+ log.debug("NEW child folder path is "+ childFolder.getPath());
+
+ // then make recursive call to update this folders children
+ updatePathTree(childFolder);
+ }
}
- public FolderData getFolder(String id)
- throws RollerException {
+ public FolderData getFolder(String id) throws RollerException {
return (FolderData) strategy.load(FolderData.class, id);
}
- public List getAllFolders(WebsiteData wd)
+ //------------------------------------------------------------ Operations
+ public void importBookmarks(WebsiteData website, String folderName, String opml)
throws RollerException {
- // todo
- return null;
+ String msg = "importBookmarks";
+ try {
+ // Build JDOC document OPML string
+ SAXBuilder builder = new SAXBuilder();
+ StringReader reader = new StringReader( opml );
+ Document doc = builder.build( reader );
+
+ FolderData newFolder = getFolder(website, folderName);
+ if (newFolder == null) {
+ newFolder = new FolderData(
+ getRootFolder(website), folderName, folderName, website);
+ this.strategy.store(newFolder);
+ }
+
+ // Iterate through children of OPML body, importing each
+ Element body = doc.getRootElement().getChild("body");
+ Iterator iter = body.getChildren().iterator();
+ while (iter.hasNext()) {
+ Element elem = (Element)iter.next();
+ importOpmlElement( website, elem, newFolder );
+ }
+
+ } catch (Exception ex) {
+ throw new RollerException(ex);
+ }
+ }
+
+ // convenience method used when importing bookmarks
+ // NOTE: this method does not commit any changes, that is done by importBookmarks()
+ private void importOpmlElement(
+ WebsiteData website, Element elem, FolderData parent)
+ throws RollerException {
+ String text = elem.getAttributeValue("text");
+ String title = elem.getAttributeValue("title");
+ String desc = elem.getAttributeValue("description");
+ String url = elem.getAttributeValue("url");
+ //String type = elem.getAttributeValue("type");
+ String xmlUrl = elem.getAttributeValue("xmlUrl");
+ String htmlUrl = elem.getAttributeValue("htmlUrl");
+
+ title = null!=title ? title : text;
+ desc = null!=desc ? desc : title;
+ xmlUrl = null!=xmlUrl ? xmlUrl : url;
+ url = null!=htmlUrl ? htmlUrl : url;
+
+ if (elem.getChildren().size()==0) {
+ // Leaf element. Store a bookmark
+ // Currently bookmarks must have at least a name and HTML url to be stored. Previous logic was
+ // trying to skip invalid ones, but was letting ones with an xml url and no html url through
+ // which could result in a db exception.
+ // TODO: Consider providing error feedback instead of silently skipping the invalid bookmarks here.
+ if (null != title && null != url) {
+ BookmarkData bd = new BookmarkData(parent,
+ title,
+ desc,
+ url,
+ xmlUrl,
+ new Integer(0),
+ new Integer(100),
+ null);
+ parent.addBookmark(bd);
+ // TODO: maybe this should be saving the folder?
+ this.strategy.store(bd);
+ }
+ } else {
+ // Store a folder
+ FolderData fd = new FolderData(
+ parent,
+ title,
+ desc,
+ parent.getWebsite());
+ this.strategy.store(fd);
+
+ // Import folder's children
+ Iterator iter = elem.getChildren("outline").iterator();
+ while ( iter.hasNext() ) {
+ Element subelem = (Element)iter.next();
+ importOpmlElement( website, subelem, fd );
+ }
+ }
}
- public FolderData getRootFolder(WebsiteData website)
+ //----------------------------------------------------------------
+ public void moveFolderContents(FolderData src, FolderData dest)
throws RollerException {
- // todo
- return null;
+ if (dest.descendentOf(src)) {
+ throw new RollerException(
+ "ERROR cannot move parent folder into it's own child");
+ }
+
+ try {
+ // Add to destination folder
+ LinkedList deleteList = new LinkedList();
+ Iterator srcBookmarks = src.getBookmarks().iterator();
+ while (srcBookmarks.hasNext()) {
+ BookmarkData bd = (BookmarkData)srcBookmarks.next();
+ deleteList.add(bd);
+
+ BookmarkData movedBd = new BookmarkData();
+ movedBd.setData(bd);
+ movedBd.setId(null);
+
+ dest.addBookmark(movedBd);
+ this.strategy.store(movedBd);
+ }
+
+ // Remove from source folder
+ Iterator deleteIter = deleteList.iterator();
+ while (deleteIter.hasNext()) {
+ BookmarkData bd = (BookmarkData)deleteIter.next();
+ src.removeBookmark(bd);
+ // TODO: this won't conflict with the bookmark we store above right?
+ this.strategy.remove(bd);
+ }
+
+ } catch (Exception ex) {
+ throw new RollerException(ex);
+ }
}
- public FolderData getFolder(WebsiteData website, String folderPath)
+ //----------------------------------------------------------------
+ public void removeFolderContents(FolderData src)
throws RollerException {
- // todo
- return null;
+ // just go through the folder and remove each bookmark
+ Iterator srcBookmarks = src.getBookmarks().iterator();
+ while (srcBookmarks.hasNext()) {
+ BookmarkData bd = (BookmarkData)srcBookmarks.next();
+ this.strategy.remove(bd);
+ }
}
- public String getPath(FolderData folder)
- throws RollerException {
- // todo
- return null;
- }
+ //---------------------------------------------------------------- Queries
- public FolderData getFolderByPath(
- WebsiteData wd, FolderData folder, String string)
+ public FolderData getFolder(WebsiteData website, String folderPath)
throws RollerException {
- // todo
- return null;
+ return getFolderByPath(website, null, folderPath);
}
- public boolean isFolderInUse(FolderData folder)
+ public String getPath(FolderData folder)
throws RollerException {
- // todo
- return true;
+ if (null == folder.getParent()) {
+ return "/";
+ } else {
+ String parentPath = getPath(folder.getParent());
+ parentPath = "/".equals(parentPath) ? "" : parentPath;
+ return parentPath + "/" + folder.getName();
+ }
}
- public boolean isDuplicateFolderName(FolderData data)
+ public FolderData getFolderByPath(
+ WebsiteData website, FolderData folder, String path)
throws RollerException {
- // todo
- return true;
- }
+ final Iterator folders;
+ final String[] pathArray = Utilities.stringToStringArray(path, "/");
- public boolean isDescendentOf(FolderData data, FolderData ancestor)
- throws RollerException {
- // todo
- return true;
- }
+ if (folder == null && (null == path || "".equals(path.trim()))) {
+ throw new RollerException("Bad arguments.");
+ }
+
+ if (path.trim().equals("/")) {
+ return getRootFolder(website);
+ } else if (folder == null || path.trim().startsWith("/")) {
+ folders = getRootFolder(website).getFolders().iterator();
+ } else {
+ folders = folder.getFolders().iterator();
+ }
+
+ while (folders.hasNext()) {
+ FolderData possibleMatch = (FolderData)folders.next();
+ if (possibleMatch.getName().equals(pathArray[0])) {
+ if (pathArray.length == 1) {
+ return possibleMatch;
+ } else {
+ String[] subpath = new String[pathArray.length - 1];
+ System.arraycopy(pathArray, 1, subpath, 0, subpath.length);
+
+ String pathString= Utilities.stringArrayToString(subpath,"/");
+ return getFolderByPath(website, possibleMatch, pathString);
+ }
+ }
+ }
- public Assoc getFolderParentAssoc(FolderData data)
- throws RollerException {
- // todo
+ // The folder did not match and neither did any subfolders
return null;
}
- public List getFolderChildAssocs(FolderData data)
- throws RollerException {
- // todo
- return null;
- }
+ //----------------------------------------------- FolderAssoc CRUD
- public List getAllFolderDecscendentAssocs(FolderData data)
- throws RollerException {
- // todo
- return null;
- }
+ public void release() {}
- public List getFolderAncestorAssocs(FolderData data)
- throws RollerException {
- // todo
- return null;
+
+ /**
+ * @see org.apache.roller.business.BookmarkManager#getBookmarks(
+ * org.apache.roller.pojos.FolderData, boolean)
+ */
+ public List getBookmarks(FolderData folder, boolean subfolders) throws RollerException {
+ DatamapperQuery query = null;
+ List results = null;
+
+ if(!subfolders) {
+ // if no subfolders then this is an equals query
+ query = strategy.newQuery(BookmarkData.class, "BoomarkData.getByFolder");
+ results = (List) query.execute(folder);
+ } else {
+ // if we are doing subfolders then do a case sensitive
+ // query using folder path
+ query = strategy.newQuery(BookmarkData.class, "BoomarkData.getByFolder.pathLike&Folder.website");
+ results = (List) query.execute(new Object[] {folder.getPath(), folder.getWebsite()});
+ }
+
+ return results;
}
- public void importBookmarks(WebsiteData site, String folder, String opml)
+ public FolderData getRootFolder(WebsiteData website)
throws RollerException {
+ if (website == null)
+ throw new RollerException("website is null");
+
+ return (FolderData) strategy.newQuery(FolderData.class,
+ "FolderData.getByWebsite&ParentNull").setUnique().execute(website);
}
- public void moveFolderContents(FolderData src, FolderData dest)
+ public List getAllFolders(WebsiteData website)
throws RollerException {
+ if (website == null)
+ throw new RollerException("Website is null");
+
+ return (List) strategy.newQuery(FolderData.class, "FolderData.getByWebsite").execute(website);
}
- public void removeFolderContents(FolderData src)
+ public boolean isDuplicateFolderName(FolderData folder)
throws RollerException {
- }
- public void release() {
+ // ensure that no sibling categories share the same name
+ FolderData parent = folder.getParent();
+ if (null != parent) {
+ return (getFolder(folder.getWebsite(), folder.getPath()) != null);
+ }
+
+ return false;
}
-
+
+
}
Modified: incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperPersistenceStrategy.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperPersistenceStrategy.java?view=diff&rev=482428&r1=482427&r2=482428
==============================================================================
--- incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperPersistenceStrategy.java (original)
+++ incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperPersistenceStrategy.java Mon Dec 4 16:26:15 2006
@@ -17,10 +17,10 @@
* directory of this distribution.
*/
-import java.util.Collection;
import org.apache.roller.RollerException;
-
import org.apache.roller.pojos.PersistentObject;
+
+import java.util.Collection;
/**
*
Modified: incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperPingQueueManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperPingQueueManagerImpl.java?view=diff&rev=482428&r1=482427&r2=482428
==============================================================================
--- incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperPingQueueManagerImpl.java (original)
+++ incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperPingQueueManagerImpl.java Mon Dec 4 16:26:15 2006
@@ -18,13 +18,16 @@
*/
package org.apache.roller.business.datamapper;
-import java.sql.Timestamp;
-import java.util.List;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.roller.RollerException;
-import org.apache.roller.model.PingQueueManager;
+import org.apache.roller.business.pings.PingQueueManager;
import org.apache.roller.pojos.AutoPingData;
import org.apache.roller.pojos.PingQueueEntryData;
+import java.sql.Timestamp;
+import java.util.List;
+
/*
* DatamapperPingQueueManagerImpl.java
*
@@ -33,55 +36,66 @@
*/
public class DatamapperPingQueueManagerImpl implements PingQueueManager {
+ private static Log log = LogFactory.getLog(DatamapperPlanetManagerImpl.class);
+
/** The strategy for this manager. */
private DatamapperPersistenceStrategy strategy;
/** Creates a new instance of DatamapperPingQueueManagerImpl */
- public DatamapperPingQueueManagerImpl
- (DatamapperPersistenceStrategy strategy) {
+ public DatamapperPingQueueManagerImpl(DatamapperPersistenceStrategy strategy) {
this.strategy = strategy;
}
- public void addQueueEntry(AutoPingData autoPing)
+ public PingQueueEntryData getQueueEntry(String id)
throws RollerException {
- // first, determine if an entry already exists
- Integer count = (Integer)strategy.newQuery(PingQueueEntryData.class,
- "countGetByPingTarget&&website")
- .execute(new Object[]
- {autoPing.getPingTarget(), autoPing.getWebsite()});
- if (count.intValue() > 0)
- return;
-
- // create and store a new entry
- Timestamp now = new Timestamp(System.currentTimeMillis());
- PingQueueEntryData pingQueueEntry =
- new PingQueueEntryData(null, now,
- autoPing.getPingTarget(), autoPing.getWebsite(), 0);
- this.saveQueueEntry(pingQueueEntry);
+ return (PingQueueEntryData)strategy.load(PingQueueEntryData.class, id);
}
- public void saveQueueEntry(PingQueueEntryData pingQueueEntry)
- throws RollerException {
+ public void saveQueueEntry(PingQueueEntryData pingQueueEntry) throws RollerException {
+ log.debug("Storing ping queue entry: " + pingQueueEntry);
strategy.store(pingQueueEntry);
}
- public void removeQueueEntry(PingQueueEntryData pingQueueEntry)
- throws RollerException {
+ public void removeQueueEntry(PingQueueEntryData pingQueueEntry) throws RollerException {
+ log.debug("Removing ping queue entry: " + pingQueueEntry);
strategy.remove(pingQueueEntry);
}
- public PingQueueEntryData getQueueEntry(String id)
+ public void addQueueEntry(AutoPingData autoPing)
throws RollerException {
- return (PingQueueEntryData)strategy.load(PingQueueEntryData.class, id);
+ log.debug("Creating new ping queue entry for auto ping configuration: " + autoPing);
+
+ // First check if there is an existing ping queue entry for the same target and website
+ if (isAlreadyQueued(autoPing)) {
+ log.debug("A ping queue entry is already present for this ping target and website: " + autoPing);
+ return;
+ }
+
+ // create and store a new entry
+ Timestamp now = new Timestamp(System.currentTimeMillis());
+ PingQueueEntryData pingQueueEntry =
+ new PingQueueEntryData(null, now,
+ autoPing.getPingTarget(), autoPing.getWebsite(), 0);
+ this.saveQueueEntry(pingQueueEntry);
}
public List getAllQueueEntries()
throws RollerException {
return (List)strategy.newQuery(PingQueueEntryData.class,
- "getAll.orderByEntryTime");
+ "PingQueueEntryData.getAllOrderyByEntryTime");
}
- public void release() {
+ // private helper to determine if an has already been queued for the same website and ping target.
+ private boolean isAlreadyQueued(AutoPingData autoPing) throws RollerException {
+ // first, determine if an entry already exists
+ List results = (List)strategy.newQuery(PingQueueEntryData.class,
+ "PingQueueEntryData.getByPingTarget&website")
+ .execute(new Object[]
+ {autoPing.getPingTarget(), autoPing.getWebsite()});
+ return results.size() > 0;
}
+
+ public void release() {}
+
}
Modified: incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperPingTargetManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperPingTargetManagerImpl.java?view=diff&rev=482428&r1=482427&r2=482428
==============================================================================
--- incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperPingTargetManagerImpl.java (original)
+++ incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperPingTargetManagerImpl.java Mon Dec 4 16:26:15 2006
@@ -18,20 +18,21 @@
*/
package org.apache.roller.business.datamapper;
-import java.net.InetAddress;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.UnknownHostException;
-import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.roller.RollerException;
-import org.apache.roller.model.PingTargetManager;
+import org.apache.roller.business.pings.PingTargetManager;
import org.apache.roller.pojos.AutoPingData;
import org.apache.roller.pojos.PingQueueEntryData;
import org.apache.roller.pojos.PingTargetData;
import org.apache.roller.pojos.WebsiteData;
+import java.net.InetAddress;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.UnknownHostException;
+import java.util.List;
+
/*
* DatamapperPingTargetManagerImpl.java
*
@@ -40,71 +41,55 @@
*/
public class DatamapperPingTargetManagerImpl implements PingTargetManager {
- private DatamapperPersistenceStrategy strategy;
-
/** The logger instance for this class. */
- private static Log logger = LogFactory
- .getFactory().getInstance(DatamapperPingTargetManagerImpl.class);
+ private static Log log = LogFactory.getLog(DatamapperPingTargetManagerImpl.class);
- /** Creates a new instance of DatamapperPropertiesManagerImpl */
- public DatamapperPingTargetManagerImpl
- (DatamapperPersistenceStrategy strategy) {
+ private DatamapperPersistenceStrategy strategy;
+
+ public DatamapperPingTargetManagerImpl(DatamapperPersistenceStrategy strategy) {
this.strategy = strategy;
}
- public void savePingTarget(PingTargetData pingTarget)
- throws RollerException {
- strategy.store(pingTarget);
- }
-
public void removePingTarget(PingTargetData pingTarget)
throws RollerException {
// remove queued ping entries that refer to this ping target
- strategy.newRemoveQuery(PingQueueEntryData.class, "getByPingTarget")
+ strategy.newRemoveQuery(PingQueueEntryData.class, "PingQueueEntryData.removeByPingTarget")
.removeAll(pingTarget);
// remove autopings that refer to this ping target
- strategy.newRemoveQuery(AutoPingData.class, "getByPingTarget")
+ strategy.newRemoveQuery(AutoPingData.class, "PingTargetData.removeByPingTarget")
.removeAll(pingTarget);
+ // remove ping target
+ strategy.remove(pingTarget);
}
public void removeAllCustomPingTargets()
throws RollerException {
- strategy.newRemoveQuery(PingTargetData.class, "getByWebsiteNotNull")
+ strategy.newRemoveQuery(PingTargetData.class, "PingTargetData.removeByWebsiteNotNull")
.removeAll();
}
- public PingTargetData getPingTarget(String id)
- throws RollerException {
- return (PingTargetData)strategy.load(PingTargetData.class, id);
- }
-
- public List getCommonPingTargets()
+ public void savePingTarget(PingTargetData pingTarget)
throws RollerException {
- return (List)strategy.newQuery(PingTargetData.class,
- "getByWebsiteNull.orderByName")
- .execute();
+ strategy.store(pingTarget);
}
- public List getCustomPingTargets(WebsiteData website)
+ public PingTargetData getPingTarget(String id)
throws RollerException {
- return (List)strategy.newQuery(PingTargetData.class,
- "getByWebsite.orderByName")
- .execute(website);
+ return (PingTargetData)strategy.load(PingTargetData.class, id);
}
public boolean isNameUnique(PingTargetData pingTarget)
throws RollerException {
String name = pingTarget.getName();
if (name == null || name.trim().length() == 0) return false;
- int count = ((Integer)
+ List results = (List)
strategy.newQuery(PingTargetData.class,
- "countByWebsite&&NameEqual&&IdNotEqual")
+ "PingTargetData.getByWebsite&Name&IdNotEqual")
.execute(new Object[]{
pingTarget.getWebsite(),
name,
- pingTarget.getId()}))
- .intValue();
- return (count != 0);
+ pingTarget.getId()});
+ return (results.size() != 0);
}
public boolean isUrlWellFormed(PingTargetData pingTarget)
@@ -139,7 +124,20 @@
}
}
- public void release() {
+ public List getCommonPingTargets()
+ throws RollerException {
+ return (List)strategy.newQuery(PingTargetData.class,
+ "PingTargetData.getByWebsiteNullOrderByName")
+ .execute();
}
+
+ public List getCustomPingTargets(WebsiteData website)
+ throws RollerException {
+ return (List)strategy.newQuery(PingTargetData.class,
+ "PingTargetData.getByWebsiteOrderByName")
+ .execute(website);
+ }
+
+ public void release() {}
}
Modified: incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperPlanetManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperPlanetManagerImpl.java?view=diff&rev=482428&r1=482427&r2=482428
==============================================================================
--- incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperPlanetManagerImpl.java (original)
+++ incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperPlanetManagerImpl.java Mon Dec 4 16:26:15 2006
@@ -17,8 +17,34 @@
* directory of this distribution.
*/
+import com.sun.syndication.feed.synd.SyndEntry;
+import com.sun.syndication.feed.synd.SyndFeed;
+import com.sun.syndication.fetcher.FeedFetcher;
+import com.sun.syndication.fetcher.impl.FeedFetcherCache;
+import com.sun.syndication.fetcher.impl.HttpURLFeedFetcher;
+import com.sun.syndication.fetcher.impl.SyndFeedInfo;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.RollerException;
+import org.apache.roller.business.Roller;
+import org.apache.roller.business.RollerFactory;
+import org.apache.roller.business.WeblogManager;
+import org.apache.roller.config.RollerRuntimeConfig;
+import org.apache.roller.planet.business.PlanetManager;
+import org.apache.roller.planet.pojos.PlanetConfigData;
+import org.apache.roller.planet.pojos.PlanetEntryData;
+import org.apache.roller.planet.pojos.PlanetGroupData;
+import org.apache.roller.planet.pojos.PlanetSubscriptionData;
+import org.apache.roller.pojos.WeblogEntryData;
+import org.apache.roller.pojos.WebsiteData;
+import org.apache.roller.util.rome.DiskFeedInfoCache;
+
+import java.io.File;
+import java.net.URL;
+import java.sql.Timestamp;
import java.text.MessageFormat;
import java.util.ArrayList;
+import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
@@ -27,26 +53,6 @@
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.apache.roller.RollerException;
-import org.apache.roller.config.RollerRuntimeConfig;
-import org.apache.roller.model.PlanetManager;
-import org.apache.roller.model.RollerFactory;
-import org.apache.roller.model.UserManager;
-import org.apache.roller.model.WeblogManager;
-import org.apache.roller.pojos.PlanetConfigData;
-import org.apache.roller.pojos.PlanetEntryData;
-import org.apache.roller.pojos.PlanetGroupData;
-import org.apache.roller.pojos.PlanetGroupSubscriptionAssoc;
-import org.apache.roller.pojos.PlanetSubscriptionData;
-import org.apache.roller.pojos.WeblogEntryData;
-import org.apache.roller.pojos.WebsiteData;
-import org.apache.roller.pojos.UserData;
-
-import com.sun.syndication.fetcher.FeedFetcher;
-import com.sun.syndication.fetcher.impl.FeedFetcherCache;
/**
* Manages Planet Roller objects and entry aggregations in a database.
@@ -55,19 +61,18 @@
*/
public class DatamapperPlanetManagerImpl implements PlanetManager {
+ private static Log log = LogFactory.getLog(DatamapperPlanetManagerImpl.class);
+
/** The strategy for this manager. */
private DatamapperPersistenceStrategy strategy;
protected Map lastUpdatedByGroup = new HashMap();
protected static final String NO_GROUP = "zzz_nogroup_zzz";
- private static Log logger = LogFactory.getFactory().getInstance(
- DatamapperPlanetManagerImpl.class);
-
- private DatamapperWeblogManagerImpl weblogManager;
-
public DatamapperPlanetManagerImpl
(DatamapperPersistenceStrategy strategy) {
+ log.debug("Instantiating Datamapper Planet Manager");
+
this.strategy = strategy;
}
@@ -77,12 +82,6 @@
}
public void saveGroup(PlanetGroupData group) throws RollerException {
- Iterator assocs = group.getGroupSubscriptionAssocs().iterator();
- while (assocs.hasNext()) {
- PlanetGroupSubscriptionAssoc assoc = (PlanetGroupSubscriptionAssoc) assocs
- .next();
- strategy.store(assoc);
- }
strategy.store(group);
}
@@ -101,27 +100,38 @@
}
}
- public PlanetConfigData getConfiguration() throws RollerException {
- return null;
+ public void deleteEntry(PlanetEntryData entry) throws RollerException {
+ strategy.remove(entry);
}
- public List getGroups() throws RollerException {
- return null;
+ public void deleteGroup(PlanetGroupData group) throws RollerException {
+ strategy.remove(group);
}
- public List getGroupHandles() throws RollerException {
- List handles = new ArrayList();
- Iterator list = getGroups().iterator();
- while (list.hasNext()) {
- PlanetGroupData group = (PlanetGroupData) list.next();
- handles.add(group.getHandle());
- }
- return handles;
+ public void deleteSubscription(PlanetSubscriptionData sub)
+ throws RollerException {
+ strategy.remove(sub);
+ }
+
+ public PlanetConfigData getConfiguration() throws RollerException {
+ List results = (List) strategy.newQuery(PlanetConfigData.class,
+ "PlanetConfigData.getAll");
+ PlanetConfigData config = results.size()!=0 ? (PlanetConfigData)results.get(0) : null;
+
+ // We inject the cache dir into the config object here to maintain
+ // compatibility with the standaline version of the aggregator.
+// if (config != null) {
+// config.setCacheDir(
+// PlanetConfig.getProperty("planet.aggregator.cache.dir"));
+// }
+ return config;
}
public PlanetSubscriptionData getSubscription(String feedUrl)
throws RollerException {
- return null;
+ List results = (List) strategy.newQuery(PlanetSubscriptionData.class,
+ "PlanetSubscriptionData.getByFeedURL");
+ return results.size()!=0 ? (PlanetSubscriptionData)results.get(0) : null;
}
public PlanetSubscriptionData getSubscriptionById(String id)
@@ -130,105 +140,167 @@
PlanetSubscriptionData.class, id);
}
- public PlanetGroupData getGroup(String handle) throws RollerException {
- return null;
+ public Iterator getAllSubscriptions() {
+ try {
+ return ((List)strategy.newQuery(PlanetSubscriptionData.class,
+ "PlanetSubscriptionData.getAll")).iterator();
+ } catch (Throwable e) {
+ throw new RuntimeException(
+ "ERROR fetching subscription collection", e);
+ }
}
- public PlanetGroupData getGroupById(String id) throws RollerException {
- return (PlanetGroupData) strategy.load(PlanetGroupData.class, id);
- }
- /**
- * Get agggration for group from cache, enries in reverse chonological order.
- * Respects category constraints of group.
- * @param group Restrict to entries from one subscription group.
- * @param offset Offset into results (for paging)
- * @param len Maximum number of results to return (for paging)
- */
- public List getAggregation(
- PlanetGroupData group, Date startDate, Date endDate,
- int offset, int len) throws RollerException {
- return null;
- }
-
- public List getAggregation(
- int offset, int len) throws RollerException {
- return null;
+ public int getSubscriptionCount() throws RollerException {
+ return ((List)strategy.newQuery(PlanetSubscriptionData.class,
+ "PlanetSubscriptionData.getAll")).size();
}
-
- public List getAggregation(
- PlanetGroupData group, int offset, int len) throws RollerException {
- return null;
+
+ public List getTopSubscriptions(int offset, int length) throws RollerException {
+ return getTopSubscriptions(null, offset, length);
}
/**
- * Get agggration from cache, enries in reverse chonological order.
- * @param offset Offset into results (for paging)
- * @param len Maximum number of results to return (for paging)
+ * Get top X subscriptions, restricted by group.
*/
- public List getAggregation(Date startDate, Date endDate,
- int offset, int len) throws RollerException {
- return null;
+ public List getTopSubscriptions(
+ String groupHandle, int offset, int len) throws RollerException {
+ List result = null;
+ if (groupHandle != null) {
+ result = (List) strategy.newQuery(PlanetSubscriptionData.class,
+ "PlanetSubscriptionData.getByGroupHandleOrderByInboundBlogsDesc").execute(groupHandle);
+ } else {
+ result = (List) strategy.newQuery(PlanetSubscriptionData.class,
+ "PlanetSubscriptionData.getAllOrderByInboundBlogsDesc").execute();
+ }
+ // TODO handle offset and length
+ return result;
}
-
- public void deleteEntry(PlanetEntryData entry) throws RollerException {
- strategy.remove(entry);
+ public PlanetGroupData getGroup(String handle) throws RollerException {
+ List results = (List) strategy.newQuery(PlanetGroupData.class,
+ "PlanetGroupData.getByHandle").execute(handle);
+ // TODO handle max result == 1
+ PlanetGroupData group = results.size()!=0 ? (PlanetGroupData)results.get(0) : null;
+ return group;
}
- public void deleteGroup(PlanetGroupData group) throws RollerException {
- strategy.remove(group);
+ public PlanetGroupData getGroupById(String id) throws RollerException {
+ return (PlanetGroupData) strategy.load(PlanetGroupData.class, id);
}
- public void deleteSubscription(PlanetSubscriptionData sub)
- throws RollerException {
- strategy.remove(sub);
+ public List getGroups() throws RollerException {
+ return (List) strategy.newQuery(PlanetGroupData.class,
+ "PlanetGroupData.getAll").execute();
}
- public Iterator getAllSubscriptions() {
- return null;
+ public List getGroupHandles() throws RollerException {
+ List handles = new ArrayList();
+ Iterator list = getGroups().iterator();
+ while (list.hasNext()) {
+ PlanetGroupData group = (PlanetGroupData) list.next();
+ handles.add(group.getHandle());
+ }
+ return handles;
}
- public int getSubscriptionCount() throws RollerException {
- return -1;
+ /**
+ * Get entries in a single feed as list of PlanetEntryData objects.
+ */
+ public List getFeedEntries(
+ String feedUrl, int offset, int len) throws RollerException {
+ // TODO: ATLAS getFeedEntries DONE
+ List result = (List) strategy.newQuery(PlanetEntryData.class,
+ "PlanetEntryData.getByFeedURL").execute(feedUrl);
+ // TODO handle offset and length
+ return result;
}
- public synchronized List getTopSubscriptions(int max)
- throws RollerException {
- return null;
+ public List getAggregation(
+ int offset, int len) throws RollerException {
+ return getAggregation(null, null, null, offset, len);
}
-
+
/**
- * Get top X subscriptions.
+ * Get agggration from cache, enries in reverse chonological order.
+ * @param offset Offset into results (for paging)
+ * @param len Maximum number of results to return (for paging)
*/
- public List getTopSubscriptions(int offset, int len) throws RollerException {
- return null;
+ public List getAggregation(Date startDate, Date endDate,
+ int offset, int len) throws RollerException {
+ return getAggregation(null, startDate, endDate, offset, len);
}
- public synchronized List getTopSubscriptions(PlanetGroupData group, int max)
- throws RollerException {
- return null;
- }
-
- /**
- * Get top X subscriptions, restricted by group.
- */
- public List getTopSubscriptions(
- String groupHandle, int offset, int len) throws RollerException {
- return null;
+ public List getAggregation(
+ PlanetGroupData group, int offset, int len) throws RollerException {
+ return getAggregation(group, null, null, offset, len);
}
/**
- * Get entries in a single feed as list of PlanetEntryData objects.
+ * Get agggration for group from cache, enries in reverse chonological order.
+ * Respects category constraints of group.
+ * @param group Restrict to entries from one subscription group.
+ * @param offset Offset into results (for paging)
+ * @param length Maximum number of results to return (for paging)
*/
- public List getFeedEntries(
- String feedUrl, int offset, int len) throws RollerException {
- return null;
+ public List getAggregation(
+ PlanetGroupData group, Date startDate, Date endDate,
+ int offset, int length) throws RollerException {
+ // TODO: ATLAS getAggregation DONE TESTED
+ List result = null;
+ if (endDate == null) endDate = new Date();
+ try {
+ String groupHandle = (group == null) ? NO_GROUP : group.getHandle();
+ long startTime = System.currentTimeMillis();
+ DatamapperQuery query;
+ Object[] params;
+ if (group != null) {
+ if (startDate != null) {
+ params = new Object[] {groupHandle, endDate, startDate};
+ query = strategy.newQuery(PlanetEntryData.class,
+ "PlanetEntryData.getByGroup&EndDate&StartDateOrderByPubTimeDesc");
+ } else {
+ params = new Object[] {groupHandle, endDate};
+ query = strategy.newQuery(PlanetEntryData.class,
+ "PlanetEntryData.getByGroup&EndDateOrderByPubTimeDesc");
+ }
+ // TODO handle offset and length
+ } else {
+ if (startDate != null) {
+ params = new Object[] {endDate, startDate};
+ query = strategy.newQuery(PlanetEntryData.class,
+ "PlanetEntryData.getByExternalOrInternalGroup&EndDate&StartDateOrderByPubTimeDesc");
+ } else {
+ params = new Object[] {endDate};
+ query = strategy.newQuery(PlanetEntryData.class,
+ "PlanetEntryData.getByExternalOrInternalGroup&EndDateOrderByPubTimeDesc");
+ }
+ // TODO handle offset and length
+ }
+ result = (List) query.execute(params);
+ Date retLastUpdated;
+ if (result.size() > 0) {
+ PlanetEntryData entry = (PlanetEntryData)result.get(0);
+ retLastUpdated = entry.getPubTime();
+ } else {
+ retLastUpdated = new Date();
+ }
+ lastUpdatedByGroup.put(groupHandle, retLastUpdated);
+
+ long endTime = System.currentTimeMillis();
+ log.debug("Generated aggregation in "
+ + ((endTime-startTime)/1000.0) + " seconds");
+
+ } catch (Throwable e) {
+ log.error("ERROR: building aggregation for: " + group, e);
+ throw new RollerException(e);
+ }
+ return result;
}
-
+
public synchronized void clearCachedAggregations() {
lastUpdatedByGroup.clear();
}
-
+
public Date getLastUpdated() {
return (Date) lastUpdatedByGroup.get(NO_GROUP);
}
@@ -237,75 +309,184 @@
return (Date) lastUpdatedByGroup.get(group);
}
- protected Set getNewEntriesLocal(PlanetSubscriptionData sub,
- FeedFetcher feedFetcher, FeedFetcherCache feedInfoCache)
+ public void refreshEntries(String cacheDirPath) throws RollerException {
+
+ Date now = new Date();
+ long startTime = System.currentTimeMillis();
+ PlanetConfigData config = getConfiguration();
+
+ // can't continue without cache dir
+ if (cacheDirPath == null) {
+ log.warn("Planet cache directory not set, aborting refresh");
+ return;
+ }
+
+ // allow ${user.home} in cache dir property
+ String cacheDirName = cacheDirPath.replaceFirst(
+ "\\$\\{user.home}",System.getProperty("user.home"));
+
+ // allow ${catalina.home} in cache dir property
+ if (System.getProperty("catalina.home") != null) {
+ cacheDirName = cacheDirName.replaceFirst(
+ "\\$\\{catalina.home}",System.getProperty("catalina.home"));
+ }
+
+ // create cache dir if it does not exist
+ File cacheDir = null;
+ try {
+ cacheDir = new File(cacheDirName);
+ if (!cacheDir.exists()) cacheDir.mkdirs();
+ } catch (Exception e) {
+ log.error("Unable to create planet cache directory");
+ return;
+ }
+
+ // abort if cache dir is not writable
+ if (!cacheDir.canWrite()) {
+ log.error("Planet cache directory is not writable");
+ return;
+ }
+
+ FeedFetcherCache feedInfoCache =
+ new DiskFeedInfoCache(cacheDirName);
+
+ if (config.getProxyHost()!=null && config.getProxyPort() > 0) {
+ System.setProperty("proxySet", "true");
+ System.setProperty("http.proxyHost", config.getProxyHost());
+ System.setProperty("http.proxyPort",
+ Integer.toString(config.getProxyPort()));
+ }
+ /** a hack to set 15 sec timeouts for java.net.HttpURLConnection */
+ System.setProperty("sun.net.client.defaultConnectTimeout", "15000");
+ System.setProperty("sun.net.client.defaultReadTimeout", "15000");
+
+ FeedFetcher feedFetcher = new HttpURLFeedFetcher(feedInfoCache);
+ //FeedFetcher feedFetcher = new HttpClientFeedFetcher(feedInfoCache);
+ feedFetcher.setUsingDeltaEncoding(false);
+ feedFetcher.setUserAgent("RollerPlanetAggregator");
+
+ // Loop through all subscriptions in the system
+ Iterator subs = getAllSubscriptions();
+ while (subs.hasNext()) {
+
+ long subStartTime = System.currentTimeMillis();
+
+ PlanetSubscriptionData sub = (PlanetSubscriptionData)subs.next();
+
+ // reattach sub. sub gets detached as we iterate
+ sub = this.getSubscriptionById(sub.getId());
+
+ Set newEntries = this.getNewEntries(sub, feedFetcher, feedInfoCache);
+ int count = newEntries.size();
+
+ log.debug(" Entry count: " + count);
+ if (count > 0) {
+ sub.purgeEntries();
+ sub.addEntries(newEntries);
+ this.saveSubscription(sub);
+ this.strategy.flush();
+ }
+ long subEndTime = System.currentTimeMillis();
+ log.info(" " + count + " - "
+ + ((subEndTime-subStartTime)/1000.0)
+ + " seconds to process (" + count + ") entries of "
+ + sub.getFeedURL());
+ }
+ // Clear the aggregation cache
+ clearCachedAggregations();
+
+ long endTime = System.currentTimeMillis();
+ log.info("--- DONE --- Refreshed entries in "
+ + ((endTime-startTime)/1000.0) + " seconds");
+ }
+
+ protected Set getNewEntries(PlanetSubscriptionData sub,
+ FeedFetcher feedFetcher,
+ FeedFetcherCache feedInfoCache)
throws RollerException {
-
+
Set newEntries = new TreeSet();
+ SyndFeed feed = null;
+ URL feedURL = null;
+ Date lastUpdated = new Date();
try {
- // for local feeds, sub.author = website.handle
- if (sub.getAuthor() != null
- && sub.getFeedURL().endsWith(sub.getAuthor())) {
-
- logger.debug("Getting LOCAL feed " + sub.getFeedURL());
-
- // get corresponding website object
- WebsiteData website = (WebsiteData)strategy.newQuery(
- WebsiteData.class, "getByHandle&&Enabled")
- .execute(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
- logger.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, //user,
- null, // startDate
- new Date(), // endDate
- null, // catName
- WeblogEntryData.PUBLISHED, // status
- null, // sortBy
- null, // locale
- 0, // offset
- entryCount); // maxEntries
-
- sub.setLastUpdated(siteUpdated);
- saveSubscription(sub);
-
+ feedURL = new URL(sub.getFeedURL());
+ log.debug("Get feed from cache "+sub.getFeedURL());
+ feed = feedFetcher.retrieveFeed(feedURL);
+ SyndFeedInfo feedInfo = feedInfoCache.getFeedInfo(feedURL);
+ if (feedInfo.getLastModified() != null) {
+ long lastUpdatedLong =
+ ((Long)feedInfo.getLastModified()).longValue();
+ if (lastUpdatedLong != 0) {
+ lastUpdated = new Date(lastUpdatedLong);
}
- else {
- if (logger.isDebugEnabled()) {
- String msg = MessageFormat.format(
- " Skipping ({0} / {1})", new Object[] {
- siteUpdated, sub.getLastUpdated() });
- logger.debug(msg);
- }
+ }
+ Thread.sleep(100); // be nice
+ } catch (Exception e) {
+ log.warn("ERROR parsing " + sub.getFeedURL()
+ + " : " + e.getClass().getName() + " : " + e.getMessage());
+ log.debug(e);
+ return newEntries; // bail out
+ }
+ if (lastUpdated!=null && sub.getLastUpdated()!=null) {
+ Calendar feedCal = Calendar.getInstance();
+ feedCal.setTime(lastUpdated);
+
+ Calendar subCal = Calendar.getInstance();
+ subCal.setTime(sub.getLastUpdated());
+
+ if (!feedCal.after(subCal)) {
+ if (log.isDebugEnabled()) {
+ String msg = MessageFormat.format(
+ " Skipping ({0} / {1})",
+ new Object[] {
+ lastUpdated, sub.getLastUpdated()});
+ log.debug(msg);
}
- return null;
+ return newEntries; // bail out
}
}
- catch (Exception e) {
- logger.warn("Problem reading local feed", e);
+ if (feed.getPublishedDate() != null) {
+ sub.setLastUpdated(feed.getPublishedDate());
+ // saving sub here causes detachment issues, so we save it later
+ }
+
+ // Horrible kludge for Feeds without entry dates: most recent entry is
+ // given feed's last publish date (or yesterday if none exists) and
+ // earler entries are placed at once day intervals before that.
+ Calendar cal = Calendar.getInstance();
+ if (sub.getLastUpdated() != null) {
+ cal.setTime(sub.getLastUpdated());
+ } else {
+ cal.setTime(new Date());
+ cal.add(Calendar.DATE, -1);
}
- //return getNewEntriesRemote(sub, feedFetcher, feedInfoCache);
- return null;
+
+ // Populate subscription object with new entries
+ Iterator entries = feed.getEntries().iterator();
+ while (entries.hasNext()) {
+ try {
+ SyndEntry romeEntry = (SyndEntry) entries.next();
+ PlanetEntryData entry =
+ new PlanetEntryData(feed, romeEntry, sub);
+ log.debug("Entry title=" + entry.getTitle() + " content size=" + entry.getContent().length());
+ if (entry.getPubTime() == null) {
+ log.debug("No published date, assigning fake date for "+feedURL);
+ entry.setPubTime(new Timestamp(cal.getTimeInMillis()));
+ }
+ if (entry.getPermalink() == null) {
+ log.warn("No permalink, rejecting entry from "+feedURL);
+ } else {
+ newEntries.add(entry);
+ }
+ cal.add(Calendar.DATE, -1);
+ } catch (Exception e) {
+ log.error("ERROR processing subscription entry", e);
+ }
+ }
+ return newEntries;
}
- public void refreshEntries() throws RollerException {
- }
+ public void release() {}
}
Modified: incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperPropertiesManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperPropertiesManagerImpl.java?view=diff&rev=482428&r1=482427&r2=482428
==============================================================================
--- incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperPropertiesManagerImpl.java (original)
+++ incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperPropertiesManagerImpl.java Mon Dec 4 16:26:15 2006
@@ -18,16 +18,25 @@
*/
package org.apache.roller.business.datamapper;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.roller.RollerException;
-import org.apache.roller.model.PropertiesManager;
+import org.apache.roller.business.PropertiesManager;
+import org.apache.roller.business.Roller;
+import org.apache.roller.business.RollerFactory;
+import org.apache.roller.config.RollerRuntimeConfig;
+import org.apache.roller.config.runtime.ConfigDef;
+import org.apache.roller.config.runtime.DisplayGroup;
+import org.apache.roller.config.runtime.PropertyDef;
+import org.apache.roller.config.runtime.RuntimeConfigDefs;
+import org.apache.roller.pojos.RollerConfigData;
import org.apache.roller.pojos.RollerPropertyData;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
/*
* DatamapperPropertiesManagerImpl.java
*
@@ -36,51 +45,234 @@
*/
public class DatamapperPropertiesManagerImpl implements PropertiesManager {
- private DatamapperPersistenceStrategy strategy;
-
/** The logger instance for this class. */
- private static Log logger = LogFactory
- .getFactory().getInstance(DatamapperPropertiesManagerImpl.class);
+ private static Log log = LogFactory.getLog(DatamapperPropertiesManagerImpl.class);
+ private DatamapperPersistenceStrategy strategy;
+
/** Creates a new instance of DatamapperPropertiesManagerImpl */
- public DatamapperPropertiesManagerImpl
- (DatamapperPersistenceStrategy strategy) {
+ public DatamapperPropertiesManagerImpl (DatamapperPersistenceStrategy strategy) {
+ log.debug("Instantiating Hibernate Properties Manager");
+
this.strategy = strategy;
+
+ // TODO: and new method initialize(props)
+ init();
}
- public void release() {
+ /**
+ * Retrieve a single property by name.
+ */
+ public RollerPropertyData getProperty(String name) throws RollerException {
+ return (RollerPropertyData) strategy.load(RollerPropertyData.class,name);
}
- public void saveProperty(RollerPropertyData property)
- throws RollerException {
- strategy.store(property);
+
+ /**
+ * Retrieve all properties.
+ *
+ * Properties are returned in a Map to make them easy to lookup. The Map
+ * uses the property name as the key and the RollerPropertyData object
+ * as the value.
+ */
+ public Map getProperties() throws RollerException {
+
+ HashMap props = new HashMap();
+ List list = (List) strategy.newQuery(RollerPropertyData.class,
+ "RollerPropertyData.getAll").execute();
+ /*
+ * for convenience sake we are going to put the list of props
+ * into a map for users to access it. The value element of the
+ * hash still needs to be the RollerPropertyData object so that
+ * we can save the elements again after they have been updated
+ */
+ RollerPropertyData prop = null;
+ Iterator it = list.iterator();
+ while(it.hasNext()) {
+ prop = (RollerPropertyData) it.next();
+ props.put(prop.getName(), prop);
+ }
+
+ return props;
}
- public void saveProperties(Map properties)
- throws RollerException {
- Iterator it = properties.values().iterator();
- while (it.hasNext()) {
- strategy.store((RollerPropertyData)it.next());
+
+ /**
+ * Save a single property.
+ */
+ public void saveProperty(RollerPropertyData property) throws RollerException {
+
+ this.strategy.store(property);
+ }
+
+
+ /**
+ * Save all properties.
+ */
+ public void saveProperties(Map properties) throws RollerException {
+
+ // just go through the list and saveProperties each property
+ Iterator props = properties.values().iterator();
+ while (props.hasNext()) {
+ this.strategy.store((RollerPropertyData) props.next());
}
}
- public RollerPropertyData getProperty(String name)
- throws RollerException {
- return (RollerPropertyData)strategy.load(RollerPropertyData.class,
- name);
+
+ private void init() {
+ Map props = null;
+ try {
+ props = this.getProperties();
+
+ if(props.size() < 1) {
+ // empty props table ... try migrating, then load defaults
+ props = migrateOldRollerConfig(props);
+ props = initializeMissingProps(props);
+ } else {
+ // found existing props ... check for new props
+ props = initializeMissingProps(props);
+ }
+
+ // save our changes
+ this.saveProperties(props);
+ } catch (Exception e) {
+ log.fatal("Failed to initialize runtime configuration properties."+
+ "Please check that the database has been upgraded!", e);
+ throw new RuntimeException(e);
+ }
+
}
- public Map getProperties()
- throws RollerException {
- HashMap result = new HashMap();
- Collection properties = (Collection)strategy.newQuery
- (RollerPropertyData.class, null)
- .execute();
- for (Iterator it = properties.iterator(); it.hasNext();) {
- RollerPropertyData property = (RollerPropertyData)it.next();
- result.put(property.getName(), property);
+
+ /**
+ * Migrate data from the old roller config.
+ * This is called only if the existing runtime properties are empty.
+ */
+ private Map migrateOldRollerConfig(Map props) {
+ // try to get the old config
+ Roller roller = RollerFactory.getRoller();
+ RollerConfigData rollerConfig = null;
+
+ try {
+ rollerConfig = roller.getConfigManager().getRollerConfig();
+ } catch (Exception e) {
+ // We currently treat any exception obtaining the roller config
+ // as if we had not found it.
+ log.error(e);
}
- return result;
+
+ if (rollerConfig != null) {
+ log.info("Found old roller config ... doing migration to new runtime properties.");
+ // copy over data
+ props.put("site.name",
+ new RollerPropertyData("site.name", rollerConfig.getSiteName()));
+ props.put("site.description",
+ new RollerPropertyData("site.description", rollerConfig.getSiteDescription()));
+ props.put("site.adminemail",
+ new RollerPropertyData("site.adminemail", rollerConfig.getEmailAddress()));
+ props.put("site.absoluteurl",
+ new RollerPropertyData("site.absoluteurl", rollerConfig.getAbsoluteURL()));
+ props.put("site.linkbacks.enabled",
+ new RollerPropertyData("site.linkbacks.enabled", rollerConfig.getEnableLinkback().toString()));
+ props.put("users.registration.enabled",
+ new RollerPropertyData("users.registration.enabled", rollerConfig.getNewUserAllowed().toString()));
+ props.put("users.themes.path",
+ new RollerPropertyData("users.themes.path", rollerConfig.getUserThemes()));
+ props.put("users.editor.pages",
+ new RollerPropertyData("users.editor.pages", rollerConfig.getEditorPages()));
+ props.put("users.comments.enabled",
+ new RollerPropertyData("users.comments.enabled", "true"));
+ props.put("users.comments.autoformat",
+ new RollerPropertyData("users.comments.autoformat", rollerConfig.getAutoformatComments().toString()));
+ props.put("users.comments.escapehtml",
+ new RollerPropertyData("users.comments.escapehtml", rollerConfig.getEscapeCommentHtml().toString()));
+ props.put("users.comments.emailnotify",
+ new RollerPropertyData("users.comments.emailnotify", rollerConfig.getEmailComments().toString()));
+ props.put("uploads.enabled",
+ new RollerPropertyData("uploads.enabled", rollerConfig.getUploadEnabled().toString()));
+ props.put("uploads.types.allowed",
+ new RollerPropertyData("uploads.types.allowed", rollerConfig.getUploadAllow()));
+ props.put("uploads.types.forbid",
+ new RollerPropertyData("uploads.types.forbid", rollerConfig.getUploadForbid()));
+ props.put("uploads.file.maxsize",
+ new RollerPropertyData("uploads.file.maxsize", rollerConfig.getUploadMaxFileMB().toString()));
+ props.put("uploads.dir.maxsize",
+ new RollerPropertyData("uploads.dir.maxsize", rollerConfig.getUploadMaxDirMB().toString()));
+ /* no longer part of runtime config
+ props.put("aggregator.enabled",
+ new RollerPropertyData("aggregator.enabled", rollerConfig.getEnableAggregator().toString()));
+ props.put("aggregator.cache.enabled",
+ new RollerPropertyData("aggregator.cache.enabled", rollerConfig.getRssUseCache().toString()));
+ props.put("aggregator.cache.timeout",
+ new RollerPropertyData("aggregator.cache.timeout", rollerConfig.getRssCacheTime().toString()));
+ props.put("debug.memory.enabled",
+ new RollerPropertyData("debug.memory.enabled", rollerConfig.getMemDebug().toString()));
+ */
+ props.put("spam.blacklist",
+ new RollerPropertyData("spam.blacklist", rollerConfig.getRefererSpamWords()));
+ } else {
+ log.info("Old roller config not found ... default values will be loaded");
+ }
+
+ return props;
}
-
+
+
+ /**
+ * This method compares the property definitions in the RuntimeConfigDefs
+ * file with the properties in the given Map and initializes any properties
+ * that were not found in the Map.
+ *
+ * If the Map of props is empty/null then we will initialize all properties.
+ **/
+ private Map initializeMissingProps(Map props) {
+
+ if(props == null)
+ props = new HashMap();
+
+ // start by getting our runtimeConfigDefs
+ RuntimeConfigDefs runtimeConfigDefs =
+ RollerRuntimeConfig.getRuntimeConfigDefs();
+
+ // can't do initialization without our config defs
+ if(runtimeConfigDefs == null)
+ return props;
+
+ // iterator through all the definitions and add properties
+ // that are not already in our props map
+ ConfigDef configDef = null;
+ DisplayGroup dGroup = null;
+ PropertyDef propDef = null;
+ Iterator defs = runtimeConfigDefs.getConfigDefs().iterator();
+ while(defs.hasNext()) {
+ configDef = (ConfigDef) defs.next();
+
+ Iterator groups = configDef.getDisplayGroups().iterator();
+ while(groups.hasNext()) {
+ dGroup = (DisplayGroup) groups.next();
+
+ Iterator propdefs = dGroup.getPropertyDefs().iterator();
+ while(propdefs.hasNext()) {
+ propDef = (PropertyDef) propdefs.next();
+
+ // do we already have this prop? if not then add it
+ if(!props.containsKey(propDef.getName())) {
+ RollerPropertyData newprop =
+ new RollerPropertyData(propDef.getName(), propDef.getDefaultValue());
+
+ props.put(propDef.getName(), newprop);
+
+ log.info("Found uninitialized property "+propDef.getName()+
+ " ... setting value to ["+propDef.getDefaultValue()+"]");
+ }
+ }
+ }
+ }
+
+ return props;
+ }
+
+
+ public void release() {}
+
}
Modified: incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperQuery.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperQuery.java?view=diff&rev=482428&r1=482427&r2=482428
==============================================================================
--- incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperQuery.java (original)
+++ incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperQuery.java Mon Dec 4 16:26:15 2006
@@ -18,8 +18,6 @@
*/
package org.apache.roller.business.datamapper;
-import java.util.List;
-
/**
*
*/