roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r453754 - in /incubator/roller/trunk: src/org/apache/roller/business/search/operations/ src/org/apache/roller/ui/authoring/struts/actions/ tests/org/apache/roller/business/
Date Fri, 06 Oct 2006 20:29:21 GMT
Author: snoopdave
Date: Fri Oct  6 13:29:20 2006
New Revision: 453754

URL: http://svn.apache.org/viewvc?view=rev&rev=453754
Log:
Fix for delete in-use and add duplicate-named category problems (ROL-1165, ROL-1163)

Modified:
    incubator/roller/trunk/src/org/apache/roller/business/search/operations/   (props changed)
    incubator/roller/trunk/src/org/apache/roller/ui/authoring/struts/actions/CategoryDeleteAction.java
    incubator/roller/trunk/src/org/apache/roller/ui/authoring/struts/actions/CategorySaveAction.java
    incubator/roller/trunk/tests/org/apache/roller/business/WeblogCategoryTest.java

Propchange: incubator/roller/trunk/src/org/apache/roller/business/search/operations/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Fri Oct  6 13:29:20 2006
@@ -1 +1,2 @@
 .LCKIndexOperation.java~
+.LCKReIndexEntryOperation.java~

Modified: incubator/roller/trunk/src/org/apache/roller/ui/authoring/struts/actions/CategoryDeleteAction.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/authoring/struts/actions/CategoryDeleteAction.java?view=diff&rev=453754&r1=453753&r2=453754
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/ui/authoring/struts/actions/CategoryDeleteAction.java
(original)
+++ incubator/roller/trunk/src/org/apache/roller/ui/authoring/struts/actions/CategoryDeleteAction.java
Fri Oct  6 13:29:20 2006
@@ -85,8 +85,7 @@
                     // root and the sub-cats of the category being deleted.
                     if (!cat.getId().equals(catid) 
                         && cat.getParent()!=null
-                        && !cat.descendentOf(catToDelete)
-                        && cat.retrieveWeblogEntries(true).size() < 1)
+                        && !cat.descendentOf(catToDelete))
                     {
                         destCats.add(cat);
                     }                    
@@ -113,15 +112,32 @@
                 
                 // User clicked YES to delete
                 // remove cat to delete
+                if (form.getMoveToWeblogCategoryId() != null) 
+                {
+                    WeblogCategoryData destCat = 
+                        wmgr.getWeblogCategory(form.getMoveToWeblogCategoryId());
+                    if (rses.isUserAuthorizedToAuthor(destCat.getWebsite())) 
+                    {
+                        wmgr.moveWeblogCategoryContents(catToDelete, destCat);          
     
+                        RollerFactory.getRoller().flush();
+                    } 
+                    else 
+                    {
+                        return mapping.findForward("access-denied");
+                    }
+                }
+                                
+                catToDelete = wmgr.getWeblogCategory(catToDelete.getId());
                 wmgr.removeWeblogCategory(catToDelete);
                 RollerFactory.getRoller().flush();
-                
+
                 // notify caches of invalidated object
                 CacheManager.invalidate(catToDelete);
