roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c..@apache.org
Subject svn commit: r489412 - in /incubator/roller/trunk: src/org/apache/roller/business/ src/org/apache/roller/business/hibernate/ src/org/apache/roller/pojos/ src/org/apache/roller/ui/admin/struts/formbeans/ src/org/apache/roller/ui/authoring/struts/actions/...
Date Thu, 21 Dec 2006 17:16:34 GMT
Author: clr
Date: Thu Dec 21 09:16:31 2006
New Revision: 489412

URL: http://svn.apache.org/viewvc?view=rev&rev=489412
Log:
Change bookmark, user role, and weblog entry to explicitly manage relationships

Modified:
    incubator/roller/trunk/src/org/apache/roller/business/UserManager.java
    incubator/roller/trunk/src/org/apache/roller/business/WeblogManager.java
    incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateBookmarkManagerImpl.java
    incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateUserManagerImpl.java
    incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java
    incubator/roller/trunk/src/org/apache/roller/pojos/FolderData.java
    incubator/roller/trunk/src/org/apache/roller/pojos/UserData.java
    incubator/roller/trunk/src/org/apache/roller/pojos/WeblogEntryData.java
    incubator/roller/trunk/src/org/apache/roller/ui/admin/struts/formbeans/UserAdminForm.java
    incubator/roller/trunk/src/org/apache/roller/ui/authoring/struts/actions/WeblogEntryFormAction.java
    incubator/roller/trunk/tests/org/apache/roller/business/BookmarkTest.java
    incubator/roller/trunk/tests/org/apache/roller/business/UserTest.java
    incubator/roller/trunk/tests/org/apache/roller/business/WeblogEntryTest.java

Modified: incubator/roller/trunk/src/org/apache/roller/business/UserManager.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/business/UserManager.java?view=diff&rev=489412&r1=489411&r2=489412
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/business/UserManager.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/business/UserManager.java Thu Dec 21 09:16:31
2006
@@ -27,7 +27,6 @@
 import org.apache.roller.pojos.UserData;
 import org.apache.roller.pojos.WebsiteData;
 
-
 /**
  * Manages users, weblogs, permissions, and weblog pages.
  */
@@ -326,6 +325,14 @@
         throws RollerException;
     
     
+    /**
+     * Revoke role of user
+     * @param roleName Name of the role to be revoked
+     * @param user    User for whom the role is to be revoked
+     */
+    public void revokeRole(String roleName, UserData user)
+        throws RollerException;
+
     /**
      * Store page.
      */

Modified: incubator/roller/trunk/src/org/apache/roller/business/WeblogManager.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/business/WeblogManager.java?view=diff&rev=489412&r1=489411&r2=489412
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/business/WeblogManager.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/business/WeblogManager.java Thu Dec 21 09:16:31
2006
@@ -194,8 +194,21 @@
      * @return Collection of WeblogEntryData objects.
      */
     public List getWeblogEntriesPinnedToMain(Integer max) throws RollerException;
-    
-    
+
+    /**
+     * Remove attribute with given name from given WeblogEntryData
+     * @param name Name of attribute to be removed
+     */
+    public void removeWeblogEntryAttribute(String name, WeblogEntryData entry)
+            throws RollerException;
+
+    /**
+     * Remove tag with given name from given WeblogEntryData
+     * @param name Name of tag to be removed
+     */
+    public void removeWeblogEntryTag(String name, WeblogEntryData entry)
+            throws RollerException;
+
     /**
      * Save weblog category.
      */

Modified: incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateBookmarkManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateBookmarkManagerImpl.java?view=diff&rev=489412&r1=489411&r2=489412
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateBookmarkManagerImpl.java
(original)
+++ incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateBookmarkManagerImpl.java
Thu Dec 21 09:16:31 2006
@@ -81,10 +81,13 @@
     
     
     public void removeBookmark(BookmarkData bookmark) throws RollerException {
+        //Remove the bookmark from its parent folder
+        bookmark.getFolder().getBookmarks().remove(bookmark);
+        //Now remove it from database
         this.strategy.remove(bookmark);
-        
         // update weblog last modified date.  date updated by saveWebsite()
-        RollerFactory.getRoller().getUserManager().saveWebsite(bookmark.getWebsite());
+        RollerFactory.getRoller().getUserManager()
+                .saveWebsite(bookmark.getWebsite());
     }
     
     

