Author: jukka
Date: Thu Mar 6 18:11:02 2014
New Revision: 1574983
URL: http://svn.apache.org/r1574983
Log:
OAK-1013: Node.addNode(name) different behavior from JR if NodeType resolves to
an abstract
Only allow the default primary type to be abstract.
Unify default type handling in TreeUtil.
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=1574983&r1=1574982&r2=1574983&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 18:11:02 2014
@@ -83,7 +83,7 @@ class TypeEditor extends DefaultEditor {
this.parent = null;
this.nodeName = null;
this.types = checkNotNull(types);
- this.effective = getEffectiveType(primary, mixins);
+ this.effective = getEffectiveType(null, null, primary, mixins);
this.builder = checkNotNull(builder);
}
@@ -94,7 +94,8 @@ class TypeEditor extends DefaultEditor {
this.parent = checkNotNull(parent);
this.nodeName = checkNotNull(name);
this.types = parent.types;
- this.effective = getEffectiveType(primary, mixins);
+ this.effective =
+ getEffectiveType(parent.effective, name, primary, mixins);
this.builder = checkNotNull(builder);
}
@@ -236,6 +237,7 @@ class TypeEditor extends DefaultEditor {
//-----------------------------------------------------------< private >--
private EffectiveType getEffectiveType(
+ EffectiveType parent, String name,
String primary, Iterable<String> mixins)
throws CommitFailedException {
List<NodeState> list = Lists.newArrayList();
@@ -249,8 +251,16 @@ class TypeEditor extends DefaultEditor {
2, "Mixin 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());
+ if (parent != null &&
primary.equals(parent.getDefaultType(name))) {
+ // OAK-1013: Allow (with a warning) an abstract primary
+ // type if it's the default type implied by the parent node
+ log.warn("Abstract type " + primary
+ + " used as the default primary type of node "
+ + getPath());
+ } else {
+ throw constraintViolation(
+ 2, "Abstract type " + primary + " used as the
primary type");
+ }
}
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=1574983&r1=1574982&r2=1574983&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 18:11:02 2014
@@ -174,17 +174,26 @@ public final class TreeUtil {
return tree;
}
- public static Tree addChild(@Nonnull Tree parent, @Nonnull String name,
- @Nonnull String typeName, boolean explicitType,
- @Nonnull Tree typeRoot,
- @CheckForNull String userID)
- throws RepositoryException {
+ public static Tree addChild(
+ @Nonnull Tree parent, @Nonnull String name,
+ @CheckForNull String typeName, @Nonnull Tree typeRoot,
+ @CheckForNull String userID) throws RepositoryException {
+ if (typeName == null) {
+ typeName = getDefaultChildType(typeRoot, parent, name);
+ if (typeName == null) {
+ String path = PathUtils.concat(parent.getPath(), name);
+ throw new ConstraintViolationException(
+ "No default node type available for " + path);
+ }
+ }
+
Tree type = typeRoot.getChild(typeName);
if (!type.exists()) {
throw new NoSuchNodeTypeException(
"Node type " + typeName + " does not exist");
- } else if (explicitType // OAK-1013: backwards compatibility
- && getBoolean(type, JCR_IS_ABSTRACT)) {
+ } else if (getBoolean(type, JCR_IS_ABSTRACT)
+ // OAK-1013: backwards compatibility for abstract default types
+ && !typeName.equals(getDefaultChildType(typeRoot, parent,
name))) {
throw new ConstraintViolationException(
"Node type " + typeName + " is abstract");
} else if (getBoolean(type, JCR_ISMIXIN)) {
@@ -277,7 +286,7 @@ public final class TreeUtil {
if (!tree.hasChild(name)) {
String typeName =
getName(definition, JCR_DEFAULTPRIMARYTYPE);
- addChild(tree, name, typeName, false, typeRoot,
userID);
+ addChild(tree, name, typeName, 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=1574983&r1=1574982&r2=1574983&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 18:11:02 2014
@@ -686,20 +686,8 @@ 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(
- "No default node type available for node "
- + PathUtils.concat(tree.getPath(), name));
- }
- }
-
- Tree child = internalAddChild(
- tree, name, typeName, explicitType, typeRoot);
+ Tree child = TreeUtil.addChild(tree, name, typeName, typeRoot,
getUserID());
return new NodeDelegate(sessionDelegate, child);
}
@@ -853,14 +841,6 @@ public class NodeDelegate extends ItemDe
//------------------------------------------------------------< internal
>---
- private Tree internalAddChild(
- Tree parent, String name,
- String typeName, boolean explicitType, Tree typeRoot)
- throws RepositoryException {
- return TreeUtil.addChild(
- parent, name, typeName, explicitType, typeRoot, getUserID());
- }
-
@Nonnull // FIXME this should be package private. OAK-672
public Tree getTree() throws InvalidItemStateException {
if (!tree.exists()) {
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=1574983&r1=1574982&r2=1574983&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 18:11:02 2014
@@ -24,7 +24,6 @@ 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.ImmutableMap;
import com.google.common.collect.Maps;
@@ -135,19 +134,9 @@ 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, explicitType, typeRoot, userId);
+ destParent, destName, primaryType, 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=1574983&r1=1574982&r2=1574983&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 18:11:02 2014
@@ -183,17 +183,10 @@ 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();
- 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) {
+ parent, nInfo.getName(), ntName, ntTypesRoot, userID);
+ if (ntName != null) {
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=1574983&r1=1574982&r2=1574983&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 18:11:02 2014
@@ -300,7 +300,7 @@ public class CompatibilityIssuesTest ext
Node node = session.getRootNode().addNode("defaultNtBase", ntName);
node.addNode("nothrow"); // See OAK-1013
try {
- node.addNode("throw", "nt:base");
+ node.addNode("throw", "nt:hierarchyNode");
fail("Abstract primary type should cause
ConstraintViolationException");
} catch (ConstraintViolationException expected) {
}