You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by ja...@apache.org on 2009/11/28 00:39:46 UTC

svn commit: r885052 - in /incubator/jspwiki/trunk: ChangeLog src/java/org/apache/wiki/Release.java src/java/org/apache/wiki/content/ContentManager.java tests/java/org/apache/wiki/content/ContentManagerTest.java

Author: jalkanen
Date: Fri Nov 27 23:39:44 2009
New Revision: 885052

URL: http://svn.apache.org/viewvc?rev=885052&view=rev
Log:
        * ContentManager.isNew() was checking if ATTR_CREATED exists
        after it had ensured it had one to determine whether page is new
        or not. Oops.
        
        * More fixes to ContentManager.checkin() and save() as it was
        accidentally creating old pages with wrong version numbers, which
        in turn caused deletions to fail in some places.

Modified:
    incubator/jspwiki/trunk/ChangeLog
    incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ContentManagerTest.java

Modified: incubator/jspwiki/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/ChangeLog?rev=885052&r1=885051&r2=885052&view=diff
==============================================================================
--- incubator/jspwiki/trunk/ChangeLog (original)
+++ incubator/jspwiki/trunk/ChangeLog Fri Nov 27 23:39:44 2009
@@ -1,3 +1,15 @@
+2009-11-28 Janne Jalkanen <ja...@apache.org>
+
+        * 3.0.0-svn-186
+        
+        * ContentManager.isNew() was checking if ATTR_CREATED exists
+        after it had ensured it had one to determine whether page is new
+        or not. Oops.
+        
+        * More fixes to ContentManager.checkin() and save() as it was
+        accidentally creating old pages with wrong version numbers, which
+        in turn caused deletions to fail in some places.
+        
 2009-11-27 Andrew Jaquith <ajaquith AT apache DOT org>
 
         * 3.0.0-svn-185

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java?rev=885052&r1=885051&r2=885052&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java Fri Nov 27 23:39:44 2009
@@ -77,7 +77,7 @@
      *  <p>
      *  If the build identifier is empty, it is not added.
      */
-    public static final String     BUILD         = "185";
+    public static final String     BUILD         = "186";
 
     /**
      *  This is the generic version string you should use

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java?rev=885052&r1=885051&r2=885052&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java Fri Nov 27 23:39:44 2009
@@ -409,47 +409,35 @@
      */
     private void checkin( String path, int currentVersion ) throws RepositoryException
     {
-        Session copierSession = null;
+        Session copierSession = getCurrentSession();
         
-        try
-        {
-            copierSession = m_sessionManager.newSession();
-            
-            // If the item does not exist yet, there is nothing to copy.
-            if( !copierSession.itemExists( path ) ) return;
+        // If the item does not exist yet, there is nothing to copy.
+        if( !copierSession.itemExists( path ) ) return;
             
-            Node nd = (Node)copierSession.getItem( path );
-            Node versions;
-            
-            if( !nd.hasNode( WIKI_VERSIONS ) )
-            {
-                versions = nd.addNode( WIKI_VERSIONS );
-            }
-            else
-            {
-                versions = nd.getNode( WIKI_VERSIONS );
-            }
+        Node nd = (Node)copierSession.getItem( path );
+        Node versions;
             
-            String versionName = Integer.toString( currentVersion );
+        if( !nd.hasNode( WIKI_VERSIONS ) )
+        {
+            versions = nd.addNode( WIKI_VERSIONS );
+        }
+        else
+        {
+            versions = nd.getNode( WIKI_VERSIONS );
+        }
             
-            if( versions.hasNode( versionName ) )
-            {
-                throw new ItemExistsException("Version already exists: "+currentVersion+". This is a JSPWiki internal error, please report!");
-            }
+        String versionName = Integer.toString( currentVersion );
             
-            Node newVersion = versions.addNode( versionName );
+        if( versions.hasNode( versionName ) )
+        {
+            throw new ItemExistsException("Version already exists: "+currentVersion+". This is a JSPWiki internal error, please report!");
+        }
             
-            newVersion.addMixin( "mix:referenceable" );
+        Node newVersion = versions.addNode( versionName );
             
-            copyProperties( nd, newVersion );
+        newVersion.addMixin( "mix:referenceable" );
             
-            copierSession.save();
-        }
-        finally
-        {
-            if( copierSession != null ) copierSession.logout();
-        }
-        
+        copyProperties( nd, newVersion );
     }
 
     private void copyProperties( Node source, Node dest )
@@ -499,24 +487,23 @@
         Node nd = getJCRNode( getJCRPath( path ) );
 
         int version = page.getVersion();
-        
-        version++; // New version is always one newer.
-        
-        nd.setProperty( JCRWikiPage.ATTR_VERSION, version );
-        
-        if( !nd.hasProperty( JCRWikiPage.ATTR_CREATED ) )
-        {
-            nd.setProperty( JCRWikiPage.ATTR_CREATED, Calendar.getInstance() );
-        }
-        
+
         if( isNew( nd ) )
         {
+            nd.setProperty( JCRWikiPage.ATTR_VERSION, 1 );
+            nd.setProperty( JCRWikiPage.ATTR_CREATED, Calendar.getInstance() );
+            
             // New node, so nothing to check in
             nd.getParent().save();
         }
         else
         {
+            // First, check in the old node, then set version for the new one
+            
             checkin( getJCRPath( path ), version );
+                        
+            nd.setProperty( JCRWikiPage.ATTR_VERSION, version+1 );
+            
             nd.save();
         }
         

Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ContentManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ContentManagerTest.java?rev=885052&r1=885051&r2=885052&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ContentManagerTest.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ContentManagerTest.java Fri Nov 27 23:39:44 2009
@@ -118,9 +118,9 @@
     
     public void testPaths() throws Exception
     {
-        assertEquals( "One", "/pages/Main/MainPage", ContentManager.getJCRPath( WikiPath.valueOf("Main:MainPage") ) );
+        assertEquals( "One", "/pages/main/mainpage", ContentManager.getJCRPath( WikiPath.valueOf("Main:MainPage") ) );
         
-        assertEquals( "Back", WikiPath.valueOf("Main:MainPage"), ContentManager.getWikiPath( "/pages/Main/MainPage" ) );
+        assertEquals( "Back", WikiPath.valueOf("Main:MainPage"), ContentManager.getWikiPath( "/pages/main/mainpage" ) );
     }
     
     public void getAllPages() throws Exception
@@ -153,6 +153,8 @@
         assertTrue( m_mgr.pageExists( path, 1 ) );
 
         m_engine.deletePage( path.toString() );
+        
+        assertFalse( m_mgr.pageExists( path ) );
     }
 
     public void testVersions() throws Exception