Author: jukka
Date: Tue Sep 17 14:37:19 2013
New Revision: 1524071
URL: http://svn.apache.org/r1524071
Log:
OAK-1020: Property value converion ignores reisdual property definition
Fix by better tracking of fuzzy matches in
NodeDelegate.findMatchingPropertyDefinition.
Note that if there's a *protected* named definition, we must not do fuzzy
matching, thus the early return.
Also a test by Chetan Mehrotra.
Modified:
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CompatibilityIssuesTest.java
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=1524071&r1=1524070&r2=1524071&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
Tue Sep 17 14:37:19 2013
@@ -586,6 +586,7 @@ public class NodeDelegate extends ItemDe
}
// First look for a matching named property definition
+ Tree fuzzyMatch = null;
for (Tree type : types) {
Tree definitions = type
.getChild(OAK_NAMED_PROPERTY_DEFINITIONS)
@@ -598,10 +599,12 @@ public class NodeDelegate extends ItemDe
if (definition.exists()) {
return definition;
}
- if (!exactTypeMatch) {
- for (Tree def : definitions.getChildren()) {
- if (propertyType.isArray() == TreeUtil.getBoolean(def,
JCR_MULTIPLE)) {
- return def;
+ for (Tree def : definitions.getChildren()) {
+ if (propertyType.isArray() == TreeUtil.getBoolean(def,
JCR_MULTIPLE)) {
+ if (getBoolean(def, JCR_PROTECTED)) {
+ return null; // no fuzzy matches for protected items
+ } else if (!exactTypeMatch && fuzzyMatch == null) {
+ fuzzyMatch = def;
}
}
}
@@ -618,16 +621,17 @@ public class NodeDelegate extends ItemDe
if (definition.exists()) {
return definition;
}
- if (!exactTypeMatch) {
+ if (!exactTypeMatch && fuzzyMatch == null) {
for (Tree def : definitions.getChildren()) {
if (propertyType.isArray() == TreeUtil.getBoolean(def,
JCR_MULTIPLE)) {
- return def;
+ fuzzyMatch = def;
+ break;
}
}
}
}
- return null;
+ return fuzzyMatch;
}
private Tree findMatchingChildNodeDefinition(
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=1524071&r1=1524070&r2=1524071&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
Tue Sep 17 14:37:19 2013
@@ -22,6 +22,10 @@ import static org.junit.Assert.assertEqu
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -32,6 +36,7 @@ import javax.jcr.Credentials;
import javax.jcr.InvalidItemStateException;
import javax.jcr.ItemExistsException;
import javax.jcr.Node;
+import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
@@ -40,11 +45,15 @@ import javax.jcr.nodetype.NodeDefinition
import javax.jcr.nodetype.NodeDefinitionTemplate;
import javax.jcr.nodetype.NodeTypeManager;
import javax.jcr.nodetype.NodeTypeTemplate;
+import javax.jcr.nodetype.PropertyDefinition;
+import javax.jcr.nodetype.PropertyDefinitionTemplate;
import javax.jcr.observation.Event;
import javax.jcr.observation.EventIterator;
import javax.jcr.observation.EventListener;
import javax.jcr.observation.ObservationManager;
+import junit.framework.Assert;
+import org.apache.commons.io.IOUtils;
import org.apache.jackrabbit.api.JackrabbitRepository;
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.junit.Test;
@@ -278,4 +287,44 @@ public class CompatibilityIssuesTest ext
session.save();
}
+ @Test
+ public void testBinaryCoercion() throws RepositoryException, IOException {
+ Session session = getAdminSession();
+
+ // node type with default child-node type of to nt:base
+ String ntName = "binaryCoercionTest";
+ NodeTypeManager ntm = session.getWorkspace().getNodeTypeManager();
+
+ NodeTypeTemplate ntt = ntm.createNodeTypeTemplate();
+ ntt.setName(ntName);
+
+ PropertyDefinitionTemplate propertyWithType =
ntm.createPropertyDefinitionTemplate();
+ propertyWithType.setName("javaObject");
+ propertyWithType.setRequiredType(PropertyType.STRING);
+
+ PropertyDefinitionTemplate unnamed =
ntm.createPropertyDefinitionTemplate();
+ unnamed.setName("*");
+ unnamed.setRequiredType(PropertyType.UNDEFINED);
+
+ List<PropertyDefinition> properties =
ntt.getPropertyDefinitionTemplates();
+ properties.add(propertyWithType);
+ properties.add(unnamed);
+
+ ntm.registerNodeType(ntt, false);
+
+ Node node = session.getRootNode().addNode("testNodeForBinary", ntName);
+ ByteArrayOutputStream bos = serializeObject("testValue");
+
node.setProperty("javaObject",session.getValueFactory().createBinary(new
ByteArrayInputStream(bos.toByteArray())));
+
+ Assert.assertTrue(IOUtils.contentEquals(new
ByteArrayInputStream(bos.toByteArray()),
node.getProperty("javaObject").getStream()));
+ }
+
+ private ByteArrayOutputStream serializeObject(Object o) throws IOException
{
+ ByteArrayOutputStream out = new ByteArrayOutputStream(5000);
+ ObjectOutputStream objectStream = new ObjectOutputStream(out);
+ objectStream.writeObject(o);
+ objectStream.flush();
+ return out;
+ }
+
}