Author: angela
Date: Wed Jan 15 19:30:42 2014
New Revision: 1558539
URL: http://svn.apache.org/r1558539
Log:
OAK-770 : NodeImpl should implement JackrabbitNode (wip)
Added:
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/JackrabbitNodeTest.java
(with props)
jackrabbit/oak/trunk/oak-jcr/src/test/resources/org/apache/jackrabbit/oak/jcr/test_mixin_nodetypes.cnd
(with props)
Modified:
jackrabbit/oak/trunk/oak-jcr/pom.xml
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java
Modified: jackrabbit/oak/trunk/oak-jcr/pom.xml
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/pom.xml?rev=1558539&r1=1558538&r2=1558539&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-jcr/pom.xml Wed Jan 15 19:30:42 2014
@@ -116,6 +116,9 @@
org.apache.jackrabbit.oak.jcr.security.authorization.CopyTest#testCopyInvisibleProperty
<!-- OAK-920 -->
org.apache.jackrabbit.oak.jcr.security.authorization.CopyTest#testCopyInvisibleAcContent
<!-- OAK-920 -->
+ <!-- JackrabbitNode -->
+ org.apache.jackrabbit.oak.jcr.JackrabbitNodeTest#testSetMixins
<!-- OAK-770 -->
+
<!-- Query -->
org.apache.jackrabbit.test.api.query.ElementTest#testElementTestNameTestSomeNTWithSNS
<!-- OAK-203 -->
org.apache.jackrabbit.test.api.query.SaveTest#testItemExistsException
<!-- OAK-203 -->
Modified:
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java?rev=1558539&r1=1558538&r2=1558539&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java
(original)
+++
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java
Wed Jan 15 19:30:42 2014
@@ -55,7 +55,6 @@ import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
-
import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.api.JackrabbitNode;
import org.apache.jackrabbit.commons.ItemNameMatcher;
@@ -65,7 +64,6 @@ import org.apache.jackrabbit.oak.api.Pro
import org.apache.jackrabbit.oak.api.Tree.Status;
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.jcr.delegate.NodeDelegate;
import org.apache.jackrabbit.oak.jcr.delegate.PropertyDelegate;
import org.apache.jackrabbit.oak.jcr.delegate.VersionManagerDelegate;
@@ -74,6 +72,7 @@ import org.apache.jackrabbit.oak.jcr.loc
import org.apache.jackrabbit.oak.jcr.session.operation.NodeOperation;
import org.apache.jackrabbit.oak.jcr.version.VersionHistoryImpl;
import org.apache.jackrabbit.oak.jcr.version.VersionImpl;
+import org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager;
import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
import org.apache.jackrabbit.oak.plugins.nodetype.EffectiveNodeType;
import
org.apache.jackrabbit.oak.spi.security.authorization.permission.Permissions;
@@ -1424,9 +1423,55 @@ public class NodeImpl<T extends NodeDele
}
//-----------------------------------------------------< JackrabbitNode
>---
+
+ /**
+ * Simplified implementation of {@link JackrabbitNode#rename(String)}. In
+ * contrast to the implementation in Jackrabbit 2.x which was operating on
+ * the NodeState level directly, this implementation does a move plus
+ * subsequent reorder on the JCR API due to a missing support for renaming
+ * on the OAK API.
+ *
+ * Note, that this also has an impact on how permissions are enforced: In
+ * Jackrabbit 2.x the rename just required permission to modify the child
+ * collection on the parent, whereas a move did the full permission check.
+ * With this simplified implementation that (somewhat inconsistent)
difference
+ * has been removed.
+ *
+ * @param newName The new name of this node.
+ * @throws RepositoryException If an error occurs.
+ */
@Override
public void rename(String newName) throws RepositoryException {
- throw new UnsupportedRepositoryOperationException("TODO:
JackrabbitNode.rename (OAK-770");
+ if (dlg.isRoot()) {
+ throw new RepositoryException("Cannot rename the root node");
+ }
+
+ String name = getName();
+ if (newName.equals(name)) {
+ // nothing to do
+ return;
+ }
+
+ String beforeName = null;
+ Node parent = getParent();
+ NodeIterator nit = parent.getNodes();
+ while (nit.hasNext()) {
+ Node child = nit.nextNode();
+ if (name.equals(child.getName())) {
+ if (nit.hasNext()) {
+ beforeName = nit.nextNode().getName();
+ }
+ break;
+ }
+ }
+
+ String srcPath = getPath();
+ String destPath = PathUtils.getAncestorPath(srcPath, 1) + '/' +
newName;
+ sessionContext.getSession().move(srcPath, destPath);
+
+ if (beforeName != null) {
+ parent.orderBefore(newName, beforeName);
+ }
}
@Override
Added:
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/JackrabbitNodeTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/JackrabbitNodeTest.java?rev=1558539&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/JackrabbitNodeTest.java
(added)
+++
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/JackrabbitNodeTest.java
Wed Jan 15 19:30:42 2014
@@ -0,0 +1,178 @@
+/*
+ * 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;
+
+import java.io.InputStreamReader;
+import java.io.Reader;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.observation.Event;
+import javax.jcr.observation.ObservationManager;
+
+import org.apache.jackrabbit.api.JackrabbitNode;
+import org.apache.jackrabbit.commons.cnd.CndImporter;
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.api.observation.EventResult;
+import org.junit.Ignore;
+
+/**
+ * JackrabbitNodeTest: Copied and slightly adjusted from
org.apache.jackrabbit.api.JackrabbitNodeTest,
+ * which used to create SNS for this test.
+ */
+public class JackrabbitNodeTest extends AbstractJCRTest {
+
+ static final String SEQ_BEFORE = "abcdefghij";
+ static final String SEQ_AFTER = "abcdefGhij";
+ static final int RELPOS = 6;
+
+ static final String TEST_NODETYPES =
"org/apache/jackrabbit/oak/jcr/test_mixin_nodetypes.cnd";
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ assertTrue(testRootNode.getPrimaryNodeType().hasOrderableChildNodes());
+ for (char c : SEQ_BEFORE.toCharArray()) {
+ testRootNode.addNode(new String(new char[]{c}));
+ }
+ superuser.save();
+
+ Reader cnd = new
InputStreamReader(getClass().getClassLoader().getResourceAsStream(TEST_NODETYPES));
+ CndImporter.registerNodeTypes(cnd, superuser);
+ cnd.close();
+ }
+
+ public void testRename() throws RepositoryException {
+ Node renamedNode = null;
+ NodeIterator it = testRootNode.getNodes();
+ int pos = 0;
+ while (it.hasNext()) {
+ Node n = it.nextNode();
+ String name = n.getName();
+ assertEquals(new String(new char[]{SEQ_BEFORE.charAt(pos)}), name);
+ if (pos == RELPOS) {
+ JackrabbitNode node = (JackrabbitNode) n;
+ node.rename(name.toUpperCase());
+ renamedNode = n;
+ }
+ pos++;
+ }
+
+ it = testRootNode.getNodes();
+ pos = 0;
+ while (it.hasNext()) {
+ Node n = it.nextNode();
+ String name = n.getName();
+ assertEquals(new String(new char[]{SEQ_AFTER.charAt(pos)}), name);
+ if (pos == RELPOS) {
+ assertTrue(n.isSame(renamedNode));
+ }
+ pos++;
+ }
+ }
+
+ public void testRenameEventHandling() throws RepositoryException {
+ Session s = getHelper().getSuperuserSession();
+ ObservationManager mgr = s.getWorkspace().getObservationManager();
+ EventResult result = new EventResult(log);
+
+ try {
+ mgr.addEventListener(result,
Event.PERSIST|Event.NODE_ADDED|Event.NODE_MOVED|Event.NODE_REMOVED,
testRootNode.getPath(), true, null, null, false);
+
+ NodeIterator it = testRootNode.getNodes();
+
+ Node n = it.nextNode();
+ String name = n.getName();
+
+ JackrabbitNode node = (JackrabbitNode) n;
+ node.rename(name.toUpperCase());
+ superuser.save();
+
+ boolean foundMove = false;
+ for (Event event : result.getEvents(5000)) {
+ if (Event.NODE_MOVED == event.getType()) {
+ foundMove = true;
+ break;
+ }
+ }
+
+ if (!foundMove) {
+ fail("Expected NODE_MOVED event upon renaming a node.");
+ }
+ } finally {
+ mgr.removeEventListener(result);
+ s.logout();
+ }
+ }
+
+ public void testRemoveMixin() throws RepositoryException {
+ // create node with mixin test:AA
+ Node n = testRootNode.addNode("foo", "nt:folder");
+ n.addMixin("test:AA");
+ n.setProperty("test:propAA", "AA");
+ n.setProperty("test:propA", "A");
+ superuser.save();
+
+ // 'downgrade' from test:AA to test:A
+ n.removeMixin("test:AA");
+ superuser.save();
+
+ assertFalse(n.hasProperty("test:propA"));
+ assertFalse(n.hasProperty("test:propAA"));
+ }
+
+ @Ignore("OAK-770") // FIXME: OAK-770
+ public void testSetMixins() throws RepositoryException {
+ // create node with mixin test:AA
+ Node n = testRootNode.addNode("foo", "nt:folder");
+ n.addMixin("test:AA");
+ n.setProperty("test:propAA", "AA");
+ n.setProperty("test:propA", "A");
+ superuser.save();
+
+ // 'downgrade' from test:AA to test:A
+ ((JackrabbitNode) n).setMixins(new String[]{"test:A"});
+ superuser.save();
+
+ assertTrue(n.hasProperty("test:propA"));
+ assertFalse(n.hasProperty("test:propAA"));
+
+ // 'upgrade' from test:A to test:AA
+ ((JackrabbitNode) n).setMixins(new String[]{"test:AA"});
+ n.setProperty("test:propAA", "AA");
+ superuser.save();
+
+ assertTrue(n.hasProperty("test:propA"));
+ assertTrue(n.hasProperty("test:propAA"));
+
+ // replace test:AA with mix:title
+ ((JackrabbitNode) n).setMixins(new String[]{"mix:title"});
+ n.setProperty("jcr:title", "...");
+ n.setProperty("jcr:description", "blah blah");
+ superuser.save();
+
+ assertTrue(n.hasProperty("jcr:title"));
+ assertTrue(n.hasProperty("jcr:description"));
+ assertFalse(n.hasProperty("test:propA"));
+ assertFalse(n.hasProperty("test:propAA"));
+
+ // clean up
+ n.remove();
+ superuser.save();
+ }
+}
Propchange:
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/JackrabbitNodeTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
jackrabbit/oak/trunk/oak-jcr/src/test/resources/org/apache/jackrabbit/oak/jcr/test_mixin_nodetypes.cnd
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/resources/org/apache/jackrabbit/oak/jcr/test_mixin_nodetypes.cnd?rev=1558539&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-jcr/src/test/resources/org/apache/jackrabbit/oak/jcr/test_mixin_nodetypes.cnd
(added)
+++
jackrabbit/oak/trunk/oak-jcr/src/test/resources/org/apache/jackrabbit/oak/jcr/test_mixin_nodetypes.cnd
Wed Jan 15 19:30:42 2014
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+<test = "http://www.apache.org/jackrabbit/test">
+
+[test:A] mixin
+ - test:propA (STRING)
+
+[test:AA] > test:A
+ mixin
+ - test:propAA (STRING)
Propchange:
jackrabbit/oak/trunk/oak-jcr/src/test/resources/org/apache/jackrabbit/oak/jcr/test_mixin_nodetypes.cnd
------------------------------------------------------------------------------
svn:eol-style = native