jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1565322 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/api/ oak-core/src/main/java/org/apache/jackrabbit/oak/core/ oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/ oak-core/src/main/java/org/apache/jac...
Date Thu, 06 Feb 2014 16:15:39 GMT
Author: angela
Date: Thu Feb  6 16:15:38 2014
New Revision: 1565322

URL: http://svn.apache.org/r1565322
Log:
OAK-920: workspace#copy and permission handling

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/FastMove.java
      - copied, changed from r1564696, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/FastCopyMove.java
Removed:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/FastCopyMove.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractRoot.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableRoot.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/MutableTree.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeBuilder.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeBuilder.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelRootBuilder.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/NodeStoreKernel.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TreeUtil.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/api/RootTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootFuzzIT.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilderTest.java
    jackrabbit/oak/trunk/oak-jcr/pom.xml
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/WorkspaceDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/authorization/CopyTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java?rev=1565322&r1=1565321&r2=1565322&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java Thu Feb  6 16:15:38 2014
@@ -64,26 +64,6 @@ public interface Root {
     boolean move(String sourcePath, String destPath);
 
     /**
-     * Copy the child located at {@code sourcePath} to a child at {@code destPath}.
-     * Both paths must be absolute and resolve to a child located in this root.<br>
-     *
-     * This method does nothing an returns {@code false} if
-     * <ul>
-     *     <li>The tree at {@code sourcePath} does exist or is not accessible,</li>
-     *     <li>the parent of the tree at {@code destinationPath} does not exist or is not accessible,</li>
-     *     <li>a tree already exists at {@code destinationPath}.</li>
-     * </ul>
-     * If a tree at {@code destinationPath} exists but is not accessible to the
-     * editing content session this method succeeds but a subsequent
-     * {@link #commit()} will detect the violation and fail.
-     *
-     * @param sourcePath source path
-     * @param destPath destination path
-     * @return  {@code true} on success, {@code false} otherwise.
-     */
-    boolean copy(String sourcePath, String destPath);
-
-    /**
      * Retrieve the possible non existing {@code Tree} at the given absolute {@code path}.
      * The path must resolve to a tree in this root.
      *

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractRoot.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractRoot.java?rev=1565322&r1=1565321&r2=1565322&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractRoot.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractRoot.java Thu Feb  6 16:15:38 2014
@@ -204,28 +204,6 @@ abstract class AbstractRoot implements R
     }
 
     @Override
-    public boolean copy(String sourcePath, String destPath) {
-        checkLive();
-        MutableTree source = rootTree.getTree(sourcePath);
-        if (!source.exists()) {
-            return false;
-        }
-
-        String newName = getName(destPath);
-        MutableTree newParent = rootTree.getTree(getParentPath(destPath));
-        if (!newParent.exists() || newParent.hasChild(newName)) {
-            return false;
-        }
-
-        boolean success = source.copyTo(newParent, newName);
-        if (success) {
-            getTree(getParentPath(destPath)).updateChildOrder();
-            updated();
-        }
-        return success;
-    }
-
-    @Override
     public MutableTree getTree(@Nonnull String path) {
         checkLive();
         return rootTree.getTree(path);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableRoot.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableRoot.java?rev=1565322&r1=1565321&r2=1565322&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableRoot.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableRoot.java Thu Feb  6 16:15:38 2014
@@ -83,7 +83,6 @@ public final class ImmutableRoot impleme
         throw new UnsupportedOperationException();
     }
 
-    @Override
     public boolean copy(String sourcePath, String destPath) {
         throw new UnsupportedOperationException();
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/MutableTree.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/MutableTree.java?rev=1565322&r1=1565321&r2=1565322&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/MutableTree.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/MutableTree.java Thu Feb  6 16:15:38 2014
@@ -320,16 +320,6 @@ class MutableTree extends AbstractTree {
     }
 
     /**
-     * Copy this tree to the parent at {@code destParent} with the new name
-     * {@code newName}.
-     * @param newParent new parent for this tree
-     * @param newName   new name for this tree
-     */
-    boolean copyTo(MutableTree newParent, String newName) {
-        return nodeBuilder.copyTo(newParent.nodeBuilder, newName);
-    }
-
-    /**
      * Get a possibly non existing tree.
      * @param path the path to the tree
      * @return a {@link Tree} instance for the child at {@code path}.

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeBuilder.java?rev=1565322&r1=1565321&r2=1565322&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeBuilder.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeBuilder.java Thu Feb  6 16:15:38 2014
@@ -28,7 +28,7 @@ import com.google.common.base.Predicate;
 import org.apache.jackrabbit.oak.api.Blob;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
-import org.apache.jackrabbit.oak.kernel.FastCopyMove;
+import org.apache.jackrabbit.oak.kernel.FastMove;
 import org.apache.jackrabbit.oak.kernel.KernelNodeBuilder;
 import org.apache.jackrabbit.oak.plugins.tree.ImmutableTree;
 import org.apache.jackrabbit.oak.spi.security.Context;
@@ -48,7 +48,7 @@ import static org.apache.jackrabbit.oak.
 import static org.apache.jackrabbit.oak.api.Type.NAMES;
 import static org.apache.jackrabbit.oak.api.Type.STRING;
 
-class SecureNodeBuilder implements NodeBuilder, FastCopyMove {
+class SecureNodeBuilder implements NodeBuilder, FastMove {
 
     /**
      * Root builder, or {@code this} for the root builder itself.
@@ -180,11 +180,6 @@ class SecureNodeBuilder implements NodeB
         return exists() && builder.moveTo(newParent, newName);
     }
 
-    @Override
-    public boolean copyTo(NodeBuilder newParent, String newName) {
-        return exists() && builder.copyTo(newParent, newName);
-    }
-
     @Override @CheckForNull
     public PropertyState getProperty(String name) {
         PropertyState property = builder.getProperty(name);
@@ -362,18 +357,6 @@ class SecureNodeBuilder implements NodeB
     }
 
     /**
-     * This implementation simply delegates back to {@code copyTo} method
-     * of {@code source} passing the underlying builder for {@code newParent}.
-     * @param source  source to move to this builder
-     * @param newName  the new name
-     * @return
-     */
-    @Override
-    public boolean copyFrom(KernelNodeBuilder source, String newName) {
-        return source.copyTo(builder, newName);
-    }
-
-    /**
      * Permissions of this tree.
      *
      * @return The permissions for this tree.

Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/FastMove.java (from r1564696, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/FastCopyMove.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/FastMove.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/FastMove.java&p1=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/FastCopyMove.java&r1=1564696&r2=1565322&rev=1565322&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/FastCopyMove.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/FastMove.java Thu Feb  6 16:15:38 2014
@@ -24,7 +24,7 @@ package org.apache.jackrabbit.oak.kernel
  * {@link org.apache.jackrabbit.oak.spi.state.NodeBuilder} implementations to indicate
  * support for optimised move and copy operations.
  */
-public interface FastCopyMove {
+public interface FastMove {
 
     /**
      * Move the {@code source} builder to this builder with the
@@ -34,13 +34,4 @@ public interface FastCopyMove {
      * @return  {@code true} on success, {@code false} otherwise
      */
     boolean moveFrom(KernelNodeBuilder source, String newName);
-
-    /**
-     * Copy the {@code source} builder to this builder with the
-     * given new name
-     * @param source  source to copy to this builder
-     * @param newName  the new name
-     * @return  {@code true} on success, {@code false} otherwise
-     */
-    boolean copyFrom(KernelNodeBuilder source, String newName);
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeBuilder.java?rev=1565322&r1=1565321&r2=1565322&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeBuilder.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeBuilder.java Thu Feb  6 16:15:38 2014
@@ -16,19 +16,19 @@
  */
 package org.apache.jackrabbit.oak.kernel;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
 /**
  * This class refines move and copy operations by delegating
  * them to the underlying store if possible.
  * @see KernelRootBuilder
  */
-public class KernelNodeBuilder extends MemoryNodeBuilder implements FastCopyMove {
+public class KernelNodeBuilder extends MemoryNodeBuilder implements FastMove {
 
     private final KernelRootBuilder root;
 
@@ -72,35 +72,18 @@ public class KernelNodeBuilder extends M
      */
     @Override
     public boolean moveTo(NodeBuilder newParent, String newName) {
-        if (newParent instanceof FastCopyMove) {
+        if (newParent instanceof FastMove) {
             checkNotNull(newParent);
             checkNotNull(newName);
             annotateSourcePath();
             boolean success = !isRoot() && exists() && !newParent.hasChildNode(newName) &&
-                    ((FastCopyMove) newParent).moveFrom(this, newName);
+                    ((FastMove) newParent).moveFrom(this, newName);
             return success;
         } else {
             return super.moveTo(newParent, newName);
         }
     }
 
-    /**
-     * If {@code newParent} is a {@link KernelNodeBuilder} this implementation
-     * purges all pending changes before applying the copy operation. This allows the
-     * underlying store to better optimise copy operations instead of just seeing
-     * them as an added node.
-     * If {@code newParent} is not a {@code KernelNodeBuilder} the implementation
-     * falls back to the super class.
-     */
-    @Override
-    public boolean copyTo(NodeBuilder newParent, String newName) {
-        if (newParent instanceof FastCopyMove) {
-            return ((FastCopyMove) newParent).copyFrom(this, newName);
-        } else {
-            return super.copyTo(newParent, newName);
-        }
-    }
-
     @Override
     public boolean moveFrom(KernelNodeBuilder source, String newName) {
         String sourcePath = source.getPath();
@@ -108,11 +91,4 @@ public class KernelNodeBuilder extends M
         return root.move(sourcePath, destPath);
     }
 
-    @Override
-    public boolean copyFrom(KernelNodeBuilder source, String newName) {
-        String sourcePath = source.getPath();
-        String destPath = PathUtils.concat(getPath(), newName);
-        return root.copy(sourcePath, destPath);
-    }
-
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelRootBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelRootBuilder.java?rev=1565322&r1=1565321&r2=1565322&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelRootBuilder.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelRootBuilder.java Thu Feb  6 16:15:38 2014
@@ -31,7 +31,7 @@ import org.apache.jackrabbit.oak.spi.sta
  * This implementation tracks the number of pending changes and purges them to
  * a private branch of the underlying store if a certain threshold is met.
  */
-class KernelRootBuilder extends MemoryNodeBuilder implements FastCopyMove {
+class KernelRootBuilder extends MemoryNodeBuilder implements FastMove {
 
     /**
      * Number of content updates that need to happen before the updates
@@ -102,12 +102,6 @@ class KernelRootBuilder extends MemoryNo
         return move(sourcePath, '/' + newName);
     }
 
-    @Override
-    public boolean copyFrom(KernelNodeBuilder source, String newName) {
-        String sourcePath = source.getPath();
-        return copy(sourcePath, '/' + newName);
-    }
-
     //------------------------------------------------------------< internal >---
 
     /**

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/NodeStoreKernel.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/NodeStoreKernel.java?rev=1565322&r1=1565321&r2=1565322&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/NodeStoreKernel.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/NodeStoreKernel.java Thu Feb  6 16:15:38 2014
@@ -16,13 +16,6 @@
  */
 package org.apache.jackrabbit.oak.kernel;
 
-import static com.google.common.collect.Lists.newArrayList;
-import static com.google.common.collect.Lists.newLinkedList;
-import static com.google.common.collect.Maps.newConcurrentMap;
-import static com.google.common.collect.Maps.newLinkedHashMap;
-import static org.apache.jackrabbit.oak.commons.PathUtils.getName;
-import static org.apache.jackrabbit.oak.commons.PathUtils.getParentPath;
-
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.LinkedList;
@@ -31,7 +24,6 @@ import java.util.Map;
 import java.util.UUID;
 import java.util.zip.CheckedInputStream;
 import java.util.zip.Checksum;
-
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 
@@ -58,6 +50,13 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
 
+import static com.google.common.collect.Lists.newArrayList;
+import static com.google.common.collect.Lists.newLinkedList;
+import static com.google.common.collect.Maps.newConcurrentMap;
+import static com.google.common.collect.Maps.newLinkedHashMap;
+import static org.apache.jackrabbit.oak.commons.PathUtils.getName;
+import static org.apache.jackrabbit.oak.commons.PathUtils.getParentPath;
+
 /**
  * This is a simple {@link NodeStore}-based {@link MicroKernel} implementation.
  */
@@ -219,15 +218,6 @@ public class NodeStoreKernel implements 
                     throw new MicroKernelException("Move failed");
                 }
                 break;
-            case '*':
-                tokenizer.read(':');
-                String copyTarget = tokenizer.readString();
-                if (!getNode(builder, path).copyTo(
-                        getNode(builder, getParentPath(copyTarget)),
-                        getName(copyTarget))) {
-                    throw new MicroKernelException("Copy failed");
-                }
-                break;
             default:
                 throw new MicroKernelException(
                         "Unexpected token: " + tokenizer.getEscapedToken());

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java?rev=1565322&r1=1565321&r2=1565322&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java Thu Feb  6 16:15:38 2014
@@ -16,20 +16,13 @@
  */
 package org.apache.jackrabbit.oak.plugins.memory;
 
-import static com.google.common.base.Objects.toStringHelper;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Preconditions.checkState;
-import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
-
 import java.io.IOException;
 import java.io.InputStream;
-
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 
 import com.google.common.base.Objects;
 import com.google.common.io.ByteStreams;
-
 import org.apache.jackrabbit.oak.api.Blob;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
@@ -39,6 +32,11 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
+import static com.google.common.base.Objects.toStringHelper;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
+import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
+
 /**
  * In-memory node state builder.
  * <p>
@@ -435,16 +433,6 @@ public class MemoryNodeBuilder implement
     }
 
     @Override
-    public boolean copyTo(NodeBuilder newParent, String newName) {
-        if (isRoot()) {
-            return false;
-        } else {
-            checkNotNull(newParent).setChildNode(checkNotNull(newName), getNodeState());
-            return true;
-        }
-    }
-
-    @Override
     public long getPropertyCount() {
         return head().getCurrentNodeState().getPropertyCount();
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java?rev=1565322&r1=1565321&r2=1565322&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java Thu Feb  6 16:15:38 2014
@@ -257,14 +257,6 @@ public interface NodeBuilder {
     boolean moveTo(@Nonnull NodeBuilder newParent, @Nonnull String newName);
 
     /**
-     * Copy this child to a new parent with a new name.
-     * @param newParent  builder for the new parent.
-     * @param newName  name of this child at the new parent
-     * @return  {@code true} on success, {@code false} otherwise
-     */
-    boolean copyTo(@Nonnull NodeBuilder newParent, @Nonnull String newName);
-
-    /**
      * Returns the current number of properties.
      *
      * @return number of properties

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java?rev=1565322&r1=1565321&r2=1565322&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java Thu Feb  6 16:15:38 2014
@@ -116,11 +116,6 @@ public class ReadOnlyBuilder implements 
     }
 
     @Override
-    public boolean copyTo(NodeBuilder newParent, String newName) {
-        throw unsupported();
-    }
-
-    @Override
     public long getPropertyCount() {
         return state.getPropertyCount();
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TreeUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TreeUtil.java?rev=1565322&r1=1565321&r2=1565322&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TreeUtil.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TreeUtil.java Thu Feb  6 16:15:38 2014
@@ -16,6 +16,28 @@
  */
 package org.apache.jackrabbit.oak.util;
 
+import java.util.Calendar;
+import java.util.List;
+import java.util.Set;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager;
+import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
+import org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants;
+import org.apache.jackrabbit.util.ISO8601;
+
 import static com.google.common.collect.Lists.newArrayList;
 import static java.util.Collections.emptyList;
 import static org.apache.jackrabbit.JcrConstants.JCR_AUTOCREATED;
@@ -44,30 +66,6 @@ import static org.apache.jackrabbit.oak.
 import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.REP_NAMED_PROPERTY_DEFINITIONS;
 import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.REP_RESIDUAL_CHILD_NODE_DEFINITIONS;
 
-import java.util.Calendar;
-import java.util.List;
-import java.util.Set;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nonnull;
-import javax.jcr.RepositoryException;
-import javax.jcr.nodetype.ConstraintViolationException;
-import javax.jcr.nodetype.NoSuchNodeTypeException;
-
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-
-import org.apache.jackrabbit.JcrConstants;
-import org.apache.jackrabbit.oak.api.PropertyState;
-import org.apache.jackrabbit.oak.api.Tree;
-import org.apache.jackrabbit.oak.api.Type;
-import org.apache.jackrabbit.oak.commons.PathUtils;
-import org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager;
-import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
-import org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants;
-import org.apache.jackrabbit.util.ISO8601;
-
 /**
  * Utility providing common operations for the {@code Tree} that are not provided
  * by the API.
@@ -172,8 +170,9 @@ public final class TreeUtil {
         return tree;
     }
 
-    public static Tree addChild(
-            Tree parent, String name, String typeName, Tree typeRoot, String userID)
+    public static Tree addChild(@Nonnull Tree parent, @Nonnull String name,
+                                @Nonnull String typeName, @Nonnull Tree typeRoot,
+                                @CheckForNull String userID)
             throws RepositoryException {
         Tree type = typeRoot.getChild(typeName);
         if (!type.exists()) {

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/api/RootTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/api/RootTest.java?rev=1565322&r1=1565321&r2=1565322&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/api/RootTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/api/RootTest.java Thu Feb  6 16:15:38 2014
@@ -18,14 +18,14 @@
  */
 package org.apache.jackrabbit.oak.api;
 
-import static org.apache.jackrabbit.oak.OakAssert.assertSequence;
-
 import org.apache.jackrabbit.oak.NodeStoreFixture;
 import org.apache.jackrabbit.oak.OakBaseTest;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
+import static org.apache.jackrabbit.oak.OakAssert.assertSequence;
+
 /**
  * Contains tests related to {@link Root}
  */
@@ -48,27 +48,6 @@ public class RootTest extends OakBaseTes
     }
 
     @Test
-    public void copyOrderableNodes() throws Exception {
-        ContentSession s = repository.login(null, null);
-        try {
-            Root r = s.getLatestRoot();
-            Tree t = r.getTree("/");
-            Tree c = t.addChild("c");
-            c.addChild("node1").orderBefore(null);
-            c.addChild("node2");
-            t.addChild("node3");
-            r.commit();
-
-            r.copy("/node3", "/c/node3");
-            assertSequence(c.getChildren(), "node1", "node2", "node3");
-            r.commit();
-            assertSequence(c.getChildren(), "node1", "node2", "node3");
-        } finally {
-            s.close();
-        }
-    }
-
-    @Test
     public void moveOrderableNodes() throws Exception {
         ContentSession s = repository.login(null, null);
         try {

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootFuzzIT.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootFuzzIT.java?rev=1565322&r1=1565321&r2=1565322&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootFuzzIT.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootFuzzIT.java Thu Feb  6 16:15:38 2014
@@ -18,15 +18,6 @@
  */
 package org.apache.jackrabbit.oak.core;
 
-import static org.apache.jackrabbit.oak.core.RootFuzzIT.Operation.AddNode;
-import static org.apache.jackrabbit.oak.core.RootFuzzIT.Operation.CopyNode;
-import static org.apache.jackrabbit.oak.core.RootFuzzIT.Operation.MoveNode;
-import static org.apache.jackrabbit.oak.core.RootFuzzIT.Operation.RemoveNode;
-import static org.apache.jackrabbit.oak.core.RootFuzzIT.Operation.RemoveProperty;
-import static org.apache.jackrabbit.oak.core.RootFuzzIT.Operation.Save;
-import static org.apache.jackrabbit.oak.core.RootFuzzIT.Operation.SetProperty;
-import static org.junit.Assert.assertEquals;
-
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Iterator;
@@ -49,6 +40,14 @@ import org.junit.runners.Parameterized.P
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.apache.jackrabbit.oak.core.RootFuzzIT.Operation.AddNode;
+import static org.apache.jackrabbit.oak.core.RootFuzzIT.Operation.MoveNode;
+import static org.apache.jackrabbit.oak.core.RootFuzzIT.Operation.RemoveNode;
+import static org.apache.jackrabbit.oak.core.RootFuzzIT.Operation.RemoveProperty;
+import static org.apache.jackrabbit.oak.core.RootFuzzIT.Operation.Save;
+import static org.apache.jackrabbit.oak.core.RootFuzzIT.Operation.SetProperty;
+import static org.junit.Assert.assertEquals;
+
 /**
  * Fuzz test running random sequences of operations on {@link Tree}.
  * Run with -DRootFuzzIT-seed=42 to set a specific seed (i.e. 42);
@@ -221,26 +220,6 @@ public class RootFuzzIT {
             }
         }
 
-        static class CopyNode extends Operation {
-            private final String source;
-            private final String destination;
-
-            CopyNode(String source, String destParent, String destName) {
-                this.source = source;
-                destination = PathUtils.concat(destParent, destName);
-            }
-
-            @Override
-            void apply(Root root) {
-                root.copy(source, destination);
-            }
-
-            @Override
-            public String toString() {
-                return '*' + source + ':' + destination;
-            }
-        }
-
         static class SetProperty extends Operation {
             private final String parentPath;
             private final String propertyName;
@@ -312,7 +291,7 @@ public class RootFuzzIT {
     private Operation createOperation() {
         Operation op;
         do {
-            switch (random.nextInt(11)) {
+            switch (random.nextInt(10)) {
                 case 0:
                 case 1:
                 case 2:
@@ -325,22 +304,18 @@ public class RootFuzzIT {
                     op = createMoveNode();
                     break;
                 case 5:
-                    // Too many copy ops make the test way slow
-                    op = random.nextInt(10) == 0 ? createCopyNode() : null;
-                    break;
-                case 6:
                     op = createAddProperty();
                     break;
-                case 7:
+                case 6:
                     op = createSetProperty();
                     break;
-                case 8:
+                case 7:
                     op = createRemoveProperty();
                     break;
-                case 9:
+                case 8:
                     op = new Save();
                     break;
-                case 10:
+                case 9:
                     op = new Rebase();
                     break;
                 default:
@@ -370,15 +345,6 @@ public class RootFuzzIT {
                 : new MoveNode(source, destParent, destName);
     }
 
-    private Operation createCopyNode() {
-        String source = chooseNodePath();
-        String destParent = chooseNodePath();
-        String destName = createNodeName();
-        return "/root".equals(source)
-                ? null
-                : new CopyNode(source, destParent, destName);
-    }
-
     private Operation createAddProperty() {
         String parent = chooseNodePath();
         String name = createPropertyName();

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootTest.java?rev=1565322&r1=1565321&r2=1565322&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootTest.java Thu Feb  6 16:15:38 2014
@@ -192,24 +192,6 @@ public class RootTest extends OakBaseTes
         assertFalse(root.move("/s", "/s/t"));
     }
 
-    @Test
-    public void copyToSelf() throws CommitFailedException {
-        Root root = session.getLatestRoot();
-        root.getTree("/").addChild("s");
-        root.commit();
-
-        assertFalse(root.copy("/s", "/s"));
-    }
-
-    @Test
-    public void copyToDescendant() throws CommitFailedException {
-        Root root = session.getLatestRoot();
-        root.getTree("/").addChild("s");
-        root.commit();
-
-        assertTrue(root.copy("/s", "/s/t"));
-    }
-
     /**
      * Regression test for OAK-208
      */
@@ -252,51 +234,6 @@ public class RootTest extends OakBaseTes
     }
 
     @Test
-    public void copy() throws CommitFailedException {
-        Root root = session.getLatestRoot();
-        Tree tree = root.getTree("/");
-
-        Tree y = tree.getChild("y");
-        Tree x = tree.getChild("x");
-        assertTrue(x.exists());
-
-        assertTrue(tree.hasChild("x"));
-        root.copy("/x", "/y/xx");
-        assertTrue(tree.hasChild("x"));
-        assertTrue(y.hasChild("xx"));
-        
-        root.commit();
-
-        assertTrue(tree.hasChild("x"));
-        assertTrue(tree.hasChild("y"));
-        assertTrue(tree.getChild("y").hasChild("xx"));
-    }
-
-    @Test
-    public void deepCopy() throws CommitFailedException {
-        Root root = session.getLatestRoot();
-        Tree tree = root.getTree("/");
-
-        Tree y = tree.getChild("y");
-
-        root.getTree("/x").addChild("x1");
-        root.copy("/x", "/y/xx");
-        assertTrue(y.hasChild("xx"));
-        assertTrue(y.getChild("xx").hasChild("x1"));
-
-        root.commit();
-
-        assertTrue(tree.hasChild("x"));
-        assertTrue(tree.hasChild("y"));
-        assertTrue(tree.getChild("y").hasChild("xx"));
-        assertTrue(tree.getChild("y").getChild("xx").hasChild("x1"));
-
-        Tree x = tree.getChild("x");
-        Tree xx = tree.getChild("y").getChild("xx");
-        checkEqual(x, xx);
-    }
-
-    @Test
     public void rebase() throws CommitFailedException {
         Root root1 = session.getLatestRoot();
         Root root2 = session.getLatestRoot();
@@ -458,24 +395,6 @@ public class RootTest extends OakBaseTes
     }
 
     @Test
-    public void rebaseWithCopy() throws CommitFailedException {
-        Root root1 = session.getLatestRoot();
-        Root root2 = session.getLatestRoot();
-
-        checkEqual(root1.getTree("/"), root2.getTree("/"));
-
-        root2.getTree("/").addChild("one").addChild("two").addChild("three")
-                .setProperty("p1", "V1");
-        root2.commit();
-
-        root1.copy("/x", "/y/x-copied");
-        root1.rebase();
-
-        root2.copy("/x", "/y/x-copied");
-        checkEqual(root1.getTree("/"), (root2.getTree("/")));
-    }
-
-    @Test
     public void oak962() throws CommitFailedException {
         Root root = session.getLatestRoot();
         Tree r = root.getTree("/").addChild("root");

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilderTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilderTest.java?rev=1565322&r1=1565321&r2=1565322&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilderTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilderTest.java Thu Feb  6 16:15:38 2014
@@ -16,13 +16,6 @@
  */
 package org.apache.jackrabbit.oak.plugins.memory;
 
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertFalse;
-import static junit.framework.Assert.assertTrue;
-import static junit.framework.Assert.fail;
-import static org.apache.jackrabbit.oak.api.Type.STRING;
-import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
-
 import javax.annotation.Nonnull;
 
 import com.google.common.collect.ImmutableSet;
@@ -34,6 +27,13 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.junit.Before;
 import org.junit.Test;
 
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+import static junit.framework.Assert.fail;
+import static org.apache.jackrabbit.oak.api.Type.STRING;
+import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
+
 public class MemoryNodeBuilderTest {
 
     private NodeState base;
@@ -327,44 +327,6 @@ public class MemoryNodeBuilderTest {
     }
 
     @Test
-    public void testCopy() {
-        NodeBuilder rootBuilder = base.builder();
-        assertTrue(rootBuilder.getChildNode("y").copyTo(rootBuilder.child("x"), "yy"));
-
-        NodeState newRoot = rootBuilder.getNodeState();
-        assertTrue(newRoot.hasChildNode("y"));
-        assertTrue(newRoot.hasChildNode("x"));
-        assertTrue(newRoot.getChildNode("x").hasChildNode("q"));
-        assertTrue(newRoot.getChildNode("x").hasChildNode("yy"));
-    }
-
-    @Test
-    public void testDuplicate() {
-        NodeBuilder rootBuilder = base.builder();
-        assertTrue(rootBuilder.getChildNode("y").copyTo(rootBuilder, "yy"));
-
-        NodeState newRoot = rootBuilder.getNodeState();
-        assertTrue(newRoot.hasChildNode("y"));
-        assertTrue(newRoot.hasChildNode("yy"));
-    }
-
-    @Test
-    public void testCopyToSelf() {
-        NodeBuilder rootBuilder = base.builder();
-        assertTrue(rootBuilder.getChildNode("y").copyTo(rootBuilder, "y"));
-    }
-
-    @Test
-    public void testCopyToDescendant() {
-        NodeBuilder rootBuilder = base.builder();
-        assertTrue(rootBuilder.getChildNode("x").copyTo(rootBuilder.getChildNode("x"), "xx"));
-
-        NodeState newRoot = rootBuilder.getNodeState();
-        assertTrue(rootBuilder.hasChildNode("x"));
-        assertTrue(rootBuilder.getChildNode("x").hasChildNode("xx"));
-    }
-
-    @Test
     public void assertion_OAK781() {
         NodeBuilder rootBuilder = EMPTY_NODE.builder();
         rootBuilder.child("a").setChildNode("b", createBC(false));

Modified: jackrabbit/oak/trunk/oak-jcr/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/pom.xml?rev=1565322&r1=1565321&r2=1565322&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-jcr/pom.xml Thu Feb  6 16:15:38 2014
@@ -119,7 +119,6 @@
       org.apache.jackrabbit.oak.jcr.security.authorization.VersionManagementTest#testRemoveVersion2  <!-- OAK-168 -->
       org.apache.jackrabbit.oak.jcr.security.authorization.VersionManagementTest#testRemoveVersion3  <!-- OAK-168 -->
 
-      org.apache.jackrabbit.oak.jcr.security.authorization.CopyTest#testCopyInvisibleSubTree         <!-- OAK-920 -->
       org.apache.jackrabbit.oak.jcr.security.authorization.MultipleMoveTest#testMoveSubTreeBack4     <!-- OAK-710 -->
       org.apache.jackrabbit.oak.jcr.security.authorization.MultipleMoveTest#testMoveDestParent2      <!-- OAK-710 -->
       org.apache.jackrabbit.oak.jcr.security.authorization.MultipleMoveTest#testMoveDestParent4      <!-- OAK-710 -->

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/WorkspaceDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/WorkspaceDelegate.java?rev=1565322&r1=1565321&r2=1565322&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/WorkspaceDelegate.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/WorkspaceDelegate.java Thu Feb  6 16:15:38 2014
@@ -19,27 +19,31 @@ package org.apache.jackrabbit.oak.jcr.de
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import javax.annotation.Nonnull;
 import javax.jcr.ItemExistsException;
 import javax.jcr.PathNotFoundException;
 import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.ConstraintViolationException;
 
+import com.google.common.collect.Maps;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.api.Type;
-import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.jcr.security.AccessManager;
 import org.apache.jackrabbit.oak.jcr.session.SessionContext;
 import org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager;
 import org.apache.jackrabbit.oak.plugins.memory.GenericPropertyState;
 import org.apache.jackrabbit.oak.plugins.memory.MultiGenericPropertyState;
 import org.apache.jackrabbit.oak.spi.security.authorization.permission.Permissions;
-
-import com.google.common.collect.Maps;
+import org.apache.jackrabbit.oak.util.TreeUtil;
+import org.apache.jackrabbit.test.api.util.Text;
 
 import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
 import static org.apache.jackrabbit.JcrConstants.JCR_UUID;
+import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.NODE_TYPES_PATH;
 
 /**
  * Delegate class for workspace operations.
@@ -69,14 +73,16 @@ public class WorkspaceDelegate {
         }
 
         // check parent of destination
-        String destParentPath = PathUtils.getParentPath(destPath);
-        Tree destParent = root.getTree(destParentPath);
+        Tree destParent = dest.getParent();
         if (!destParent.exists()) {
-            throw new PathNotFoundException(PathUtils.getParentPath(destPath));
+            throw new PathNotFoundException(destParent.getPath());
         }
 
         // check source exists
         Tree src = root.getTree(srcPath);
+        if (src.isRoot()) {
+            throw new RepositoryException("Cannot copy the root node");
+        }
         if (!src.exists()) {
             throw new PathNotFoundException(srcPath);
         }
@@ -84,7 +90,8 @@ public class WorkspaceDelegate {
         accessManager.checkPermissions(destPath, Permissions.getString(Permissions.NODE_TYPE_MANAGEMENT));
 
         try {
-            new WorkspaceCopy(root, srcPath, destPath).perform();
+            Tree typeRoot = root.getTree(NODE_TYPES_PATH);
+            new WorkspaceCopy(src, destParent, Text.getName(destPath), typeRoot, sessionDelegate.getAuthInfo().getUserID()).perform();
             context.getSessionDelegate().commit(root);
             sessionDelegate.refresh(true);
         } catch (CommitFailedException e) {
@@ -94,41 +101,62 @@ public class WorkspaceDelegate {
 
     //---------------------------< internal >-----------------------------------
 
-    private class WorkspaceCopy {
+    private static final class WorkspaceCopy {
 
         private final Map<String, String> translated = Maps.newHashMap();
-        private final String srcPath;
-        private final String destPath;
-        private final Root currentRoot;
-
-        public WorkspaceCopy(Root currentRoot, String srcPath, String destPath) {
-            this.srcPath = checkNotNull(srcPath);
-            this.destPath = checkNotNull(destPath);
-            this.currentRoot = checkNotNull(currentRoot);
+
+        private final Tree src;
+        private final Tree destParent;
+        private final String destName;
+
+        private final Tree typeRoot;
+        private final String userId;
+
+        public WorkspaceCopy(@Nonnull Tree src, @Nonnull Tree destParent,
+                             @Nonnull String destName, @Nonnull Tree typeRoot,
+                             @Nonnull String userId) {
+            this.src = src;
+            this.destParent = destParent;
+            this.destName = destName;
+            this.typeRoot = typeRoot;
+            this.userId = userId;
         }
 
         public void perform() throws RepositoryException {
-            if (!currentRoot.copy(srcPath, destPath)) {
-                throw new RepositoryException("Cannot copy node at " + srcPath + " to " + destPath);
-            }
-            Tree src = currentRoot.getTree(srcPath);
-            Tree dest = currentRoot.getTree(destPath);
-            generateNewIdentifiers(dest);
-            updateReferences(src, dest);
+            copy(src, destParent, destName);
+            updateReferences(src, destParent.getChild(destName));
         }
 
-        public void generateNewIdentifiers(Tree t) throws RepositoryException {
-            if (t.hasProperty(JCR_UUID)) {
-                getNewId(t);
+        private void copy(@Nonnull Tree source, @Nonnull Tree destParent, @Nonnull String destName) throws RepositoryException {
+            String primaryType = TreeUtil.getPrimaryTypeName(source);
+            if (primaryType == null) {
+                primaryType = TreeUtil.getDefaultChildType(typeRoot, destParent, destName);
+                if (primaryType == null) {
+                    throw new ConstraintViolationException("Cannot determine default node type.");
+                }
             }
-            for (Tree c : t.getChildren()) {
-                generateNewIdentifiers(c);
+            Tree dest = TreeUtil.addChild(destParent, destName, primaryType, typeRoot, userId);
+            for (PropertyState property : source.getProperties()) {
+                String propName = property.getName();
+                if (JCR_UUID.equals(propName)) {
+                    String sourceId = property.getValue(Type.STRING);
+                    String newId = IdentifierManager.generateUUID();
+                    dest.setProperty(JCR_UUID, newId, Type.STRING);
+                    if (!translated.containsKey(sourceId)) {
+                        translated.put(sourceId, newId);
+                    }
+                } else if (!JCR_PRIMARYTYPE.equals(propName)) {
+                    dest.setProperty(property);
+                }
+            }
+            for (Tree child : source.getChildren()) {
+                copy(child, dest, child.getName());
             }
         }
 
         /**
          * Recursively updates references on the destination tree as defined by
-         * <code>Workspace.copy()</code>.
+         * {@code Workspace.copy()}.
          *
          * @param src  the source tree of the copy operation.
          * @param dest the unprocessed copy of the tree.
@@ -149,8 +177,7 @@ public class WorkspaceDelegate {
             }
         }
 
-        private void updateProperty(PropertyState prop, Tree dest)
-                throws RepositoryException {
+        private void updateProperty(PropertyState prop, Tree dest) {
             boolean multi = prop.isArray();
             boolean weak = prop.getType() == Type.WEAKREFERENCE
                     || prop.getType() == Type.WEAKREFERENCES;
@@ -183,8 +210,7 @@ public class WorkspaceDelegate {
             dest.setProperty(p);
         }
 
-        private void translateId(String id, List<String> ids)
-                throws RepositoryException {
+        private void translateId(String id, List<String> ids) {
             String newId = translated.get(id);
             if (newId != null) {
                 ids.add(newId);
@@ -192,23 +218,6 @@ public class WorkspaceDelegate {
                 ids.add(id);
             }
         }
-
-        private String getNewId(Tree t) throws RepositoryException {
-            PropertyState uuid = t.getProperty(JCR_UUID);
-            if (uuid == null) {
-                // not referenceable?
-                throw new RepositoryException(
-                        "Node is not referenceable: " + t.getPath());
-            }
-            String targetId = uuid.getValue(Type.STRING);
-            // new id needed?
-            if (!translated.containsKey(targetId)) {
-                String newId = IdentifierManager.generateUUID();
-                translated.put(targetId, newId);
-                t.setProperty(JCR_UUID, newId, Type.STRING);
-            }
-            return translated.get(targetId);
-        }
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/authorization/CopyTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/authorization/CopyTest.java?rev=1565322&r1=1565321&r2=1565322&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/authorization/CopyTest.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/authorization/CopyTest.java Thu Feb  6 16:15:38 2014
@@ -24,7 +24,6 @@ import org.apache.jackrabbit.oak.spi.sec
 import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants;
 import org.apache.jackrabbit.util.Text;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 
 /**
@@ -79,7 +78,6 @@ public class CopyTest extends AbstractEv
         assertTrue(testSession.nodeExists(destPath));
     }
 
-    @Ignore("OAK-920") // FIXME
     @Test
     public void testCopyInvisibleSubTree() throws Exception {
         deny(childNPath, privilegesFromName(Privilege.JCR_READ));



Mime
View raw message