Modified: incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateUserManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateUserManagerImpl.java?view=diff&rev=489412&r1=489411&r2=489412
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateUserManagerImpl.java
(original)
+++ incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateUserManagerImpl.java
Thu Dec 21 09:16:31 2006
@@ -26,6 +26,8 @@
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
+import java.util.Collection;
+
 import org.apache.roller.pojos.StatCount;
 import org.hibernate.Criteria;
 import org.hibernate.HibernateException;
@@ -58,6 +60,7 @@
 import org.apache.roller.pojos.WeblogCategoryData;
 import org.apache.roller.pojos.WeblogEntryData;
 import org.apache.roller.pojos.WebsiteData;
+import org.apache.roller.pojos.RoleData;
 import org.hibernate.Query;
 
 
@@ -962,6 +965,20 @@
         }
         return ret;
     }
+
+    public void revokeRole(String roleName, UserData user) throws RollerException {
+        RoleData removeme = null;
+        Collection roles = user.getRoles();
+        Iterator iter = roles.iterator();
+        while (iter.hasNext()) {
+            RoleData role = (RoleData) iter.next();
+            if (role.getRole().equals(roleName)) {
+                iter.remove();
+                this.strategy.remove(role);
+            }
+        }
+    }
+
 
     
     /**

Modified: incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java?view=diff&rev=489412&r1=489411&r2=489412
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java
(original)
+++ incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java
Thu Dec 21 09:16:31 2006
@@ -50,6 +50,7 @@
 import org.apache.roller.pojos.WeblogEntryTagData;
 import org.apache.roller.pojos.WeblogEntryTagAggregateData;
 import org.apache.roller.pojos.WebsiteData;
+import org.apache.roller.pojos.EntryAttributeData;
 import org.apache.roller.util.DateUtil;
 import org.hibernate.Criteria;
 import org.hibernate.HibernateException;
@@ -60,12 +61,6 @@
 import org.hibernate.criterion.MatchMode;
 import org.hibernate.criterion.Order;
 import org.hibernate.criterion.Restrictions;
-import org.hibernate.dialect.DerbyDialect;
-import org.hibernate.dialect.Dialect;
-import org.hibernate.dialect.OracleDialect;
-import org.hibernate.dialect.SQLServerDialect;
-import org.hibernate.engine.SessionFactoryImplementor;
-
 
 /**
  * Hibernate implementation of the WeblogManager.
@@ -323,6 +318,36 @@
         this.entryAnchorToIdMap.remove(entry.getWebsite().getHandle()+":"+entry.getAnchor());
     }
         
+    public void removeWeblogEntryAttribute(String name, WeblogEntryData entry)
+             throws RollerException {
+        for (Iterator it = entry.getEntryAttributes().iterator(); it.hasNext();) {
+            EntryAttributeData entryAttribute = (EntryAttributeData) it.next();
+            if (entryAttribute.getName().equals(name)) {
+                //Call back the entity to adjust its internal state
+                entry.onRemoveEntryAttribute(entryAttribute);
+                //Remove it from the collection
+                it.remove();
+                //Remove it from database
+                this.strategy.remove(entryAttribute);
+            }
+        }
+    }
+
+    public void removeWeblogEntryTag(String name, WeblogEntryData entry)
+            throws RollerException {
+        for (Iterator it = entry.getTags().iterator(); it.hasNext();) {
+            WeblogEntryTagData tag = (WeblogEntryTagData) it.next();
+            if (tag.getName().equals(name)) {
+                //Call back the entity to adjust its internal state
+                entry.onRemoveTag(name);
+                //Remove it from the collection
+                it.remove();
+                //Remove it from database
+                this.strategy.remove(tag);
+            }
+        }
+    }
+
     public List getNextPrevEntries(WeblogEntryData current, String catName, 
                                    String locale, int maxEntries, boolean next)
             throws RollerException {

Modified: incubator/roller/trunk/src/org/apache/roller/pojos/FolderData.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/pojos/FolderData.java?view=diff&rev=489412&r1=489411&r2=489412
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/pojos/FolderData.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/pojos/FolderData.java Thu Dec 21 09:16:31
2006
@@ -274,7 +274,7 @@
      *
      * @roller.wrapPojoMethod type="pojo-collection" class="org.apache.roller.pojos.BookmarkData"
      *
-     * @hibernate.set lazy="true" order-by="name" inverse="true" cascade="all-delete-orphan"
+     * @hibernate.set lazy="true" order-by="name" inverse="true" cascade="all"
      * @hibernate.collection-key column="folderid"
      * @hibernate.collection-one-to-many class="org.apache.roller.pojos.BookmarkData"
      */
@@ -295,15 +295,6 @@
         bookmark.setFolder(this);
         getBookmarks().add(bookmark);
     }
