Author: jukka
Date: Thu Mar 6 17:22:35 2014
New Revision: 1574970
URL: http://svn.apache.org/r1574970
Log:
OAK-1013: Node.addNode(name) different behavior from JR if NodeType resolves to
an abstract
Allow abstract types to be used in jcr:primaryType and jcr:mixinTypes,
but throw an exception if explicitly passed in addNode(..., type) and
log warnings in other cases.
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditor.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TreeUtil.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/WorkspaceDelegate.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CompatibilityIssuesTest.java
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditor.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditor.java?rev=1574970&r1=1574969&r2=1574970&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditor.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditor.java
Thu Mar 6 17:22:35 2014
@@ -32,6 +32,8 @@ import org.apache.jackrabbit.oak.spi.com
import org.apache.jackrabbit.oak.spi.commit.Editor;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.apache.jackrabbit.JcrConstants.JCR_ISMIXIN;
@@ -62,6 +64,8 @@ import static org.apache.jackrabbit.oak.
*/
class TypeEditor extends DefaultEditor {
+ private static final Logger log =
LoggerFactory.getLogger(TypeEditor.class);
+
private final TypeEditor parent;
private final String nodeName;
@@ -243,10 +247,11 @@ class TypeEditor extends DefaultEditor {
} else if (type.getBoolean(JCR_ISMIXIN)) {
throw constraintViolation(
2, "Mixin type " + primary + " used as the primary type");
- } else if (type.getBoolean(JCR_IS_ABSTRACT)) {
- throw constraintViolation(
- 3, "Abstract type " + primary + " used as the primary
type");
} else {
+ if (type.getBoolean(JCR_IS_ABSTRACT)) {
+ log.warn("Abstract type " + primary
+ + " used as the primary type of node " + getPath());
+ }
list.add(type);
}
@@ -259,10 +264,11 @@ class TypeEditor extends DefaultEditor {
} else if (!type.getBoolean(JCR_ISMIXIN)) {
throw constraintViolation(
6, "Primary type " + mixin + " used as a mixin type");
- } else if (type.getBoolean(JCR_IS_ABSTRACT)) {
- throw constraintViolation(
- 7, "Abstract type " + mixin + " used as a mixin type");
} else {
+ if (type.getBoolean(JCR_IS_ABSTRACT)) {
+ log.warn("Abstract type " + mixin
+ + " used as a mixin type of node " + getPath());
+ }
list.add(type);
}
}
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=1574970&r1=1574969&r2=1574970&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 Mar 6 17:22:35 2014
@@ -19,6 +19,7 @@ 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;
@@ -28,6 +29,7 @@ import javax.jcr.nodetype.NoSuchNodeType
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;
@@ -173,14 +175,16 @@ public final class TreeUtil {
}
public static Tree addChild(@Nonnull Tree parent, @Nonnull String name,
- @Nonnull String typeName, @Nonnull Tree
typeRoot,
+ @Nonnull String typeName, boolean explicitType,
+ @Nonnull Tree typeRoot,
@CheckForNull String userID)
throws RepositoryException {
Tree type = typeRoot.getChild(typeName);
if (!type.exists()) {
throw new NoSuchNodeTypeException(
"Node type " + typeName + " does not exist");
- } else if (getBoolean(type, JCR_IS_ABSTRACT)) {
+ } else if (explicitType // OAK-1013: backwards compatibility
+ && getBoolean(type, JCR_IS_ABSTRACT)) {
throw new ConstraintViolationException(
"Node type " + typeName + " is abstract");
} else if (getBoolean(type, JCR_ISMIXIN)) {
@@ -273,7 +277,7 @@ public final class TreeUtil {
if (!tree.hasChild(name)) {
String typeName =
getName(definition, JCR_DEFAULTPRIMARYTYPE);
- addChild(tree, name, typeName, typeRoot, userID);
+ addChild(tree, name, typeName, false, typeRoot,
userID);
}
break;
}
Modified:
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java?rev=1574970&r1=1574969&r2=1574970&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java
(original)
+++
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java
Thu Mar 6 17:22:35 2014
@@ -686,8 +686,10 @@ public class NodeDelegate extends ItemDe
return null;
}
+ boolean explicitType = true;
Tree typeRoot = sessionDelegate.getRoot().getTree(NODE_TYPES_PATH);
if (typeName == null) {
+ explicitType = false;
typeName = TreeUtil.getDefaultChildType(typeRoot, tree, name);
if (typeName == null) {
throw new ConstraintViolationException(
@@ -696,7 +698,8 @@ public class NodeDelegate extends ItemDe
}
}
- Tree child = internalAddChild(tree, name, typeName, typeRoot);
+ Tree child = internalAddChild(
+ tree, name, typeName, explicitType, typeRoot);
return new NodeDelegate(sessionDelegate, child);
}
@@ -851,9 +854,11 @@ public class NodeDelegate extends ItemDe
//------------------------------------------------------------< internal
>---
private Tree internalAddChild(
- Tree parent, String name, String typeName, Tree typeRoot)
+ Tree parent, String name,
+ String typeName, boolean explicitType, Tree typeRoot)
throws RepositoryException {
- return TreeUtil.addChild(parent, name, typeName, typeRoot,
getUserID());
+ return TreeUtil.addChild(
+ parent, name, typeName, explicitType, typeRoot, getUserID());
}
@Nonnull // FIXME this should be package private. OAK-672
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=1574970&r1=1574969&r2=1574970&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 Mar 6 17:22:35 2014
@@ -135,14 +135,19 @@ public class WorkspaceDelegate {
private void copy(Tree source, Tree destParent, String destName, Tree
typeRoot, String userId)
throws RepositoryException {
+ boolean explicitType = true;
String primaryType = TreeUtil.getPrimaryTypeName(source);
if (primaryType == null) {
+ explicitType = false;
primaryType = TreeUtil.getDefaultChildType(typeRoot,
destParent, destName);
if (primaryType == null) {
throw new ConstraintViolationException("Cannot determine
default node type.");
}
}
- Tree dest = TreeUtil.addChild(destParent, destName, primaryType,
typeRoot, userId);
+
+ Tree dest = TreeUtil.addChild(
+ destParent, destName,
+ primaryType, explicitType, typeRoot, userId);
for (PropertyState property : source.getProperties()) {
String propName = property.getName();
if (JCR_MIXINTYPES.equals(propName)) {
Modified:
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java?rev=1574970&r1=1574969&r2=1574970&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java
(original)
+++
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java
Thu Mar 6 17:22:35 2014
@@ -183,10 +183,17 @@ public class ImporterImpl implements Imp
}
private Tree createTree(@Nonnull Tree parent, @Nonnull NodeInfo nInfo,
@CheckForNull String uuid) throws RepositoryException {
+ boolean explicitType = true;
String ntName = nInfo.getPrimaryTypeName();
- String value = (ntName != null) ? ntName :
TreeUtil.getDefaultChildType(ntTypesRoot, parent, nInfo.getName());
- Tree child = TreeUtil.addChild(parent, nInfo.getName(), value,
ntTypesRoot, userID);
- if (ntName != null) {
+ if (ntName == null) {
+ explicitType = false;
+ ntName = TreeUtil.getDefaultChildType(
+ ntTypesRoot, parent, nInfo.getName());
+ }
+ Tree child = TreeUtil.addChild(
+ parent, nInfo.getName(),
+ ntName, explicitType, ntTypesRoot, userID);
+ if (explicitType) {
accessManager.checkPermissions(child,
child.getProperty(JcrConstants.JCR_PRIMARYTYPE),
Permissions.NODE_TYPE_MANAGEMENT);
}
if (uuid != null) {
Modified:
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CompatibilityIssuesTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CompatibilityIssuesTest.java?rev=1574970&r1=1574969&r2=1574970&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CompatibilityIssuesTest.java
(original)
+++
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CompatibilityIssuesTest.java
Thu Mar 6 17:22:35 2014
@@ -279,7 +279,7 @@ public class CompatibilityIssuesTest ext
}
}
- @Test(expected = ConstraintViolationException.class)
+ @Test
public void addNodeTest() throws RepositoryException {
Session session = getAdminSession();
@@ -298,7 +298,12 @@ public class CompatibilityIssuesTest ext
// try to create a node with the default nt:base
Node node = session.getRootNode().addNode("defaultNtBase", ntName);
- node.addNode("throw"); // Throws ConstraintViolationException on Oak,
works on Jackrabbit 2
+ node.addNode("nothrow"); // See OAK-1013
+ try {
+ node.addNode("throw", "nt:base");
+ fail("Abstract primary type should cause
ConstraintViolationException");
+ } catch (ConstraintViolationException expected) {
+ }
session.save();
}