You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by an...@apache.org on 2015/10/23 10:16:32 UTC

svn commit: r1710135 - 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/OpvIgnoreTest.java

Author: angela
Date: Fri Oct 23 08:16:31 2015
New Revision: 1710135

URL: http://svn.apache.org/viewvc?rev=1710135&view=rev
Log:
OAK-3541 : VersionableState.copy doesn't respect OPV flag in the subtree (WIP, committing initial patch to unblock OAK-1268, in depth testing especially for OPV VERSION is required)

Added:
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/OpvIgnoreTest.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionableState.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=1710135&r1=1710134&r2=1710135&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 Fri Oct 23 08:16:31 2015
@@ -494,10 +494,10 @@ class VersionableState {
                     versionedChild(child, dest.child(name));
                 } else {
                     // else copy
-                    copy(child, childId, dest.child(name));
+                    createFrozen(child, childId, dest.child(name));
                 }
             } else if (opv == COPY) {
-                copy(child, childId, dest.child(name));
+                createFrozen(child, childId, dest.child(name));
             }
         }
     }
@@ -508,20 +508,6 @@ class VersionableState {
         dest.setProperty(JCR_CHILDVERSIONHISTORY, ref, Type.REFERENCE);
     }
 
-    private void copy(NodeBuilder src,
-                      String srcId,
-                      NodeBuilder dest)
-            throws RepositoryException, CommitFailedException {
-        initFrozen(dest, src, srcId);
-        copyProperties(src, dest, OPVForceCopy.INSTANCE, true);
-        for (String name : src.getChildNodeNames()) {
-            if (!NodeStateUtils.isHidden(name)) {
-                NodeBuilder child = src.getChildNode(name);
-                copy(child, getChildId(srcId, child, name), dest.child(name));
-            }
-        }
-    }
-
     /**
      * Returns the id of the {@code child} node. The id is the value of the
      * jcr:uuid property of the child node if present, or the concatenation of

Added: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/OpvIgnoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/OpvIgnoreTest.java?rev=1710135&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/OpvIgnoreTest.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/OpvIgnoreTest.java Fri Oct 23 08:16:31 2015
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * 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.
+ */
+package org.apache.jackrabbit.oak.jcr.version;
+
+import javax.annotation.Nonnull;
+import javax.jcr.Node;
+import javax.jcr.security.AccessControlManager;
+import javax.jcr.security.Privilege;
+import javax.jcr.version.OnParentVersionAction;
+import javax.jcr.version.Version;
+import javax.jcr.version.VersionManager;
+
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.jackrabbit.api.security.JackrabbitAccessControlList;
+import org.apache.jackrabbit.commons.jackrabbit.authorization.AccessControlUtils;
+import org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants;
+import org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.AccessControlConstants;
+import org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal;
+import org.apache.jackrabbit.test.AbstractJCRTest;
+
+/**
+ * Test OPV IGNORE
+ */
+public class OpvIgnoreTest extends AbstractJCRTest {
+
+    private VersionManager versionManager;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        // add child nodes that have OPV COPY and thus end up in the frozen node
+        testRootNode.addNode(nodeName1, NodeTypeConstants.NT_OAK_UNSTRUCTURED).addNode(nodeName2, NodeTypeConstants.NT_OAK_UNSTRUCTURED);
+        superuser.save();
+
+        versionManager = superuser.getWorkspace().getVersionManager();
+    }
+
+    private void addIgnoredChild(@Nonnull Node node) throws Exception {
+        AccessControlManager acMgr = superuser.getAccessControlManager();
+        JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, node.getPath());
+        acl.addAccessControlEntry(EveryonePrincipal.getInstance(), AccessControlUtils.privilegesFromNames(acMgr, Privilege.JCR_READ));
+        acMgr.setPolicy(acl.getPath(), acl);
+        superuser.save();
+
+        Node c = node.getNode(AccessControlConstants.REP_POLICY);
+        assertEquals(OnParentVersionAction.IGNORE, c.getDefinition().getOnParentVersion());
+    }
+
+    public void testDirectChild() throws Exception {
+        addIgnoredChild(testRootNode);
+
+        testRootNode.addMixin(JcrConstants.MIX_VERSIONABLE);
+        superuser.save();
+
+        // enforce the creation of the version (and the frozen node)
+        Version version = versionManager.checkpoint(testRoot);
+        Node frozen = version.getFrozenNode();
+
+        assertTrue(frozen.hasNode(nodeName1));
+        assertTrue(frozen.getNode(nodeName1).hasNode(nodeName2));
+        assertFalse(frozen.hasNode(AccessControlConstants.REP_POLICY));
+    }
+
+    public void testChildInSubTree() throws Exception {
+        addIgnoredChild(testRootNode.getNode(nodeName1));
+
+        testRootNode.addMixin(JcrConstants.MIX_VERSIONABLE);
+        superuser.save();
+
+        // enforce the creation of the version (and the frozen node)
+        Version version = versionManager.checkpoint(testRoot);
+        Node frozen = version.getFrozenNode();
+
+        assertTrue(frozen.hasNode(nodeName1));
+        Node frozenChild = frozen.getNode(nodeName1);
+        assertTrue(frozenChild.hasNode(nodeName2));
+        assertFalse(frozenChild.hasNode(AccessControlConstants.REP_POLICY));
+    }
+}
\ No newline at end of file