roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r475368 [2/2] - in /incubator/roller/trunk: metadata/database/ metadata/database/hibernate/ src/org/apache/roller/business/ src/org/apache/roller/business/hibernate/ src/org/apache/roller/pojos/ src/org/apache/roller/ui/authoring/struts/for...
Date Wed, 15 Nov 2006 19:14:26 GMT
Modified: incubator/roller/trunk/src/org/apache/roller/pojos/WeblogCategoryData.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/pojos/WeblogCategoryData.java?view=diff&rev=475368&r1=475367&r2=475368
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/pojos/WeblogCategoryData.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/pojos/WeblogCategoryData.java Wed Nov 15
11:14:24 2006
@@ -18,12 +18,11 @@
 
 package org.apache.roller.pojos;
 
-import java.util.Iterator;
-import java.util.LinkedList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 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.util.PojoUtil;
@@ -35,10 +34,10 @@
  * @struts.form include-all="true"
  *
  * @ejb:bean name="WeblogCategoryData"
- * @hibernate.class lazy="false" table="weblogcategory"
+ * @hibernate.class lazy="true" table="weblogcategory"
  * @hibernate.cache usage="read-write"
  */
-public class WeblogCategoryData extends HierarchicalPersistentObject {
+public class WeblogCategoryData extends PersistentObject {
     
     public static final long serialVersionUID = 1435782148712018954L;
     
@@ -47,10 +46,11 @@
     private String description = null;
     private String image = null;
     
-    private String cachedPath = null;
-    
     private WebsiteData website = null;
-    private List weblogCategories = null;
+    private WeblogCategoryData parentCategory = null;
+    private Set childCategories = new HashSet();
+    
+    private String cachedPath = null;
     
     
     public WeblogCategoryData() {
@@ -65,10 +65,10 @@
             java.lang.String image) {
         this.id = id;
         this.website = website;
-        this.mNewParent = parent;
         this.name = name;
         this.description = description;
         this.image = image;
+        this.parentCategory = parent;
     }
     
     public WeblogCategoryData(WeblogCategoryData otherData) {
@@ -85,11 +85,8 @@
         this.description = other.getDescription();
         this.image = other.getImage();
         
-        try {
-            this.mNewParent = other.getParent();
-        } catch(RollerException re) {
-            // why does this throw an exception?
-        }
+        this.parentCategory = other.getParent();
+        this.childCategories = other.getWeblogCategories();
     }
     
     
@@ -204,18 +201,24 @@
     
     
     /**
-     * Get path in category hierarhcy.
+     * Get path in category hierarchy.
+     *
+     * TODO: category path should be persisted.
      *
      * @roller.wrapPojoMethod type="simple"
      */
     public String getPath() {
+        
         if (null == cachedPath) {
-            try {
-                cachedPath = RollerFactory.getRoller().getWeblogManager().getPath(this);
-            } catch (RollerException e) {
-                throw new RuntimeException(e);
+            if (getParent() == null) {
+                return "/";
+            } else {
+                String parentPath = getParent().getPath();
+                parentPath = "/".equals(parentPath) ? "" : parentPath;
+                return parentPath + "/" + this.name;
             }
         }
+        
         return cachedPath;
     }
     /** TODO: fix formbean generation so this is not needed. */
@@ -224,14 +227,13 @@
     
     /**
      * @roller.wrapPojoMethod type="pojo"
-     * @ejb:persistent-field
      *
      * @hibernate.many-to-one column="websiteid" cascade="none" not-null="true"
      */
     public WebsiteData getWebsite() {
         return website;
     }
-    /** @ejb:persistent-field */
+    
     public void setWebsite(WebsiteData website) {
         this.website = website;
     }
@@ -241,22 +243,15 @@
      * Return parent category, or null if category is root of hierarchy.
      *
      * @roller.wrapPojoMethod type="pojo"
+     *
+     * @hibernate.many-to-one column="parentid" cascade="none" not-null="false"
      */
-    public WeblogCategoryData getParent() throws RollerException {
-        if (mNewParent != null) {
-            // Category has new parent, so return that
-            return (WeblogCategoryData)mNewParent;
-        } else if (getParentAssoc() != null) {
-            // Return parent found in database
-            return ((WeblogCategoryAssoc)getParentAssoc()).getAncestorCategory();
-        } else {
-            return null;
-        }
+    public WeblogCategoryData getParent() {
+        return this.parentCategory;
     }
     
-    /** Set parent category, database will be updated when object is saved. */
-    public void setParent(HierarchicalPersistentObject parent) {
-        mNewParent = parent;
+    public void setParent(WeblogCategoryData parent) {
+        this.parentCategory = parent;
     }
     
     
@@ -264,37 +259,18 @@
      * Query to get child categories of this category.
      *
      * @roller.wrapPojoMethod type="pojo-collection" class="org.apache.roller.pojos.WeblogCategoryData"
+     *
+     * @hibernate.set lazy="true" inverse="true" cascade="delete"
+     * @hibernate.collection-key column="parentid"
+     * @hibernate.collection-one-to-many class="org.apache.roller.pojos.WeblogCategoryData"
      */
-    public List getWeblogCategories() throws RollerException {
-        if (weblogCategories == null) {
-            weblogCategories = new LinkedList();
-            List childAssocs = getChildAssocs();
-            Iterator childIter = childAssocs.iterator();
-            while (childIter.hasNext()) {
-                WeblogCategoryAssoc assoc =
-                        (WeblogCategoryAssoc) childIter.next();
-                weblogCategories.add(assoc.getCategory());
-            }
-        }
-        return weblogCategories;
+    public Set getWeblogCategories() {
+        return this.childCategories;
     }
     
-    
-    /**
-     * Determine if category is in use. Returns true if any weblog entries
-     * use this category or any of it's subcategories.
-     *
-     * @roller.wrapPojoMethod type="simple"
-     */
-    public boolean isInUse() {
-        try {
-            return RollerFactory.getRoller().getWeblogManager().isWeblogCategoryInUse(this);
-        } catch (RollerException e) {
-            throw new RuntimeException(e);
-        }
+    private void setWeblogCategories(Set cats) {
+        this.childCategories = cats;
     }
-    /** TODO: fix form generation so this is not needed. */
-    public void setInUse(boolean dummy) {}
     
     
     /**
@@ -317,91 +293,37 @@
     /**
      * @roller.wrapPojoMethod type="simple"
      */
-    public boolean descendentOf(WeblogCategoryData ancestor)
-    throws RollerException {
-        return RollerFactory.getRoller().getWeblogManager().isDescendentOf(this, ancestor);
-    }
-    
-    
-    /**
-     * @see org.apache.roller.pojos.HierarchicalPersistentObject#createAssoc(
-     * org.apache.roller.pojos.HierarchicalPersistentObject,
-     * org.apache.roller.pojos.HierarchicalPersistentObject, java.lang.String)
-     */
-    public Assoc createAssoc(
-            HierarchicalPersistentObject object,
-            HierarchicalPersistentObject associatedObject,
-            String relation) throws RollerException {
-        return new WeblogCategoryAssoc(null,
-                (WeblogCategoryData)object,
-                (WeblogCategoryData)associatedObject,
-                relation);
-    }
-    
-    
-    /**
-     * @see org.apache.roller.pojos.HierarchicalPersistentObject#getAssocClass()
-     */
-    public Class getAssocClass() {
-        return WeblogCategoryAssoc.class;
-    }
-    
-    /** TODO: fix Struts form generation template so this is not needed. */
-    public void setAssocClassName(String dummy) {};
-    
-    
-    /**
-     * @see org.apache.roller.pojos.HierarchicalPersistentObject#getObjectPropertyName()
-     *
-     * @roller.wrapPojoMethod type="simple"
-     */
-    public String getObjectPropertyName() {
-        return "category";
+    public boolean descendentOf(WeblogCategoryData ancestor) {
+        
+        // if this is root then we can't be a descendent
+        if(getParent() == null) {
+            return false;
+        } else {
+            // if ancestor is our parent then we are a descendent
+            if(getParent().equals(ancestor)) {
+                return true;
+            } else {
+                // see if our parent is a descendent
+                return getParent().descendentOf(ancestor);
+            }
+        }
     }
     
-    /** TODO: fix Struts form generation template so this is not needed. */
-    public void setObjectPropertyName(String dummy) {};
-    
     
     /**
-     * @see org.apache.roller.pojos.HierarchicalPersistentObject#getAncestorPropertyName()
+     * Determine if category is in use. Returns true if any weblog entries
+     * use this category or any of it's subcategories.
      *
      * @roller.wrapPojoMethod type="simple"
      */
-    public String getAncestorPropertyName() {
-        return "ancestorCategory";
-    }
-    
-    /** TODO: fix Struts form generation template so this is not needed. */
-    public void setAncestorPropertyName(String dummy) {};
-    
-    
-    /**
-     * @see org.apache.roller.pojos.HierarchicalPersistentObject#getParentAssoc()
-     */
-    public Assoc getParentAssoc() throws RollerException {
-        return RollerFactory.getRoller().getWeblogManager().getWeblogCategoryParentAssoc(this);
-    }
-    
-    /**
-     * @see org.apache.roller.pojos.HierarchicalPersistentObject#getChildAssocs()
-     */
-    public List getChildAssocs() throws RollerException {
-        return RollerFactory.getRoller().getWeblogManager().getWeblogCategoryChildAssocs(this);
-    }
-    
-    /**
-     * @see org.apache.roller.pojos.HierarchicalPersistentObject#getAllDescendentAssocs()
-     */
-    public List getAllDescendentAssocs() throws RollerException {
-        return RollerFactory.getRoller().getWeblogManager().getAllWeblogCategoryDecscendentAssocs(this);
-    }
-    
-    /**
-     * @see org.apache.roller.pojos.HierarchicalPersistentObject#getAncestorAssocs()
-     */
-    public List getAncestorAssocs() throws RollerException {
-        return RollerFactory.getRoller().getWeblogManager().getWeblogCategoryAncestorAssocs(this);
+    public boolean isInUse() {
+        try {
+            return RollerFactory.getRoller().getWeblogManager().isWeblogCategoryInUse(this);
+        } catch (RollerException e) {
+            throw new RuntimeException(e);
+        }
     }
+    /** TODO: fix form generation so this is not needed. */
+    public void setInUse(boolean dummy) {}
     
 }

Modified: incubator/roller/trunk/src/org/apache/roller/pojos/WeblogEntryData.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/pojos/WeblogEntryData.java?view=diff&rev=475368&r1=475367&r2=475368
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/pojos/WeblogEntryData.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/pojos/WeblogEntryData.java Wed Nov 15 11:14:24
2006
@@ -59,7 +59,7 @@
  *
  * @ejb:bean name="WeblogEntryData"
  * @struts.form include-all="true"
- * @hibernate.class lazy="false" table="weblogentry"
+ * @hibernate.class lazy="true" table="weblogentry"
  * @hibernate.cache usage="read-write"
  */
 public class WeblogEntryData extends PersistentObject implements Serializable {

Modified: incubator/roller/trunk/src/org/apache/roller/pojos/WeblogEntryTagAggregateData.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/pojos/WeblogEntryTagAggregateData.java?view=diff&rev=475368&r1=475367&r2=475368
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/pojos/WeblogEntryTagAggregateData.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/pojos/WeblogEntryTagAggregateData.java Wed
Nov 15 11:14:24 2006
@@ -30,7 +30,7 @@
  *
  * @ejb:bean name="WeblogEntryTagAggregateData"
  * @struts.form include-all="true"
- * @hibernate.class lazy="false" table="roller_weblogentrytagagg"
+ * @hibernate.class lazy="true" table="roller_weblogentrytagagg"
  * @hibernate.cache usage="read-write"
  */
 public class WeblogEntryTagAggregateData extends PersistentObject

Modified: incubator/roller/trunk/src/org/apache/roller/pojos/WeblogEntryTagData.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/pojos/WeblogEntryTagData.java?view=diff&rev=475368&r1=475367&r2=475368
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/pojos/WeblogEntryTagData.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/pojos/WeblogEntryTagData.java Wed Nov 15
11:14:24 2006
@@ -31,7 +31,7 @@
  *
  * @ejb:bean name="WeblogEntryTagData"
  * @struts.form include-all="true"
- * @hibernate.class lazy="false" table="roller_weblogentrytag"
+ * @hibernate.class lazy="true" table="roller_weblogentrytag"
  * @hibernate.cache usage="read-write"
  */
 public class WeblogEntryTagData extends PersistentObject

Modified: incubator/roller/trunk/src/org/apache/roller/pojos/WeblogTemplate.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/pojos/WeblogTemplate.java?view=diff&rev=475368&r1=475367&r2=475368
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/pojos/WeblogTemplate.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/pojos/WeblogTemplate.java Wed Nov 15 11:14:24
2006
@@ -34,7 +34,7 @@
  *
  * @ejb:bean name="WeblogTemplate"
  * @struts.form include-all="true"
- * @hibernate.class lazy="false" table="webpage"
+ * @hibernate.class lazy="true" table="webpage"
  * @hibernate.cache usage="read-write"
  */
 public class WeblogTemplate extends PersistentObject

Modified: incubator/roller/trunk/src/org/apache/roller/pojos/WebsiteData.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/pojos/WebsiteData.java?view=diff&rev=475368&r1=475367&r2=475368
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/pojos/WebsiteData.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/pojos/WebsiteData.java Wed Nov 15 11:14:24
2006
@@ -23,10 +23,12 @@
 import java.util.Calendar;
 import java.util.Collections;
 import java.util.Date;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Set;
 import java.util.TimeZone;
 import java.util.TreeMap;
 import org.apache.commons.lang.StringUtils;
@@ -54,7 +56,7 @@
  *
  * @ejb:bean name="WebsiteData"
  * @struts.form include-all="true"
- * @hibernate.class lazy="false"  table="website"
+ * @hibernate.class lazy="true"  table="website"
  * @hibernate.cache usage="read-write"
  */
 public class WebsiteData extends org.apache.roller.pojos.PersistentObject
@@ -493,7 +495,7 @@
     /**
      * @roller.wrapPojoMethod type="simple"
      * @ejb:persistent-field
-     * @hibernate.many-to-one column="bloggercatid" non-null="false"
+     * @hibernate.many-to-one column="bloggercatid" non-null="false" cascade="none"
      */
     public WeblogCategoryData getBloggerCategory() {
         return bloggerCategory;
@@ -511,7 +513,7 @@
      *
      * @roller.wrapPojoMethod type="pojo"
      * @ejb:persistent-field
-     * @hibernate.many-to-one column="defaultcatid" non-null="false"
+     * @hibernate.many-to-one column="defaultcatid" non-null="false" cascade="none"
      */
     public WeblogCategoryData getDefaultCategory() {
         return defaultCategory;
@@ -1130,14 +1132,14 @@
      * Returns categories under the default category of the weblog.
      * @roller.wrapPojoMethod type="pojo-collection" class="org.apache.roller.pojos.WeblogCategoryData"
      */
-    public List getWeblogCategories() {
-        List ret = new ArrayList();
-        try {           
+    public Set getWeblogCategories() {
+        Set ret = new HashSet();
+//        try {           
             WeblogCategoryData category = this.getDefaultCategory();
             ret = category.getWeblogCategories();
-        } catch (RollerException e) {
-            log.error("ERROR: fetching categories", e);
-        }
+//        } catch (RollerException e) {
+//            log.error("ERROR: fetching categories", e);
+//        }
         return ret;
     }
     
@@ -1145,8 +1147,8 @@
     /**
      * @roller.wrapPojoMethod type="pojo-collection" class="org.apache.roller.pojos.WeblogCategoryData"
      */
-    public List getWeblogCategories(String categoryPath) {
-        List ret = new ArrayList();
+    public Set getWeblogCategories(String categoryPath) {
+        Set ret = new HashSet();
         try {
             Roller roller = RollerFactory.getRoller();
             WeblogManager wmgr = roller.getWeblogManager();            

Modified: incubator/roller/trunk/src/org/apache/roller/ui/authoring/struts/formbeans/WeblogCategoryFormEx.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/authoring/struts/formbeans/WeblogCategoryFormEx.java?view=diff&rev=475368&r1=475367&r2=475368
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/ui/authoring/struts/formbeans/WeblogCategoryFormEx.java
(original)
+++ incubator/roller/trunk/src/org/apache/roller/ui/authoring/struts/formbeans/WeblogCategoryFormEx.java
Wed Nov 15 11:14:24 2006
@@ -81,14 +81,7 @@
     public void copyFrom(WeblogCategoryData dataHolder, java.util.Locale locale) throws RollerException
     {
         super.copyFrom(dataHolder, locale);
-        try
-        {
             mParentId = dataHolder.getParent().getId();
-        }
-        catch (RollerException e)
-        {
-            throw new RuntimeException("ERROR fetching parent category.");
-        }
     }
 
 }

Modified: incubator/roller/trunk/src/org/apache/roller/ui/core/RollerSession.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/core/RollerSession.java?view=diff&rev=475368&r1=475367&r2=475368
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/ui/core/RollerSession.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/ui/core/RollerSession.java Wed Nov 15 11:14:24
2006
@@ -42,6 +42,7 @@
 
 /**
  * Roller session handles session startup and shutdown.
+ *
  * @web.listener
  */
 public class RollerSession 
@@ -49,7 +50,8 @@
     
     static final long serialVersionUID = 5890132909166913727L;
     
-    private UserData authenticatedUser = null;
+    // the id of the user represented by this session
+    private String userId = null;
     
     private static Log log = LogFactory.getLog(RollerSession.class);
     
@@ -141,7 +143,18 @@
      * Authenticated user associated with this session.
      */
     public UserData getAuthenticatedUser() {
-        return authenticatedUser;
+        
+        UserData authenticUser = null;
+        if(userId != null) {
+            try {
+                UserManager mgr = RollerFactory.getRoller().getUserManager();
+                authenticUser = mgr.getUser(userId);
+            } catch (RollerException ex) {
+                log.warn("Error looking up authenticated user "+userId, ex);
+            }
+        }
+        
+        return authenticUser;
     }
     
     
@@ -149,7 +162,7 @@
      * Authenticated user associated with this session.
      */
     public void setAuthenticatedUser(UserData authenticatedUser) {
-        this.authenticatedUser = authenticatedUser;
+        this.userId = authenticatedUser.getId();
     }
     
     

Modified: incubator/roller/trunk/src/org/apache/roller/ui/rendering/plugins/BookmarkPlugin.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/rendering/plugins/BookmarkPlugin.java?view=diff&rev=475368&r1=475367&r2=475368
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/ui/rendering/plugins/BookmarkPlugin.java
(original)
+++ incubator/roller/trunk/src/org/apache/roller/ui/rendering/plugins/BookmarkPlugin.java
Wed Nov 15 11:14:24 2006
@@ -93,19 +93,17 @@
      * @return
      */
     private String lookInFolders(String text, Collection folders) {
+        
         Iterator it = folders.iterator();
         while (it.hasNext()) {
             FolderData folder = (FolderData)it.next();
             text = matchBookmarks(text, folder);
             
-            try {
-                if (!folder.getFolders().isEmpty()) {
-                    lookInFolders(text, folder.getFolders());
-                }
-            } catch (RollerException e) {
-                mLogger.error("Error getting child Folders");
+            if (!folder.getFolders().isEmpty()) {
+                lookInFolders(text, folder.getFolders());
             }
         }
+        
         return text;
     }
     

Modified: incubator/roller/trunk/src/org/apache/roller/ui/rendering/velocity/deprecated/OldWeblogPageModel.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/rendering/velocity/deprecated/OldWeblogPageModel.java?view=diff&rev=475368&r1=475367&r2=475368
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/ui/rendering/velocity/deprecated/OldWeblogPageModel.java
(original)
+++ incubator/roller/trunk/src/org/apache/roller/ui/rendering/velocity/deprecated/OldWeblogPageModel.java
Wed Nov 15 11:14:24 2006
@@ -23,9 +23,11 @@
 import java.util.Collection;
 import java.util.Date;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.TimeZone;
 import javax.servlet.http.HttpServletRequest;
 import org.apache.commons.logging.Log;
@@ -604,15 +606,15 @@
     //------------------------------------------------------------------------
     
     /** Encapsulates WeblogManager.getWeblogCategories() */
-    public List getWeblogCategories(String categoryName) {
-        List ret = null;
+    public Set getWeblogCategories(String categoryName) {
+        Set ret = null;
         if (VELOCITY_NULL.equals(categoryName)) categoryName = null;
         
         // Make sure we have not already fetched this category.
         if (categoryName != null) {
-            ret = (List)mCategories.get(categoryName);
+            ret = (Set)mCategories.get(categoryName);
         } else {
-            ret = (List)mCategories.get("zzz_null_zzz");
+            ret = (Set)mCategories.get("zzz_null_zzz");
         }
         
         if (null == ret) {
@@ -625,14 +627,14 @@
                     category = mWebsite.getDefaultCategory();
                 }
                 
-                List mRet = category.getWeblogCategories();
+                Set mRet = category.getWeblogCategories();
                 
                 // wrap pojos
-                ret = new ArrayList(mRet.size());
+                ret = new HashSet(mRet.size());
                 Iterator it = mRet.iterator();
                 int i=0;
                 while(it.hasNext()) {
-                    ret.add(i, WeblogCategoryDataWrapper.wrap((WeblogCategoryData)it.next()));
+                    ret.add(WeblogCategoryDataWrapper.wrap((WeblogCategoryData)it.next()));
                     i++;
                 }
                 if (categoryName != null) {

Modified: incubator/roller/trunk/tests/org/apache/roller/TestUtils.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/tests/org/apache/roller/TestUtils.java?view=diff&rev=475368&r1=475367&r2=475368
==============================================================================
--- incubator/roller/trunk/tests/org/apache/roller/TestUtils.java (original)
+++ incubator/roller/trunk/tests/org/apache/roller/TestUtils.java Wed Nov 15 11:14:24 2006
@@ -81,6 +81,9 @@
         UserManager mgr = RollerFactory.getRoller().getUserManager();
         mgr.addUser(testUser);
         
+        // flush to db
+        RollerFactory.getRoller().flush();
+        
         // query for the user to make sure we return the persisted object
         UserData user = mgr.getUserByUserName(username);
         
@@ -102,6 +105,9 @@
         
         // remove the user
         mgr.removeUser(user);
+        
+        // flush to db
+        RollerFactory.getRoller().flush();
     }
     
     
@@ -128,6 +134,9 @@
         UserManager mgr = RollerFactory.getRoller().getUserManager();
         mgr.addWebsite(testWeblog);
         
+        // flush to db
+        RollerFactory.getRoller().flush();
+        
         // query for the new weblog and return it
         WebsiteData weblog = mgr.getWebsiteByHandle(handle);
         
@@ -149,6 +158,9 @@
         
         // remove the weblog
         mgr.removeWebsite(weblog);
+        
+        // flush to db
+        RollerFactory.getRoller().flush();
     }
  
     
@@ -177,6 +189,9 @@
         WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
         mgr.saveWeblogEntry(testEntry);
         
+        // flush to db
+        RollerFactory.getRoller().flush();
+        
         // query for object
         WeblogEntryData entry = mgr.getWeblogEntry(testEntry.getId());
         
@@ -198,6 +213,9 @@
         
         // remove the entry
         mgr.removeWeblogEntry(entry);
+        
+        // flush to db
+        RollerFactory.getRoller().flush();
     }
     
     
@@ -222,6 +240,9 @@
         WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
         mgr.saveComment(testComment);
         
+        // flush to db
+        RollerFactory.getRoller().flush();
+        
         // query for object
         CommentData comment = mgr.getComment(testComment.getId());
         
@@ -243,6 +264,9 @@
         
         // remove the comment
         mgr.removeComment(comment);
+        
+        // flush to db
+        RollerFactory.getRoller().flush();
     }
     
     
@@ -260,6 +284,9 @@
         PingTargetManager pingMgr = RollerFactory.getRoller().getPingTargetManager();
         pingMgr.savePingTarget(testPing);
         
+        // flush to db
+        RollerFactory.getRoller().flush();
+        
         // query for it
         PingTargetData ping = pingMgr.getPingTarget(testPing.getId());
         
@@ -281,6 +308,9 @@
         
         // remove the ping
         pingMgr.removePingTarget(ping);
+        
+        // flush to db
+        RollerFactory.getRoller().flush();
     }
     
     
@@ -296,6 +326,9 @@
         AutoPingData autoPing = new AutoPingData(null, ping, weblog);
         mgr.saveAutoPing(autoPing);
         
+        // flush to db
+        RollerFactory.getRoller().flush();
+        
         // query for it
         autoPing = mgr.getAutoPing(autoPing.getId());
         
@@ -317,6 +350,9 @@
         
         // remove the auto ping
         mgr.removeAutoPing(autoPing);
+        
+        // flush to db
+        RollerFactory.getRoller().flush();
     }
     
     
@@ -334,6 +370,9 @@
         testCount.setDailyHits(amount);
         mgr.saveHitCount(testCount);
         
+        // flush to db
+        RollerFactory.getRoller().flush();
+        
         // query for it
         testCount = mgr.getHitCount(testCount.getId());
         
@@ -355,6 +394,9 @@
         
         // remove
         mgr.removeHitCount(testCount);
+        
+        // flush to db
+        RollerFactory.getRoller().flush();
     }
     
 }

Modified: incubator/roller/trunk/tests/org/apache/roller/business/BookmarkTest.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/tests/org/apache/roller/business/BookmarkTest.java?view=diff&rev=475368&r1=475367&r2=475368
==============================================================================
--- incubator/roller/trunk/tests/org/apache/roller/business/BookmarkTest.java (original)
+++ incubator/roller/trunk/tests/org/apache/roller/business/BookmarkTest.java Wed Nov 15 11:14:24
2006
@@ -92,26 +92,93 @@
     }
     
     
-    public void testAddBookmarkToFolder() throws Exception {
+    /**
+     * Test add/modify/remove of folders (no bookmarks).
+     */
+    public void testFolderCRUD() throws Exception {
         
         BookmarkManager bmgr = getRoller().getBookmarkManager();
-        FolderData folder = null;
-        BookmarkData bookmark1 = null, bookmark2 = null;
         
         FolderData root = bmgr.getRootFolder(testWeblog);
         
-        folder = new FolderData();
+        // start out with no folders and no bookmarks
+        assertEquals(0, root.getFolders().size());
+        assertEquals(0, root.getBookmarks().size());
+        
+        // add a folder
+        FolderData folder = new FolderData();
         folder.setName("TestFolder1");
-        folder.setDescription("created by testAddBookmarkToFolder()");
+        folder.setDescription("created by testFolderCRUD()");
         folder.setWebsite(testWeblog);
         folder.setParent(root);
         bmgr.saveFolder(folder);
+        TestUtils.endSession(true);
+        
+        // check that folder was saved
+        root = bmgr.getRootFolder(testWeblog);
+        folder = (FolderData) root.getFolders().iterator().next();
+        assertEquals("TestFolder1", folder.getName());
+        
+        // modify folder
+        folder.setName("folderTest1");
+        bmgr.saveFolder(folder);
+        TestUtils.endSession(true);
+        
+        // check that folder was saved
+        root = bmgr.getRootFolder(testWeblog);
+        folder = (FolderData) root.getFolders().iterator().next();
+        assertEquals("folderTest1", folder.getName());
+        
+        // add a subfolder
+        FolderData subfolder = new FolderData();
+        subfolder.setName("subfolderTest1");
+        subfolder.setDescription("created by testFolderCRUD()");
+        subfolder.setWebsite(testWeblog);
+        subfolder.setParent(folder);
+        bmgr.saveFolder(subfolder);
+        TestUtils.endSession(true);
+        
+        // check that subfolder was saved and we can navigate to it
+        root = bmgr.getRootFolder(testWeblog);
+        assertEquals(1, root.getFolders().size());
+        folder = (FolderData) root.getFolders().iterator().next();
+        assertEquals("folderTest1", folder.getName());
+        assertEquals(1, folder.getFolders().size());
+        subfolder = (FolderData) folder.getFolders().iterator().next();
+        assertEquals("subfolderTest1", subfolder.getName());
+        
+        // test remove folder, which should cascade to subfolders
+        bmgr.removeFolder(folder);
+        TestUtils.endSession(true);
+        
+        // check that folders were removed
+        root = bmgr.getRootFolder(testWeblog);
+        assertEquals(0, root.getFolders().size());
+    }
+    
+    
+    public void testBookmarkCRUD() throws Exception {
+        
+        BookmarkManager bmgr = getRoller().getBookmarkManager();
+        
+        FolderData root = bmgr.getRootFolder(testWeblog);
+        
+        FolderData folder = new FolderData();
+        folder.setName("TestFolder2");
+        folder.setDescription("created by testBookmarkCRUD()");
+        folder.setWebsite(testWeblog);
+        folder.setParent(root);
+        bmgr.saveFolder(folder);
+        TestUtils.endSession(true);
+        
+        // query for folder again since session ended
+        folder = bmgr.getFolder(folder.getId());
         
         // Add bookmark by adding to folder
-        bookmark1 = new BookmarkData(
+        BookmarkData bookmark1 = new BookmarkData(
                 folder,
                 "TestBookmark1",
-                "created by testAddBookmarkToFolder()",
+                "created by testBookmarkCRUD()",
                 "http://www.example.com",
                 "http://www.example.com/rss.xml",
                 new Integer(1),
@@ -120,10 +187,10 @@
         folder.addBookmark(bookmark1);
         
         // Add another bookmark
-        bookmark2 = new BookmarkData(
+        BookmarkData bookmark2 = new BookmarkData(
                 folder,
                 "TestBookmark2",
-                "created by testAddBookmarkToFolder()",
+                "created by testBookmarkCRUD()",
                 "http://www.example.com",
                 "http://www.example.com/rss.xml",
                 new Integer(1),
@@ -133,6 +200,7 @@
         
         TestUtils.endSession(true);
         
+        
         FolderData testFolder = null;
         BookmarkData bookmarkb = null, bookmarka = null;
         
@@ -141,18 +209,17 @@
         assertEquals(2, testFolder.getBookmarks().size());
         bookmarka = (BookmarkData)testFolder.getBookmarks().iterator().next();
         bookmarkb = (BookmarkData)testFolder.getBookmarks().iterator().next();
+        
         // Remove one bookmark
         testFolder.removeBookmark(bookmarka);
-        bmgr.removeBookmark(bookmarka);
+        bmgr.saveFolder(testFolder);
         TestUtils.endSession(true);
         
         // Folder should now contain one bookmark
         testFolder = bmgr.getFolder(folder.getId());
         assertEquals(1, testFolder.getBookmarks().size());
-        TestUtils.endSession(true);
         
         // Remove folder
-        testFolder = bmgr.getFolder(folder.getId());
         bmgr.removeFolder(testFolder);
         TestUtils.endSession(true);
         
@@ -163,13 +230,8 @@
     
     
     public void testBookmarkImport() throws Exception {
-        importBookmarks("/bookmarks.opml");
-    }
-    
-    
-    public void importBookmarks(String fileName) throws Exception {
         
-        InputStream fis = this.getClass().getResourceAsStream(fileName);
+        InputStream fis = this.getClass().getResourceAsStream("/bookmarks.opml");
         getRoller().getBookmarkManager().importBookmarks(
                 testWeblog, "ZZZ_imports_ZZZ", fileToString(fis));
         TestUtils.endSession(true);
@@ -177,7 +239,7 @@
         FolderData fd = null;
         
         fd = getRoller().getBookmarkManager().getFolder(testWeblog, "ZZZ_imports_ZZZ");
-        assertTrue("no bookmarks found", fd.retrieveBookmarks(true).size() > 0 );
+        assertTrue(fd.retrieveBookmarks(true).size() > 0 );
         getRoller().getBookmarkManager().removeFolder(fd);
         TestUtils.endSession(true);
     }
@@ -202,6 +264,12 @@
      *          b1
      *          f2/
      *             f3/
+     *
+     * TODO: it is unclear exactly what the expected behavior of this test is
+     * supposed to be.  i.e. how the moveContents() methods are supposed to
+     * work.  they could move only bookmarks, only bookmarks and folders from
+     * the specified src folder, all bookmarks (recursively), or all bookmarks
+     * and folder recursively.
      */
     public void testMoveFolderContents() throws Exception {
         
@@ -259,49 +327,48 @@
         
         TestUtils.endSession(true);
         
+        // verify our new tree
+        dest = bmgr.getFolder(dest.getId());
+        f1 = bmgr.getFolder(f1.getId());
+        f2 = bmgr.getFolder(f2.getId());
+        f3 = bmgr.getFolder(f3.getId());
+        assertEquals(0, dest.getBookmarks().size());
+        assertEquals(1, f1.getBookmarks().size());
+        assertEquals(1, f2.getBookmarks().size());
+        assertEquals(1, f3.getBookmarks().size());
+        assertEquals(0, dest.retrieveBookmarks(true).size());
+        assertEquals(3, f1.retrieveBookmarks(true).size());
+        
         // test that parent cannot be moved into child
         boolean safe = false;
         try {
-            
             // Move folder into one of it's children
-            f1 = bmgr.getFolder(f1.getId());
-            f3 = bmgr.getFolder(f3.getId());
             bmgr.moveFolderContents(f1, f3);
-            //f3.save();
-            //f1.save();
             TestUtils.endSession(true);
         } catch (RollerException e) {
             safe = true;
         }
         assertTrue(safe);
         
-        // verify number of entries in each folder
-        dest = bmgr.getFolder(dest.getId());
-        f1 = bmgr.getFolder(f1.getId());
-        assertEquals(0, dest.retrieveBookmarks(true).size());
-        assertEquals(0, dest.retrieveBookmarks(false).size());
-        assertEquals(1, f1.retrieveBookmarks(false).size());
-        
-        List f1list = f1.retrieveBookmarks(true);
-        assertEquals(3, f1list.size());
-        
-        // move contents of source category c1 to destination catetory dest
-        f1.moveContents(dest);
-        bmgr.saveFolder(f1);
-        bmgr.saveFolder(dest);
+        // move contents of f1 to dest
+        bmgr.moveFolderContents(f1, dest);
         TestUtils.endSession(true);
         
         // after move, verify number of entries in eacch folder
         dest = bmgr.getFolder(dest.getId());
         f1 = bmgr.getFolder(f1.getId());
-        assertEquals(3, dest.retrieveBookmarks(true).size());
-        assertEquals(3, dest.retrieveBookmarks(false).size());
-        assertEquals(0, f1.retrieveBookmarks(true).size());
-        assertEquals(0, f1.retrieveBookmarks(false).size());
+        assertEquals(1, dest.retrieveBookmarks(true).size());
+        assertEquals(2, f1.retrieveBookmarks(true).size());
+        
+        bmgr.removeFolder(f1);
+        bmgr.removeFolder(dest);
+        TestUtils.endSession(true);
     }
     
     
-    /** Test bookmark folder paths. */
+    /** 
+     * Test bookmark folder paths. 
+     */
     public void testPaths() throws Exception {
         
         BookmarkManager bmgr = getRoller().getBookmarkManager();
@@ -353,37 +420,41 @@
     }
     
     
-    /** Ensure that duplicate folder name will throw RollerException */
+    /** 
+     * Ensure that duplicate folder name will throw RollerException 
+     */
     public void testUniquenessOfFolderNames() throws Exception {
         
-        boolean exception = false;
-        FolderData f3 = null;
         BookmarkManager bmgr = getRoller().getBookmarkManager();
+        
+        FolderData root = bmgr.getRootFolder(testWeblog);
+        
+        FolderData f1 = new FolderData();
+        f1.setName("f1");
+        f1.setParent(root);
+        f1.setWebsite(testWeblog);
+        bmgr.saveFolder(f1);
+        
+        // first child folder
+        FolderData f2 = new FolderData();
+        f2.setName("f2");
+        f2.setParent(f1);
+        f2.setWebsite(testWeblog);
+        bmgr.saveFolder(f2);
+        
+        TestUtils.endSession(true);
+        
+        // need to requery for folder since session was closed
+        f1 = bmgr.getFolder(f1.getId());
+        
+        boolean exception = false;
         try {
-            FolderData root = bmgr.getRootFolder(testWeblog);
-            
-            FolderData f1 = new FolderData();
-            f1.setName("f1");
-            f1.setParent(root);
-            f1.setWebsite(testWeblog);
-            bmgr.saveFolder(f1);
-            
-            // first child folder
-            FolderData f2 = new FolderData();
-            f2.setName("f2");
-            f2.setParent(f1);
-            f2.setWebsite(testWeblog);
-            bmgr.saveFolder(f2);
-            
-            TestUtils.endSession(true);
-            
             // child folder with same name as first
-            f3 = new FolderData();
+            FolderData f3 = new FolderData();
             f3.setName("f2");
             f3.setParent(f1);
             f3.setWebsite(testWeblog);
             bmgr.saveFolder(f3);
-            
             TestUtils.endSession(true);
         } catch (RollerException e) {
             exception = true;

Modified: incubator/roller/trunk/tests/org/apache/roller/business/WeblogCategoryTest.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/tests/org/apache/roller/business/WeblogCategoryTest.java?view=diff&rev=475368&r1=475367&r2=475368
==============================================================================
--- incubator/roller/trunk/tests/org/apache/roller/business/WeblogCategoryTest.java (original)
+++ incubator/roller/trunk/tests/org/apache/roller/business/WeblogCategoryTest.java Wed Nov
15 11:14:24 2006
@@ -1,24 +1,19 @@
 /*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-*  contributor license agreements.  The ASF licenses this file to You
-* under the Apache License, Version 2.0 (the "License"); you may not
-* use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*     http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.  For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
-/*
- * WeblogCategoryTest.java
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
  *
- * Created on April 13, 2006, 10:07 PM
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
  */
 
 package org.apache.roller.business;
@@ -100,27 +95,28 @@
         WeblogCategoryData cat = null;
         List cats = null;
         
-        // we need to know how many categories we start the test with
-        int numCats = mgr.getRootWeblogCategory(testWeblog).getWeblogCategories().size();
+        WeblogCategoryData root = mgr.getRootWeblogCategory(testWeblog);
+        
+        // make sure we are starting with 0 categories (beneath root)
+        assertEquals(0, root.getWeblogCategories().size());
         
         // add a new category
         WeblogCategoryData newCat = new WeblogCategoryData();
         newCat.setName("catTestCategory");
-        newCat.setParent(testWeblog.getDefaultCategory());
+        newCat.setParent(root);
         newCat.setWebsite(testWeblog);
         mgr.saveWeblogCategory(newCat);
-        String id = newCat.getId();
         TestUtils.endSession(true);
         
         // make sure category was added
         cat = null;
-        cat = mgr.getWeblogCategory(id);
+        cat = mgr.getWeblogCategory(newCat.getId());
         assertNotNull(cat);
         assertEquals(newCat, cat);
         
         // make sure category count increased
-        testWeblog = RollerFactory.getRoller().getUserManager().getWebsite(testWeblog.getId());
-        assertEquals(numCats+1, mgr.getRootWeblogCategory(testWeblog).getWeblogCategories().size());
+        root = mgr.getRootWeblogCategory(testWeblog);
+        assertEquals(1, root.getWeblogCategories().size());
         
         // update category
         cat.setName("testtest");
@@ -129,22 +125,41 @@
         
         // verify category was updated
         cat = null;
-        cat = mgr.getWeblogCategory(id);
+        cat = mgr.getWeblogCategory(newCat.getId());
         assertNotNull(cat);
         assertEquals("testtest", cat.getName());
         
-        // remove category
+        // add a subcat
+        WeblogCategoryData subcat = new WeblogCategoryData();
+        subcat.setName("subcatTest1");
+        subcat.setWebsite(testWeblog);
+        subcat.setParent(cat);
+        mgr.saveWeblogCategory(subcat);
+        TestUtils.endSession(true);
+        
+        // check that subcat was saved and we can navigate to it
+        root = mgr.getRootWeblogCategory(testWeblog);
+        assertEquals(1, root.getWeblogCategories().size());
+        cat = (WeblogCategoryData) root.getWeblogCategories().iterator().next();
+        assertEquals("testtest", cat.getName());
+        assertEquals(1, cat.getWeblogCategories().size());
+        subcat = (WeblogCategoryData) cat.getWeblogCategories().iterator().next();
+        assertEquals("subcatTest1", subcat.getName());
+        
+        // remove category, should cascade to subcat
         mgr.removeWeblogCategory(cat);
         TestUtils.endSession(true);
         
-        // make sure category was removed
+        // make sure category and subcat was removed
         cat = null;
-        mgr.getWeblogCategory(id);
+        cat = mgr.getWeblogCategory(newCat.getId());
+        assertNull(cat);
+        cat = mgr.getWeblogCategory(subcat.getId());
         assertNull(cat);
         
         // make sure category count decreased
-        testWeblog = RollerFactory.getRoller().getUserManager().getWebsite(testWeblog.getId());
-        assertEquals(numCats, mgr.getRootWeblogCategory(testWeblog).getWeblogCategories().size());
+        root = mgr.getRootWeblogCategory(testWeblog);
+        assertEquals(0, root.getWeblogCategories().size());
     }
     
     



Mime
View raw message