Author: chetanm
Date: Thu Nov 3 13:54:03 2016
New Revision: 1767884
URL: http://svn.apache.org/viewvc?rev=1767884&view=rev
Log:
OAK-5045 - Support bundling of nodes present in version store
Added:
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/document/
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/document/VersionedDocumentBundlingTest.java
(with props)
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundledTypesRegistry.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundledTypesRegistryTest.java
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundledTypesRegistry.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundledTypesRegistry.java?rev=1767884&r1=1767883&r2=1767884&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundledTypesRegistry.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundledTypesRegistry.java
Thu Nov 3 13:54:03 2016
@@ -62,27 +62,45 @@ public class BundledTypesRegistry {
@CheckForNull
public DocumentBundlor getBundlor(NodeState state) {
+ if (isVersionedNode(state)){
+ return getBundlorForVersionedNode(state);
+ }
//Prefer mixin (as they are more specific) over primaryType
- for (String mixin : getMixinNames(state)){
+ for (String mixin : getMixinNames(state, JcrConstants.JCR_MIXINTYPES)){
DocumentBundlor bundlor = bundlors.get(mixin);
if (bundlor != null){
return bundlor;
}
}
- return bundlors.get(getPrimaryTypeName(state));
+ return bundlors.get(getPrimaryTypeName(state,
JcrConstants.JCR_PRIMARYTYPE));
+ }
+
+ private DocumentBundlor getBundlorForVersionedNode(NodeState state) {
+ //Prefer mixin (as they are more specific) over primaryType
+ for (String mixin : getMixinNames(state,
JcrConstants.JCR_FROZENMIXINTYPES)){
+ DocumentBundlor bundlor = bundlors.get(mixin);
+ if (bundlor != null){
+ return bundlor;
+ }
+ }
+ return bundlors.get(getPrimaryTypeName(state,
JcrConstants.JCR_FROZENPRIMARYTYPE));
}
Map<String, DocumentBundlor> getBundlors() {
return bundlors;
}
- private static String getPrimaryTypeName(NodeState nodeState) {
- PropertyState ps = nodeState.getProperty(JcrConstants.JCR_PRIMARYTYPE);
+ private static boolean isVersionedNode(NodeState state) {
+ return JcrConstants.NT_FROZENNODE.equals(getPrimaryTypeName(state,
JcrConstants.JCR_PRIMARYTYPE));
+ }
+
+ private static String getPrimaryTypeName(NodeState nodeState, String
typePropName) {
+ PropertyState ps = nodeState.getProperty(typePropName);
return (ps == null) ? JcrConstants.NT_BASE : ps.getValue(Type.NAME);
}
- private static Iterable<String> getMixinNames(NodeState nodeState) {
- PropertyState ps = nodeState.getProperty(JcrConstants.JCR_MIXINTYPES);
+ private static Iterable<String> getMixinNames(NodeState nodeState, String
typePropName) {
+ PropertyState ps = nodeState.getProperty(typePropName);
return (ps == null) ? Collections.<String>emptyList() :
ps.getValue(Type.NAMES);
}
Modified:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundledTypesRegistryTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundledTypesRegistryTest.java?rev=1767884&r1=1767883&r2=1767884&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundledTypesRegistryTest.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundledTypesRegistryTest.java
Thu Nov 3 13:54:03 2016
@@ -21,12 +21,15 @@ package org.apache.jackrabbit.oak.plugin
import java.util.Collections;
+import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;
import org.junit.Test;
import static java.util.Arrays.asList;
+import static org.apache.jackrabbit.JcrConstants.JCR_FROZENMIXINTYPES;
+import static org.apache.jackrabbit.JcrConstants.JCR_FROZENPRIMARYTYPE;
import static org.apache.jackrabbit.JcrConstants.JCR_MIXINTYPES;
import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
import static org.apache.jackrabbit.oak.api.Type.STRINGS;
@@ -69,6 +72,31 @@ public class BundledTypesRegistryTest {
}
@Test
+ public void versioned() throws Exception{
+ builder.child("nt:file").setProperty(createProperty(PROP_PATTERN,
asList("jcr:content"), STRINGS));
+ BundledTypesRegistry registry =
BundledTypesRegistry.from(builder.getNodeState());
+
+ NodeBuilder builder = EMPTY_NODE.builder();
+ builder.setProperty(JCR_PRIMARYTYPE, JcrConstants.NT_FROZENNODE,
Type.NAME);
+ builder.setProperty(JCR_FROZENPRIMARYTYPE, "nt:file", Type.NAME);
+
+ assertNotNull(registry.getBundlor(builder.getNodeState()));
+ }
+
+ @Test
+ public void versionedMixins() throws Exception{
+ builder.child("mix:foo").setProperty(createProperty(PROP_PATTERN,
asList("jcr:content"), STRINGS));
+ BundledTypesRegistry registry =
BundledTypesRegistry.from(builder.getNodeState());
+
+ NodeBuilder builder = EMPTY_NODE.builder();
+ builder.setProperty(JCR_PRIMARYTYPE, JcrConstants.NT_FROZENNODE,
Type.NAME);
+ builder.setProperty(JCR_FROZENMIXINTYPES,
Collections.singleton("mix:foo"), Type.NAMES);
+
+ assertNotNull(registry.getBundlor(builder.getNodeState()));
+ }
+
+
+ @Test
public void mixinOverPrimaryType() throws Exception{
builder.child("mix:foo").setProperty(createProperty(PROP_PATTERN,
asList("foo"), STRINGS));
builder.child("nt:file").setProperty(createProperty(PROP_PATTERN,
asList("jcr:content"), STRINGS));
Added:
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/document/VersionedDocumentBundlingTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/document/VersionedDocumentBundlingTest.java?rev=1767884&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/document/VersionedDocumentBundlingTest.java
(added)
+++
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/document/VersionedDocumentBundlingTest.java
Thu Nov 3 13:54:03 2016
@@ -0,0 +1,134 @@
+/*
+ * 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.document;
+
+import java.io.IOException;
+import java.io.StringReader;
+
+import javax.jcr.Node;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+import javax.jcr.version.VersionManager;
+
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.jackrabbit.commons.JcrUtils;
+import org.apache.jackrabbit.commons.cnd.CndImporter;
+import org.apache.jackrabbit.commons.cnd.ParseException;
+import org.apache.jackrabbit.oak.NodeStoreFixtures;
+import org.apache.jackrabbit.oak.Oak;
+import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.fixture.NodeStoreFixture;
+import org.apache.jackrabbit.oak.jcr.Jcr;
+import org.apache.jackrabbit.oak.plugins.document.Collection;
+import org.apache.jackrabbit.oak.plugins.document.DocumentNodeState;
+import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
+import org.apache.jackrabbit.oak.plugins.document.DocumentStore;
+import org.apache.jackrabbit.oak.plugins.document.NodeDocument;
+import
org.apache.jackrabbit.oak.plugins.document.bundlor.BundlingConfigHandler;
+import org.apache.jackrabbit.oak.plugins.document.util.Utils;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.junit.After;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.apache.jackrabbit.oak.commons.PathUtils.concat;
+import static org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest.dispose;
+import static
org.apache.jackrabbit.oak.plugins.document.bundlor.DocumentBundlor.PROP_PATTERN;
+import static org.junit.Assert.assertNull;
+
+public class VersionedDocumentBundlingTest {
+ public static final String TEST_NODE_TYPE = "[oak:Asset]\n" +
+ " - * (UNDEFINED) multiple\n" +
+ " - * (UNDEFINED)\n" +
+ " + * (nt:base) = oak:TestNode VERSION";
+
+ private NodeStoreFixture fixture;
+ private NodeStore ns;
+ private Repository repository;
+ private Session s;
+ private DocumentStore ds;
+
+ @Before
+ public void setUp() throws Exception {
+ Assume.assumeTrue(NodeStoreFixtures.DOCUMENT_NS.isAvailable());
+ fixture = NodeStoreFixtures.DOCUMENT_MEM;
+
+ ns = fixture.createNodeStore();
+ if (ns == null){
+ return;
+ }
+ ds = ((DocumentNodeStore)ns).getDocumentStore();
+ Oak oak = new Oak(ns);
+ repository = new Jcr(oak).createRepository();
+ s = repository.login(new SimpleCredentials("admin",
"admin".toCharArray()));
+ configureBundling();
+ }
+
+ @After
+ public void tearDown(){
+ if (s != null){
+ s.logout();
+ }
+
+ dispose(repository);
+ if (ns != null){
+ fixture.dispose(ns);
+ }
+ }
+
+ @Test
+ public void createVersionedNode() throws Exception{
+ Node asset = JcrUtils.getOrCreateByPath("/bundlingtest/foo.png",
"oak:Unstructured", "oak:Asset", s, false);
+ asset.addMixin(JcrConstants.MIX_VERSIONABLE);
+ Node content = asset.addNode("jcr:content", "oak:Unstructured");
+ content.addNode("metadata", "oak:Unstructured");
+ s.save();
+
+ VersionManager vm = s.getWorkspace().getVersionManager();
+ String assetPath = asset.getPath();
+ vm.checkin(assetPath);
+
+ String versionedPath =
vm.getBaseVersion(assetPath).getNode("jcr:frozenNode").getPath();
+
+ //Both normal node and versioned nodes should be bundled
+ assertNull(getNodeDocument(concat(assetPath, "jcr:content")));
+ assertNull(getNodeDocument(concat(versionedPath, "jcr:content")));
+ }
+
+ private void configureBundling() throws ParseException,
RepositoryException, IOException {
+ CndImporter.registerNodeTypes(new StringReader(TEST_NODE_TYPE), s);
+ Node bundlor =
JcrUtils.getOrCreateByPath(BundlingConfigHandler.CONFIG_PATH,
"oak:Unstructured", s);
+ Node asset = bundlor.addNode("oak:Asset");
+ asset.setProperty(PROP_PATTERN, new String[]{
+ "jcr:content",
+ "jcr:content/metadata",
+ "jcr:content/renditions"
+ });
+
+ s.save();
+ }
+
+ private NodeDocument getNodeDocument(String path) {
+ return ds.find(Collection.NODES, Utils.getIdFromPath(path));
+ }
+}
Propchange:
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/document/VersionedDocumentBundlingTest.java
------------------------------------------------------------------------------
svn:eol-style = native