Author: chetanm
Date: Wed Oct 19 15:11:28 2016
New Revision: 1765644
URL: http://svn.apache.org/viewvc?rev=1765644&view=rev
Log:
OAK-1312 - [bundling] Bundle nodes into a document
Initializer to bootstrap default bundling config for nt:file
Added:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingConfigInitializer.java
(with props)
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingConfigInitializerTest.java
(with props)
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingConfigHandler.java
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingConfigHandler.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingConfigHandler.java?rev=1765644&r1=1765643&r2=1765644&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingConfigHandler.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingConfigHandler.java
Wed Oct 19 15:11:28 2016
@@ -47,7 +47,10 @@ import static com.google.common.base.Pre
import static
org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
public class BundlingConfigHandler implements Observer, Closeable {
- private static final String CONFIG_PATH =
"/jcr:system/documentstore/bundlor";
+ public static final String DOCUMENT_NODE_STORE = "documentstore";
+ public static final String BUNDLOR = "bundlor";
+
+ public static final String CONFIG_PATH =
"/jcr:system/documentstore/bundlor";
private final Logger log = LoggerFactory.getLogger(getClass());
private NodeState root = EMPTY_NODE;
private BackgroundObserver backgroundObserver;
Added:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingConfigInitializer.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingConfigInitializer.java?rev=1765644&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingConfigInitializer.java
(added)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingConfigInitializer.java
Wed Oct 19 15:11:28 2016
@@ -0,0 +1,56 @@
+/*
+ * 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.plugins.document.bundlor;
+
+import javax.annotation.Nonnull;
+
+import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants;
+import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+
+import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
+import static org.apache.jackrabbit.JcrConstants.JCR_SYSTEM;
+import static
org.apache.jackrabbit.oak.plugins.document.bundlor.BundlingConfigHandler.BUNDLOR;
+import static
org.apache.jackrabbit.oak.plugins.document.bundlor.BundlingConfigHandler.DOCUMENT_NODE_STORE;
+
+public enum BundlingConfigInitializer implements RepositoryInitializer {
+ INSTANCE;
+
+ @Override
+ public void initialize(@Nonnull NodeBuilder builder) {
+ if (builder.hasChildNode(JCR_SYSTEM)){
+ NodeBuilder system = builder.getChildNode(JCR_SYSTEM);
+
+ if (!system.hasChildNode(DOCUMENT_NODE_STORE)){
+ NodeBuilder dns = system.child(DOCUMENT_NODE_STORE);
+ dns.setProperty(JCR_PRIMARYTYPE,
NodeTypeConstants.NT_OAK_UNSTRUCTURED, Type.NAME);
+
+ NodeState registryState = BundledTypesRegistry.builder()
+ .forType("nt:file", "jcr:content")
+ .build();
+ NodeBuilder bundlor = dns.setChildNode(BUNDLOR, registryState);
+ bundlor.setProperty(JCR_PRIMARYTYPE,
NodeTypeConstants.NT_OAK_UNSTRUCTURED, Type.NAME);
+ }
+ }
+
+ }
+}
Propchange:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingConfigInitializer.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingConfigInitializerTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingConfigInitializerTest.java?rev=1765644&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingConfigInitializerTest.java
(added)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingConfigInitializerTest.java
Wed Oct 19 15:11:28 2016
@@ -0,0 +1,69 @@
+/*
+ * 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.plugins.document.bundlor;
+
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.spi.state.NodeStateUtils;
+import org.junit.Test;
+
+import static org.apache.jackrabbit.JcrConstants.JCR_SYSTEM;
+import static
org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
+import static
org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent.INITIAL_CONTENT;
+import static org.junit.Assert.*;
+
+public class BundlingConfigInitializerTest {
+ private NodeState root = INITIAL_CONTENT;
+
+ @Test
+ public void bootstrapDefault() throws Exception{
+ NodeBuilder builder = root.builder();
+ BundlingConfigInitializer.INSTANCE.initialize(builder);
+
+ NodeState state = builder.getNodeState();
+ NodeState bundlor = NodeStateUtils.getNode(state,
BundlingConfigHandler.CONFIG_PATH);
+ assertTrue(bundlor.exists());
+ assertTrue(bundlor.getChildNode("nt:file").exists());
+ }
+
+ @Test
+ public void noInitWhenJcrSystemNotPresent() throws Exception{
+ NodeBuilder builder = EMPTY_NODE.builder();
+ BundlingConfigInitializer.INSTANCE.initialize(builder);
+
+ NodeState state = builder.getNodeState();
+ NodeState bundlor = NodeStateUtils.getNode(state,
BundlingConfigHandler.CONFIG_PATH);
+ assertFalse(bundlor.exists());
+ }
+
+ @Test
+ public void noInitIfPartialExists() throws Exception{
+ NodeBuilder builder = root.builder();
+
builder.child(JCR_SYSTEM).child(BundlingConfigHandler.DOCUMENT_NODE_STORE);
+
+ BundlingConfigInitializer.INSTANCE.initialize(builder);
+ NodeState state = builder.getNodeState();
+ NodeState bundlor = NodeStateUtils.getNode(state,
BundlingConfigHandler.CONFIG_PATH);
+ ///jcr:system/documentstore was already present then
+ //no initialization should have happened
+ assertFalse(bundlor.exists());
+ }
+
+}
\ No newline at end of file
Propchange:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingConfigInitializerTest.java
------------------------------------------------------------------------------
svn:eol-style = native