Permalink
Browse files

JCR-3452: Modified property and child node definition are rejected

trivial modifications:
- adding/removing nt:base as requiredPrimaryType constraint
- making a single-valued property multi-valued
- changing a property's requiredType constraint to UNDEFINED

git-svn-id: https://svn.apache.org/repos/asf/jackrabbit/trunk@1415685 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 1822df9 commit ad814e90da2f4e40ceab2bb1cb66dbfc9e593f0f @stefan-guggisberg stefan-guggisberg committed Nov 30, 2012
@@ -602,11 +602,14 @@ protected void init() {
// no need to check defaultPrimaryType (TRIVIAL change)
if (type == TRIVIAL) {
- List<Name> l1 = Arrays.asList(getOldDef().getRequiredPrimaryTypes());
- List<Name> l2 = Arrays.asList(getNewDef().getRequiredPrimaryTypes());
- if (!l1.equals(l2)) {
+ Set<Name> s1 = new HashSet<Name>(Arrays.asList(getOldDef().getRequiredPrimaryTypes()));
+ Set<Name> s2 = new HashSet<Name>(Arrays.asList(getNewDef().getRequiredPrimaryTypes()));
+ // normalize sets by removing nt:base (adding/removing nt:base is irrelevant for the diff)
+ s1.remove(NameConstants.NT_BASE);
+ s2.remove(NameConstants.NT_BASE);
+ if (!s1.equals(s2)) {
// requiredPrimaryTypes have been modified
- if (l1.containsAll(l2)) {
+ if (s1.containsAll(s2)) {
// old list is a superset of new list
// => removed requiredPrimaryType (TRIVIAL change)
type = TRIVIAL;
@@ -628,16 +631,12 @@ protected void init() {
Name declaringNodeType;
Name name;
- int requiredType;
boolean definesResidual;
- boolean isMultiple;
QPropertyDefinitionId(QPropertyDefinition def) {
declaringNodeType = def.getDeclaringNodeType();
name = def.getName();
- requiredType = def.getRequiredType();
definesResidual = def.definesResidual();
- isMultiple = def.isMultiple();
}
//---------------------------------------< java.lang.Object overrides >
@@ -650,9 +649,7 @@ public boolean equals(Object obj) {
QPropertyDefinitionId other = (QPropertyDefinitionId) obj;
return declaringNodeType.equals(other.declaringNodeType)
&& name.equals(other.name)
- && requiredType == other.requiredType
- && definesResidual == other.definesResidual
- && isMultiple == other.isMultiple;
+ && definesResidual == other.definesResidual;
}
return false;
}
@@ -663,8 +660,6 @@ public int hashCode() {
h = 37 * h + declaringNodeType.hashCode();
h = 37 * h + name.hashCode();
h = 37 * h + (definesResidual ? 11 : 43);
- h = 37 * h + (isMultiple ? 11 : 43);
- h = 37 * h + requiredType;
return h;
}
}
@@ -676,16 +671,10 @@ public int hashCode() {
Name declaringNodeType;
Name name;
- Name[] requiredPrimaryTypes;
QNodeDefinitionId(QNodeDefinition def) {
declaringNodeType = def.getDeclaringNodeType();
name = def.getName();
- requiredPrimaryTypes = def.getRequiredPrimaryTypes();
- if (requiredPrimaryTypes == null || requiredPrimaryTypes.length == 0) {
- requiredPrimaryTypes = new Name[]{NameConstants.NT_BASE};
- }
- Arrays.sort(requiredPrimaryTypes);
}
//---------------------------------------< java.lang.Object overrides >
@@ -697,8 +686,7 @@ public boolean equals(Object obj) {
if (obj instanceof QNodeDefinitionId) {
QNodeDefinitionId other = (QNodeDefinitionId) obj;
return declaringNodeType.equals(other.declaringNodeType)
- && name.equals(other.name)
- && Arrays.equals(requiredPrimaryTypes, other.requiredPrimaryTypes);
+ && name.equals(other.name);
}
return false;
}
@@ -708,9 +696,6 @@ public int hashCode() {
int h = 17;
h = 37 * h + declaringNodeType.hashCode();
h = 37 * h + name.hashCode();
- for (int i = 0; i < requiredPrimaryTypes.length; i++) {
- h = 37 * h + requiredPrimaryTypes[i].hashCode();
- }
return h;
}
}
@@ -0,0 +1,92 @@
+/*
+ * 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.spi.commons.nodetype;
+
+import junit.framework.TestCase;
+
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.NameFactory;
+import org.apache.jackrabbit.spi.QNodeDefinition;
+import org.apache.jackrabbit.spi.QPropertyDefinition;
+import org.apache.jackrabbit.spi.commons.name.NameConstants;
+import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
+
+import javax.jcr.PropertyType;
+
+public class NodeTypeDefDiffTest extends TestCase {
+
+ private static final NameFactory FACTORY = NameFactoryImpl.getInstance();
+
+ private static final Name NODE_TYPE1 = FACTORY.create("{}nodeType1");
+ private static final Name PROP_NAME = FACTORY.create("{}prop");
+ private static final Name CHILD_NAME = FACTORY.create("{}child");
+
+ public void testChangedPropertyDefinition() throws Exception {
+ // old node type definition
+ QNodeTypeDefinitionBuilder oldDef = new QNodeTypeDefinitionBuilder();
+ oldDef.setName(NODE_TYPE1);
+ oldDef.setSupertypes(new Name[] { NameConstants.NT_BASE });
+
+ QPropertyDefinitionBuilder oldPropDef = new QPropertyDefinitionBuilder();
+ oldPropDef.setDeclaringNodeType(NODE_TYPE1);
+ oldPropDef.setName(PROP_NAME);
+ oldPropDef.setRequiredType(PropertyType.STRING);
+ oldPropDef.setMultiple(false);
+
+ oldDef.setPropertyDefs(new QPropertyDefinition[]{oldPropDef.build()});
+
+ QNodeDefinitionBuilder oldChildDef = new QNodeDefinitionBuilder();
+ oldChildDef.setRequiredPrimaryTypes(new Name[]{ NODE_TYPE1, NameConstants.NT_FOLDER });
+ oldChildDef.setName(CHILD_NAME);
+ oldChildDef.setDeclaringNodeType(oldDef.getName());
+
+ oldDef.setChildNodeDefs(new QNodeDefinition[] { oldChildDef.build() });
+
+ // new node type definition
+ QNodeTypeDefinitionBuilder newDef = new QNodeTypeDefinitionBuilder();
+ newDef.setName(NODE_TYPE1);
+ newDef.setSupertypes(new Name[] { NameConstants.NT_BASE });
+
+ QPropertyDefinitionBuilder newPropDef = new QPropertyDefinitionBuilder();
+ newPropDef.setDeclaringNodeType(NODE_TYPE1);
+ newPropDef.setName(PROP_NAME);
+ newPropDef.setRequiredType(PropertyType.UNDEFINED);
+ newPropDef.setMultiple(true);
+
+ newDef.setPropertyDefs(new QPropertyDefinition[]{newPropDef.build()});
+
+ QNodeDefinitionBuilder newChildDef = new QNodeDefinitionBuilder();
+ newChildDef.setRequiredPrimaryTypes(new Name[]{ NameConstants.NT_BASE, NODE_TYPE1, NameConstants.NT_FOLDER });
+ newChildDef.setRequiredPrimaryTypes(new Name[]{ NODE_TYPE1, NameConstants.NT_BASE });
+ newChildDef.setName(CHILD_NAME);
+ newChildDef.setDeclaringNodeType(oldDef.getName());
+
+ newDef.setChildNodeDefs(new QNodeDefinition[] { newChildDef.build() });
+
+ // change a property def isMultiple from false to true and requiredType STRING to UNDEFINED
+ // remove nt:folder from a node def's requiredPrimaryType constraint
+ NodeTypeDefDiff nodeTypeDefDiff = NodeTypeDefDiff.create(oldDef.build(), newDef.build());
+ System.out.println(nodeTypeDefDiff);
+ assertTrue(nodeTypeDefDiff.isTrivial());
+
+ // change a property def isMultiple from true to false and requiredType UNDEFINED to STRING
+ // add nt:folder to a node def's requiredPrimaryType constraint
+ nodeTypeDefDiff = NodeTypeDefDiff.create(newDef.build(), oldDef.build());
+ System.out.println(nodeTypeDefDiff);
+ assertTrue(nodeTypeDefDiff.isMajor());
+ }
+}
@@ -32,6 +32,7 @@
public static Test suite() {
TestSuite suite = new TestSuite("org.apache.jackrabbit.spi.commons.nodetype tests");
+ suite.addTestSuite(NodeTypeDefDiffTest.class);
suite.addTestSuite(NodeDefinitionTemplateImplTest.class);
suite.addTestSuite(PropertyDefinitionTemplateImplTest.class);

0 comments on commit ad814e9

Please sign in to comment.