Update of /cvsroot/roller/roller/src/org/roller/business
In directory sc8-pr-cvs1:/tmp/cvs-serv3968/src/org/roller/business
Modified Files:
BookmarkManagerImpl.java WeblogManagerImpl.java
UserManagerImpl.java
Log Message:
Hierarchical categories and some build script refactoring
Index: BookmarkManagerImpl.java
===================================================================
RCS file:
/cvsroot/roller/roller/src/org/roller/business/BookmarkManagerImpl.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** BookmarkManagerImpl.java 7 Dec 2003 16:38:07 -0000 1.6
--- BookmarkManagerImpl.java 1 Jan 2004 17:35:46 -0000 1.7
***************
*** 113,119 ****
public FolderData retrieveFolder(String id) throws RollerException
{
! FolderData fd = (FolderData)
! mStrategy.load(id, FolderData.class);
! return fd;
}
--- 113,117 ----
public FolderData retrieveFolder(String id) throws RollerException
{
! return (FolderData)mStrategy.load(id, FolderData.class);
}
***************
*** 298,306 ****
if (null == folder.getParent())
{
! return new String("");
}
else
{
! return getPath(folder.getParent()) + "/" + folder.getName();
}
}
--- 296,306 ----
if (null == folder.getParent())
{
! return new String("/");
}
else
{
! String parentPath = getPath(folder.getParent());
! parentPath = "/".equals(parentPath) ? "" : parentPath;
! return parentPath + "/" + folder.getName();
}
}
Index: WeblogManagerImpl.java
===================================================================
RCS file:
/cvsroot/roller/roller/src/org/roller/business/WeblogManagerImpl.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** WeblogManagerImpl.java 12 Dec 2003 02:57:24 -0000 1.4
--- WeblogManagerImpl.java 1 Jan 2004 17:35:46 -0000 1.5
***************
*** 129,133 ****
"website", Query.EQ, website);
! Condition userEnabled = factory.createCondition(
"parent", Query.IS_NULL );
--- 129,133 ----
"website", Query.EQ, website);
! Condition parentNull = factory.createCondition(
"parent", Query.IS_NULL );
***************
*** 136,140 ****
query.setWhere(factory.createCondition(
! Query.AND, specifiedWebsite, userEnabled, nameIsRoot));
List results = query.execute();
--- 136,140 ----
query.setWhere(factory.createCondition(
! Query.AND, specifiedWebsite, parentNull, nameIsRoot));
List results = query.execute();
***************
*** 152,155 ****
--- 152,244 ----
}
+ /**
+ * @see
org.roller.model.WeblogManager#getAllWeblogCategories(org.roller.pojos.WebsiteData)
+ */
+ public List getAllWeblogCategories(WebsiteData website) throws
RollerException
+ {
+ if (website == null) throw new RollerException("website is null");
+ QueryFactory factory = mStrategy.getQueryFactory();
+ Query query =
factory.createQuery(WeblogCategoryData.class.getName());
+ query.setWhere(factory.createCondition("website", Query.EQ, website));
+ return query.execute();
+ }
+
+ /**
+ * @see
org.roller.model.WeblogManager#getWeblogCategory(org.roller.pojos.WebsiteData,
java.lang.String)
+ */
+ public WeblogCategoryData getWeblogCategory(WebsiteData website, String
categoryPath) throws RollerException
+ {
+ return getWeblogCategoryByPath(website, null, categoryPath);
+ }
+
+ /**
+ * @see
org.roller.model.WeblogManager#getPath(org.roller.pojos.WeblogCategoryData)
+ */
+ public String getPath(WeblogCategoryData category)
+ {
+ if (null == category.getParent())
+ {
+ return new String("/");
+ }
+ else
+ {
+ String parentPath = getPath(category.getParent());
+ parentPath = "/".equals(parentPath) ? "" : parentPath;
+ return parentPath + "/" + category.getName();
+ }
+ }
+
+ /**
+ * @see
org.roller.model.WeblogManager#getWeblogCategoryByPath(org.roller.pojos.WebsiteData,
org.roller.pojos.WeblogCategoryData, java.lang.String)
+ */
+ public WeblogCategoryData getWeblogCategoryByPath(
+ WebsiteData website, WeblogCategoryData category, String path)
+ throws RollerException
+ {
+ final Iterator cats;
+ final String[] pathArray = Utilities.stringToStringArray(path, "/");
+
+ if (category == null && (null == path || "".equals(path.trim())))
+ {
+ throw new RollerException("Bad arguments.");
+ }
+
+ if (path.trim().equals("/"))
+ {
+ return getRootWeblogCategory(website);
+ }
+ else if (category == null || path.trim().startsWith("/"))
+ {
+ cats =
getRootWeblogCategory(website).getWeblogCategories().iterator();
+ }
+ else
+ {
+ cats = category.getWeblogCategories().iterator();
+ }
+
+ while (cats.hasNext())
+ {
+ WeblogCategoryData possibleMatch =
(WeblogCategoryData)cats.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 getWeblogCategoryByPath(website, possibleMatch,
pathString);
+ }
+ }
+ }
+
+ // The category did not match and neither did any sub-categories
+ return null;
+ }
+
public boolean isWeblogCategoryInUse(String catId) throws RollerException
{
***************
*** 934,937 ****
--- 1023,1027 ----
return base;
}
+
}
Index: UserManagerImpl.java
===================================================================
RCS file: /cvsroot/roller/roller/src/org/roller/business/UserManagerImpl.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** UserManagerImpl.java 12 Dec 2003 02:57:24 -0000 1.5
--- UserManagerImpl.java 1 Jan 2004 17:35:46 -0000 1.6
***************
*** 398,562 ****
}
! try
! {
!
! // We use storeValue object here in order to do everything in one
! // database transaction. If there is a failure, we need to be able
! // to roll back all of the objects associated with the new user.
!
! mStrategy.store(ud);
!
! RoleData rd = new RoleData(
! null,ud.getUserName(),ud.getId(),"editor");
! mStrategy.store(rd);
!
! //WeblogManager wmgr = mRoller.getWeblogManager();
!
! //
! // CREATE WEBSITE AND CATEGORIES FOR USER
! //
!
! WebsiteData website = new WebsiteData(null,
! ud.getFullName()+"'s Weblog", // name
! ud.getFullName()+"'s Weblog", // description
! ud, // userId
! "dummy", // defaultPageId
! "dummy", // weblogDayPageId
! Boolean.TRUE, // enableBloggerApi
! "dummy", // bloggerCategoryId
! "editor-text.jsp", // editorPage
! "", // ignoreWords
! Boolean.TRUE); // allowComments
! website.setAutoformatDefault(Boolean.TRUE);
! mStrategy.store(website);
! WeblogCategoryData rootCat = new WeblogCategoryData(
! null, // id
! website, // websiteId
! null,
! "General", // name
! "General", // description
! null ); // image
! mStrategy.store(rootCat);
!
! WeblogCategoryData generalCat = new WeblogCategoryData(
! null, // id
! website, // websiteId
! rootCat,
! "General", // name
! "General", // description
! null ); // image
! mStrategy.store(generalCat);
!
! WeblogCategoryData javaCat = new WeblogCategoryData(
! null, // id
! website, // websiteId
! rootCat,
! "Java", // name
! "Java", // description
! null ); // image
! mStrategy.store(javaCat);
!
! WeblogCategoryData musicCat = new WeblogCategoryData(
! null, // id
! website, // websiteId
! rootCat,
! "Music", // name
! "Music", // description
! null ); // image
! mStrategy.store(musicCat);
!
! website.setBloggerCategoryId(generalCat.getId());
! Integer zero = new Integer(0);
! BookmarkManager bmgr = mRoller.getBookmarkManager();
!
! FolderData root = bmgr.createFolder(
! null, "root", "root", website);
! mStrategy.store(root);
! FolderData blogroll = bmgr.createFolder(
! root, "Blogroll", "Blogroll", website);
! mStrategy.store(blogroll);
! BookmarkData b1 = bmgr.createBookmark(
! blogroll, "Dave Johnson", "",
! "http://rollerweblogger.org/page/roller",
! "http://rollerweblogger.org/rss/roller",
! zero, zero, null);
! mStrategy.store(b1);
! BookmarkData b2 = bmgr.createBookmark(
! blogroll, "Matt Raible", "",
! "http://raibledesigns.com",
! "http://raibledesigns.com/rss",
! zero, zero, null);
! mStrategy.store(b2);
! BookmarkData b3 = bmgr.createBookmark(
! blogroll, "Lance Lavandowska", "",
! "http://brainopolis.dnsalias.com/roller/page/lance/",
! "http://brainopolis.dnsalias.com/roller/rss/lance/",
! zero, zero, null);
! mStrategy.store(b3);
!
!
! FolderData news = bmgr.createFolder(
! root, "News", "News", website);
! mStrategy.store(news);
! BookmarkData b5 = bmgr.createBookmark(
! news, "CNN", "",
! "http://www.cnn.com",
! "",
! zero, zero, null);
! mStrategy.store(b5);
! BookmarkData b6 = bmgr.createBookmark(
! news, "NY Times", "",
! "http://nytimes.com",
! "",
! zero, zero, null);
! mStrategy.store(b6);
! //
! // READ THEME FILES AND CREATE PAGES FOR USER
! //
! Iterator iter = pages.keySet().iterator();
! while ( iter.hasNext() )
! {
! String pageName = (String) iter.next();
! String sb = (String)pages.get( pageName );
!
! // Store each Velocity template as a page
! PageData pd = new PageData( null,
! website, // website
! pageName, // name
! pageName, // description
! pageName, // link
! sb, // template
! new Date() // updateTime
! );
! mStrategy.store(pd);
!
! if ( pd.getName().equals("Weblog") )
! {
! website.setDefaultPageId(pd.getId());
! }
! else if ( pd.getName().equals("_day") )
! {
! website.setWeblogDayPageId(pd.getId());
! }
! }
!
! // Save website with blogger cat id, defauld page id and day id
! mStrategy.store(website);
!
! //
! // MAKE FIRST WEBLOG POST
! //
// Timestamp ts = new Timestamp(new Date().getTime());
// WeblogEntryData post = new WeblogEntryData( mRoller, null,
--- 398,555 ----
}
! mStrategy.store(ud);
!
! RoleData rd = new RoleData(
! null,ud.getUserName(),ud.getId(),"editor");
! mStrategy.store(rd);
!
! //WeblogManager wmgr = mRoller.getWeblogManager();
!
! //
! // CREATE WEBSITE AND CATEGORIES FOR USER
! //
!
! WebsiteData website = new WebsiteData(null,
! ud.getFullName()+"'s Weblog", // name
! ud.getFullName()+"'s Weblog", // description
! ud, // userId
! "dummy", // defaultPageId
! "dummy", // weblogDayPageId
! Boolean.TRUE, // enableBloggerApi
! "dummy", // bloggerCategoryId
! "editor-text.jsp", // editorPage
! "", // ignoreWords
! Boolean.TRUE); // allowComments
! website.setAutoformatDefault(Boolean.TRUE);
! mStrategy.store(website);
! WeblogCategoryData rootCat = new WeblogCategoryData(
! null, // id
! website, // websiteId
! null,
! "root", // name
! "root", // description
! null ); // image
! mStrategy.store(rootCat);
!
! WeblogCategoryData generalCat = new WeblogCategoryData(
! null, // id
! website, // websiteId
! rootCat,
! "General", // name
! "General", // description
! null ); // image
! mStrategy.store(generalCat);
! WeblogCategoryData javaCat = new WeblogCategoryData(
! null, // id
! website, // websiteId
! rootCat,
! "Java", // name
! "Java", // description
! null ); // image
! mStrategy.store(javaCat);
! WeblogCategoryData musicCat = new WeblogCategoryData(
! null, // id
! website, // websiteId
! rootCat,
! "Music", // name
! "Music", // description
! null ); // image
! mStrategy.store(musicCat);
!
! website.setBloggerCategoryId(generalCat.getId());
!
! Integer zero = new Integer(0);
!
! BookmarkManager bmgr = mRoller.getBookmarkManager();
!
! FolderData root = bmgr.createFolder(
! null, "root", "root", website);
! mStrategy.store(root);
! FolderData blogroll = bmgr.createFolder(
! root, "Blogroll", "Blogroll", website);
! mStrategy.store(blogroll);
! BookmarkData b1 = bmgr.createBookmark(
! blogroll, "Dave Johnson", "",
! "http://rollerweblogger.org/page/roller",
! "http://rollerweblogger.org/rss/roller",
! zero, zero, null);
! mStrategy.store(b1);
! BookmarkData b2 = bmgr.createBookmark(
! blogroll, "Matt Raible", "",
! "http://raibledesigns.com",
! "http://raibledesigns.com/rss",
! zero, zero, null);
! mStrategy.store(b2);
! BookmarkData b3 = bmgr.createBookmark(
! blogroll, "Lance Lavandowska", "",
! "http://brainopolis.dnsalias.com/roller/page/lance/",
! "http://brainopolis.dnsalias.com/roller/rss/lance/",
! zero, zero, null);
! mStrategy.store(b3);
!
!
! FolderData news = bmgr.createFolder(
! root, "News", "News", website);
! mStrategy.store(news);
! BookmarkData b5 = bmgr.createBookmark(
! news, "CNN", "",
! "http://www.cnn.com",
! "",
! zero, zero, null);
! mStrategy.store(b5);
! BookmarkData b6 = bmgr.createBookmark(
! news, "NY Times", "",
! "http://nytimes.com",
! "",
! zero, zero, null);
! mStrategy.store(b6);
! //
! // READ THEME FILES AND CREATE PAGES FOR USER
! //
! Iterator iter = pages.keySet().iterator();
! while ( iter.hasNext() )
! {
! String pageName = (String) iter.next();
! String sb = (String)pages.get( pageName );
!
! // Store each Velocity template as a page
! PageData pd = new PageData( null,
! website, // website
! pageName, // name
! pageName, // description
! pageName, // link
! sb, // template
! new Date() // updateTime
! );
! mStrategy.store(pd);
+ if ( pd.getName().equals("Weblog") )
+ {
+ website.setDefaultPageId(pd.getId());
+ }
+ else if ( pd.getName().equals("_day") )
+ {
+ website.setWeblogDayPageId(pd.getId());
+ }
+ }
+
+ // Save website with blogger cat id, defauld page id and day id
+ mStrategy.store(website);
+
+ //
+ // MAKE FIRST WEBLOG POST
+ //
+
// Timestamp ts = new Timestamp(new Date().getTime());
// WeblogEntryData post = new WeblogEntryData( mRoller, null,
***************
*** 572,590 ****
// mStrategy.storePersistentObject(post);
- }
- catch (RollerException pe)
- {
- try
- {
- mStrategy.rollback();
- }
- catch ( Exception e )
- {
- mLogger.error("ERROR rolling back new user transaction");
- }
-
- mLogger.error(msg, pe);
- throw pe;
- }
}
--- 565,568 ----
***************
*** 608,618 ****
// remove folders (takes bookmarks with it)
! Iterator folders =
bMgr.getRootFolder(website).getFolders().iterator();
! while (folders.hasNext())
! {
! FolderData folder = (FolderData) folders.next();
! folder.remove();
! }
!
// remove entries
List entries =
--- 586,592 ----
// remove folders (takes bookmarks with it)
! FolderData rootFolder = bMgr.getRootFolder(website);
! if (null != rootFolder) rootFolder.remove();
!
// remove entries
List entries =
***************
*** 638,649 ****
// remove categories
! List cats = wMgr.getWeblogCategories(website);
! for (Iterator wbcItr = cats.iterator(); wbcItr.hasNext();) {
! WeblogCategoryData category = (WeblogCategoryData)
wbcItr.next();
! mStrategy.remove(
! category.getId(),
! WeblogCategoryData.class);
! }
!
// remove roles
--- 612,617 ----
// remove categories
! WeblogCategoryData rootCat = wMgr.getRootWeblogCategory(website);
! if (null != rootCat) rootCat.remove();
// remove roles
***************
*** 661,663 ****
--- 629,681 ----
mStrategy.remove( user.getId(), UserData.class);
}
+
+ /**
+ * Currently, this implementation just checks for root categories.
+ * If a website does not have a root category, this will create one.
+ *
+ * @see org.roller.model.Roller#upgradeIfNeeded()
+ */
+ public void repairIfNeeded() throws RollerException
+ {
+ QueryFactory factory = mStrategy.getQueryFactory();
+
+ // iterate through websites
+ Query websiteQuery =
+ factory.createQuery(WebsiteData.class.getName());
+ Iterator websites = websiteQuery.execute().iterator();
+ while (websites.hasNext())
+ {
+
+ // Ensure that website has a root category
+ WebsiteData wd = (WebsiteData) websites.next();
+ Query rootQuery =
factory.createQuery(WeblogCategoryData.class.getName());
+ rootQuery.setWhere( factory.createCondition(
+ Query.AND,
+ factory.createCondition("website", Query.EQ, wd),
+ factory.createCondition("name", Query.EQ, "root"),
+ factory.createCondition("parent", Query.IS_NULL)));
+ List roots = rootQuery.execute();
+
+ if (roots.size() == 0)
+ {
+ WeblogCategoryData rootCat =
+ mRoller.getWeblogManager().createWeblogCategory(
+ wd, null, "root", "root", null);
+ mRoller.getWeblogManager().storeWeblogCategory(rootCat);
+
+ // iterate through cats in website
+ Query allCats =
+ factory.createQuery(WeblogCategoryData.class.getName());
+ allCats.setWhere(
+ factory.createCondition("name", Query.NE, "root"));
+ Iterator cats = allCats.execute().iterator();
+ while (cats.hasNext())
+ {
+ WeblogCategoryData cat = (WeblogCategoryData) cats.next();
+ cat.setParent(rootCat);
+ }
+ }
+ }
+ }
+
}
-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills. Sign up for IBM's
Free Linux Tutorials. Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
|