jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1517515 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionableState.java oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/RestoreTest.java
Date Mon, 26 Aug 2013 12:15:07 GMT
Author: mreutegg
Date: Mon Aug 26 12:15:06 2013
New Revision: 1517515

URL: http://svn.apache.org/r1517515
Log:
OAK-977: Version restore may include jcr:frozenXXX properties

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionableState.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/RestoreTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionableState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionableState.java?rev=1517515&r1=1517514&r2=1517515&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionableState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionableState.java
Mon Aug 26 12:15:06 2013
@@ -256,7 +256,7 @@ class VersionableState {
         } else {
             // replace
             destParent.getChildNode(name).remove();
-            restoreNode(src, destParent.child(name), selector);
+            restoreCopiedNode(src, destParent.child(name), selector);
         }
     }
 
@@ -268,7 +268,7 @@ class VersionableState {
                                @Nonnull VersionSelector selector)
             throws RepositoryException, CommitFailedException {
         // 15.7.2 Restoring Type and Identifier
-        restoreFrozen(frozen, dest);
+        restoreFrozenTypeAndUUID(frozen, dest);
         // 15.7.3 Restoring Properties
         for (PropertyState p : frozen.getProperties()) {
             if (BASIC_FROZEN_PROPERTIES.contains(p.getName())) {
@@ -307,8 +307,8 @@ class VersionableState {
      * Restores the basic frozen properties (jcr:primaryType, jcr:mixinTypes
      * and jcr:uuid).
      */
-    private void restoreFrozen(@Nonnull NodeBuilder frozen,
-                               @Nonnull NodeBuilder dest) {
+    private void restoreFrozenTypeAndUUID(@Nonnull NodeBuilder frozen,
+                                          @Nonnull NodeBuilder dest) {
         dest.setProperty(JCR_PRIMARYTYPE,
                 frozen.getName(JCR_FROZENPRIMARYTYPE), Type.NAME);
         dest.setProperty(JCR_UUID,
@@ -323,13 +323,26 @@ class VersionableState {
     /**
      * Restore a copied node.
      */
-    private void restoreNode(NodeBuilder src,
-                             NodeBuilder dest,
-                             VersionSelector selector)
+    private void restoreCopiedNode(NodeBuilder src,
+                                   NodeBuilder dest,
+                                   VersionSelector selector)
             throws RepositoryException, CommitFailedException {
         if (primaryTypeOf(src).equals(NT_FROZENNODE)) {
-            restoreFrozen(src, dest);
-            copyProperties(src, dest, OPVForceCopy.INSTANCE, true);
+            restoreFrozenTypeAndUUID(src, dest);
+            copyProperties(src, dest, new OPVProvider() {
+                @Override
+                public int getAction(NodeBuilder src,
+                                     NodeBuilder dest,
+                                     PropertyState prop)
+                        throws RepositoryException {
+                    // copy back, except for basic frozen props
+                    if (BASIC_FROZEN_PROPERTIES.contains(prop.getName())) {
+                        return IGNORE;
+                    } else {
+                        return COPY;
+                    }
+                }
+            }, true);
         } else {
             copyProperties(src, dest, OPVForceCopy.INSTANCE, false);
         }
@@ -366,7 +379,7 @@ class VersionableState {
             if (action == COPY) {
                 // replace on destination
                 dest.getChildNode(name).remove();
-                restoreNode(srcChild, dest.child(name), selector);
+                restoreCopiedNode(srcChild, dest.child(name), selector);
             } else if (action == VERSION) {
                 restoreState(srcChild, dest, name, selector);
             }

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/RestoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/RestoreTest.java?rev=1517515&r1=1517514&r2=1517515&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/RestoreTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/RestoreTest.java
Mon Aug 26 12:15:06 2013
@@ -21,6 +21,7 @@ import javax.jcr.RepositoryException;
 import javax.jcr.version.Version;
 import javax.jcr.version.VersionManager;
 
+import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.test.AbstractJCRTest;
 
 /**
@@ -46,4 +47,26 @@ public class RestoreTest extends Abstrac
         n = superuser.getNode(path);
         assertEquals("Property not restored", "a", n.getProperty("prop").getString());
     }
+
+    public void testRestoreReferenceableChild() throws RepositoryException {
+        VersionManager vMgr = superuser.getWorkspace().getVersionManager();
+        Node n = testRootNode.addNode(nodeName1, "test:versionable");
+        n.addMixin(mixVersionable);
+        n.setProperty("prop", "a");
+        Node child = n.addNode("test:copyOnParentVersion", ntUnstructured);
+        child.addMixin(mixReferenceable);
+        child.setProperty("prop", "a");
+        superuser.save();
+        String path = n.getPath();
+        Version v = vMgr.checkpoint(path); // 1.0
+        n.setProperty("prop", "b");
+        child.setProperty("prop", "b");
+        superuser.save();
+        vMgr.checkpoint(path); // 1.1
+        vMgr.restore(v, true);
+        assertEquals("Property not restored", "a", n.getProperty("prop").getString());
+        assertEquals("Property not restored", "a", child.getProperty("prop").getString());
+        assertFalse("Restored node must not have jcr:frozenPrimaryType property",
+                child.hasProperty(JcrConstants.JCR_FROZENPRIMARYTYPE));
+    }
 }



Mime
View raw message