-    
-    
-    /** 
-     * Remove a boomkark from folder.
-     */
-    public void removeBookmark(BookmarkData bookmark) {
-        getBookmarks().remove(bookmark);
-    }
-    
     
     /**
      * @roller.wrapPojoMethod type="pojo-collection" class="org.apache.roller.pojos.BookmarkData"

Modified: incubator/roller/trunk/src/org/apache/roller/pojos/UserData.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/pojos/UserData.java?view=diff&rev=489412&r1=489411&r2=489412
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/pojos/UserData.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/pojos/UserData.java Thu Dec 21 09:16:31 2006
@@ -404,7 +404,7 @@
     
     
     /**
-     * @hibernate.set lazy="true" inverse="true" cascade="all-delete-orphan"
+     * @hibernate.set lazy="true" inverse="true" cascade="all"
      * @hibernate.collection-key column="userid"
      * @hibernate.collection-one-to-many class="org.apache.roller.pojos.RoleData"
      */
@@ -433,31 +433,6 @@
         }
         return false;
     }
-    
-    
-    /**
-     * Revokes specified role from user.
-     */
-    public void revokeRole(String roleName) throws RollerException {
-        RoleData removeme = null;
-        Iterator iter = roles.iterator();
-        while (iter.hasNext()) {
-            RoleData role = (RoleData) iter.next();
-            if (role.getRole().equals(roleName)) {
-                removeme = role;
-            }
-        }
-        
-        /* 
-         * NOTE: we do this outside the loop above because we are not allowed
-         * to modify the contents of the Set while we are iterating over it.
-         * doing so causes a ConcurrentModificationException
-         */
-        if(removeme != null) {
-            roles.remove(removeme);
-        }
-    }
-    
     
     /**
      * Grant to user role specified by role name.

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=489412&r1=489411&r2=489412
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/pojos/WeblogEntryData.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/pojos/WeblogEntryData.java Thu Dec 21 09:16:31
2006
@@ -353,7 +353,7 @@
      *
      * @roller.wrapPojoMethod type="pojo-collection" class="org.apache.roller.pojos.EntryAttributeData"
      * @ejb:persistent-field
-     * @hibernate.set lazy="true" order-by="name" inverse="true" cascade="all-delete-orphan"
+     * @hibernate.set lazy="true" order-by="name" inverse="true" cascade="all"
      * @hibernate.collection-key column="entryid" type="String"
      * @hibernate.collection-one-to-many class="org.apache.roller.pojos.EntryAttributeData"
      */
@@ -404,12 +404,8 @@
             att.setValue(value);
         }
     }
-    public void removeEntryAttribute(String name) throws RollerException {
-        EntryAttributeData att = (EntryAttributeData)attMap.get(name);
-        if (att != null) {
-            attMap.remove(att);
-            attSet.remove(att);
-        }
+    public void onRemoveEntryAttribute(EntryAttributeData att) throws RollerException {
+        attMap.remove(att);
     }
     //-------------------------------------------------------------------------
     
@@ -609,7 +605,7 @@
      *
      * @ejb:persistent-field
      * 
-     * @hibernate.set lazy="true" order-by="name" inverse="true" cascade="all-delete-orphan"

+     * @hibernate.set lazy="true" order-by="name" inverse="true" cascade="all" 
      * @hibernate.collection-key column="entryid" 
      * @hibernate.collection-one-to-many class="org.apache.roller.pojos.WeblogEntryTagData"
      */
@@ -654,16 +650,10 @@
         addedTags.add(name);
     }
 
-    public void removeTag(String name) throws RollerException {
-        for (Iterator it = tagSet.iterator(); it.hasNext();) {
-            WeblogEntryTagData tag = (WeblogEntryTagData) it.next();
-            if (tag.getName().equals(name)) {
-                removedTags.add(name);
-                it.remove();
-            }
-        }
+    public void onRemoveTag(String name) throws RollerException {
+        removedTags.add(name);
     }
-    
+
     public Set getAddedTags() {
         return addedTags;
     }
@@ -696,9 +686,10 @@
                 newTags.remove(tag.getName());
             }
         }