-                
-                if (null != returnId) {
+
+                if (null != returnId) 
+                {
                     request.setAttribute(RequestConstants.WEBLOGCATEGORY_ID, returnId);
-                }               
+                }  
             }
             else 
             {

Modified: incubator/roller/trunk/src/org/apache/roller/ui/authoring/struts/actions/CategorySaveAction.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/authoring/struts/actions/CategorySaveAction.java?view=diff&rev=453754&r1=453753&r2=453754
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/ui/authoring/struts/actions/CategorySaveAction.java
(original)
+++ incubator/roller/trunk/src/org/apache/roller/ui/authoring/struts/actions/CategorySaveAction.java
Fri Oct  6 13:29:20 2006
@@ -38,6 +38,7 @@
 import org.apache.roller.util.cache.CacheManager;
 import org.apache.roller.ui.authoring.struts.formbeans.WeblogCategoryFormEx;
 import org.apache.roller.ui.core.RequestConstants;
+import org.apache.roller.RollerException;
 
 /**
  * @struts.action path="/roller-ui/authoring/categorySave" name="weblogCategoryFormEx"
@@ -78,11 +79,18 @@
             rses.getAuthenticatedUser(), PermissionsData.AUTHOR))
         {
             form.copyTo(cd, request.getLocale());
-            wmgr.saveWeblogCategory(cd);
-            RollerFactory.getRoller().flush();
-            
-            // notify caches of object invalidation
-            CacheManager.invalidate(cd);
+            try {
+                wmgr.saveWeblogCategory(cd);
+                RollerFactory.getRoller().flush();
+                
+                // notify caches of object invalidation
+                CacheManager.invalidate(cd);
+            } catch (RollerException re) {
+                ActionErrors errors = new ActionErrors();
+                errors.add(ActionErrors.GLOBAL_ERROR,
+                    new ActionError("error.untranslated", re.getMessage())); 
+                saveErrors(request, errors);
+            }            
         }
         else
         {

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=453754&r1=453753&r2=453754
==============================================================================
--- incubator/roller/trunk/tests/org/apache/roller/business/WeblogCategoryTest.java (original)
+++ incubator/roller/trunk/tests/org/apache/roller/business/WeblogCategoryTest.java Fri Oct
 6 13:29:20 2006
@@ -292,5 +292,71 @@
         List entries = c1.retrieveWeblogEntries(true);
         assertEquals(3, entries.size());
     }
+    
+    public void testMoveWeblogCategoryContents() throws Exception {
+        
+        WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
+        
+        // add some categories and entries to test with
+        WeblogCategoryData dest = new WeblogCategoryData();
+        dest.setName("c0");
+        dest.setParent(mgr.getRootWeblogCategory(testWeblog));
+        dest.setWebsite(testWeblog);
+        mgr.saveWeblogCategory(dest);
+        
+        WeblogCategoryData c1 = new WeblogCategoryData();
+        c1.setName("c1");
+        c1.setParent(mgr.getRootWeblogCategory(testWeblog));
+        c1.setWebsite(testWeblog);
+        mgr.saveWeblogCategory(c1);
+        
+        WeblogCategoryData c2 = new WeblogCategoryData();
+        c2.setName("c2");
+        c2.setParent(c1);
+        c2.setWebsite(testWeblog);
+        mgr.saveWeblogCategory(c2);
+        
+        WeblogCategoryData c3 = new WeblogCategoryData();
+        c3.setName("c3");
+        c3.setParent(c2);
+        c3.setWebsite(testWeblog);
+        mgr.saveWeblogCategory(c3);
+        
+        TestUtils.endSession(true);
+        
+        c1 = mgr.getWeblogCategory(c1.getId());
+        c2 = mgr.getWeblogCategory(c2.getId());
+        c3 = mgr.getWeblogCategory(c3.getId());
+        dest = mgr.getWeblogCategory(dest.getId());
+        
+        WeblogEntryData e1 = TestUtils.setupWeblogEntry("e1", c1, testWeblog, testUser);
+        WeblogEntryData e2 = TestUtils.setupWeblogEntry("e2", c2, testWeblog, testUser);
+        WeblogEntryData e3 = TestUtils.setupWeblogEntry("e3", c3, testWeblog, testUser);
+        
+        TestUtils.endSession(true);
+        
+        // verify number of entries in each category
+        assertEquals(0, dest.retrieveWeblogEntries(true).size());
+        assertEquals(0, dest.retrieveWeblogEntries(false).size());
+        assertEquals(1, c1.retrieveWeblogEntries(false).size());
+        assertEquals(3, c1.retrieveWeblogEntries(true).size());
+        
+        // move contents of source category c1 to destination category dest
+        mgr.moveWeblogCategoryContents(c1, dest);
+        mgr.saveWeblogCategory(c1);
+        TestUtils.endSession(true);
+        
+        // after move, verify number of entries in each category
+        dest = mgr.getWeblogCategory(dest.getId());
+        c1 = mgr.getWeblogCategory(c1.getId());
+        
+        // Hierarchy is flattened under dest      
+        assertEquals(3, dest.retrieveWeblogEntries(true).size());
+        assertEquals(3, dest.retrieveWeblogEntries(false).size());
+        
+        // c1 category should be empty now
+        assertEquals(0, c1.retrieveWeblogEntries(false).size());
+               
 
+    }
 }



Mime
View raw message