-        
+
+        WeblogManager weblogManager = RollerFactory.getRoller().getWeblogManager();
         for (Iterator it = removeTags.iterator(); it.hasNext();) {
-            removeTag((String) it.next());
+            weblogManager.removeWeblogEntryTag((String) it.next(), this);
         }
         
         for (Iterator it = newTags.iterator(); it.hasNext();) {

Modified: incubator/roller/trunk/src/org/apache/roller/ui/admin/struts/formbeans/UserAdminForm.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/admin/struts/formbeans/UserAdminForm.java?view=diff&rev=489412&r1=489411&r2=489412
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/ui/admin/struts/formbeans/UserAdminForm.java
(original)
+++ incubator/roller/trunk/src/org/apache/roller/ui/admin/struts/formbeans/UserAdminForm.java
Thu Dec 21 09:16:31 2006
@@ -23,6 +23,9 @@
 
 import org.apache.struts.action.ActionMapping;
 import org.apache.roller.RollerException;
+import org.apache.roller.business.Roller;
+import org.apache.roller.business.RollerImpl;
+import org.apache.roller.business.RollerFactory;
 import org.apache.roller.pojos.UserData;
 import org.apache.roller.ui.authoring.struts.forms.UserForm;
 
@@ -118,7 +121,7 @@
         }
         else
         {
-            user.revokeRole("admin");
+            RollerFactory.getRoller().getUserManager().revokeRole("admin", user);
         }
     }
 

Modified: incubator/roller/trunk/src/org/apache/roller/ui/authoring/struts/actions/WeblogEntryFormAction.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/authoring/struts/actions/WeblogEntryFormAction.java?view=diff&rev=489412&r1=489411&r2=489412
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/ui/authoring/struts/actions/WeblogEntryFormAction.java
(original)
+++ incubator/roller/trunk/src/org/apache/roller/ui/authoring/struts/actions/WeblogEntryFormAction.java
Thu Dec 21 09:16:31 2006
@@ -513,10 +513,11 @@
         }
         if (!valid || empty) {
             mLogger.debug("Removing MediaCast attributes");
+            WeblogManager weblogManager = RollerFactory.getRoller().getWeblogManager();
             try {
-                entry.removeEntryAttribute("att_mediacast_url");
-                entry.removeEntryAttribute("att_mediacast_type");
-                entry.removeEntryAttribute("att_mediacast_length");
+                weblogManager.removeWeblogEntryAttribute("att_mediacast_url", entry);
+                weblogManager.removeWeblogEntryAttribute("att_mediacast_type", entry);
+                weblogManager.removeWeblogEntryAttribute("att_mediacast_length", entry);
             } catch (RollerException e) {
                 mLogger.error("ERROR removing invalid MediaCast attributes");
             }

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=489412&r1=489411&r2=489412
==============================================================================
--- incubator/roller/trunk/tests/org/apache/roller/business/BookmarkTest.java (original)
+++ incubator/roller/trunk/tests/org/apache/roller/business/BookmarkTest.java Thu Dec 21 09:16:31
2006
@@ -328,7 +328,7 @@
         bookmarkb = (BookmarkData)testFolder.getBookmarks().iterator().next();
         
         // Remove one bookmark
-        testFolder.removeBookmark(bookmarka);
+        bmgr.removeBookmark(bookmarka);
         bmgr.saveFolder(testFolder);
         TestUtils.endSession(true);
         

Modified: incubator/roller/trunk/tests/org/apache/roller/business/UserTest.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/tests/org/apache/roller/business/UserTest.java?view=diff&rev=489412&r1=489411&r2=489412
==============================================================================
--- incubator/roller/trunk/tests/org/apache/roller/business/UserTest.java (original)
+++ incubator/roller/trunk/tests/org/apache/roller/business/UserTest.java Thu Dec 21 09:16:31
2006
@@ -186,7 +186,7 @@
         assertTrue(user.hasRole("admin"));
         
         // remove role
-        user.revokeRole("admin");
+        mgr.revokeRole("admin",user);
         mgr.saveUser(user);
         TestUtils.endSession(true);
         

Modified: incubator/roller/trunk/tests/org/apache/roller/business/WeblogEntryTest.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/tests/org/apache/roller/business/WeblogEntryTest.java?view=diff&rev=489412&r1=489411&r2=489412
==============================================================================
--- incubator/roller/trunk/tests/org/apache/roller/business/WeblogEntryTest.java (original)
+++ incubator/roller/trunk/tests/org/apache/roller/business/WeblogEntryTest.java Thu Dec 21
09:16:31 2006
@@ -415,8 +415,8 @@
         TestUtils.endSession(true);
 
         entry = mgr.getWeblogEntry(id);
-        entry.removeTag("testtag");
-        entry.removeTag("testtag2");
+        mgr.removeWeblogEntryTag("testtag", entry);
+        mgr.removeWeblogEntryTag("testtag2", entry);
         mgr.saveWeblogEntry(entry);
         TestUtils.endSession(true);
 



Mime
View raw message