Author: davide
Date: Thu Mar 17 16:44:51 2016
New Revision: 1735455

URL: http://svn.apache.org/viewvc?rev=1735455&view=rev
Log:
OAK-3725 - Add oak:Indexable mixin type

- added the mixin
- covered the case with test

Added:
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/nodetype/write/NodeTypeRegistryTest.java
    
jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/plugins/
    
jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/plugins/nodetype/
    
jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/
    
jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/oak3725-1.cnd
      - copied, changed from r1735405, 
jackrabbit/oak/trunk/oak-core/src/main/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/builtin_nodetypes.cnd
    
jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/oak3725-2.cnd
      - copied, changed from r1735405, 
jackrabbit/oak/trunk/oak-core/src/main/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/builtin_nodetypes.cnd
Modified:
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeConstants.java
    
jackrabbit/oak/trunk/oak-core/src/main/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/builtin_nodetypes.cnd

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeConstants.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeConstants.java?rev=1735455&r1=1735454&r2=1735455&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeConstants.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeConstants.java
 Thu Mar 17 16:44:51 2016
@@ -95,4 +95,10 @@ public interface NodeTypeConstants exten
      * mixin to enable the AtomicCounterEditor.
      */
     String MIX_ATOMIC_COUNTER = "mix:atomicCounter";
+    
+    /**
+     * adding such mixin will allow the {@link JcrConstants#NT_UNSTRUCTURED} 
type under restricting
+     * nodes such {@link JcrConstants#NT_FOLDER}
+     */
+    String MIX_INDEXABLE = "mix:indexable";
 }

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/builtin_nodetypes.cnd
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/builtin_nodetypes.cnd?rev=1735455&r1=1735454&r2=1735455&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/builtin_nodetypes.cnd
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/builtin_nodetypes.cnd
 Thu Mar 17 16:44:51 2016
@@ -253,6 +253,13 @@
   mixin
   - oak:counter (LONG) = '0' protected autocreated
 
+/**
+ * allows restricting node types such as NT_FOLDER to have NT_UNSTRUCTURED. 
Required for oak:index
+ */
+[mix:indexable]
+  mixin
+  + oak:index (nt:base) = nt:unstructured COPY
+
 
//------------------------------------------------------------------------------
 // U N S T R U C T U R E D   C O N T E N T
 
//------------------------------------------------------------------------------

Added: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/nodetype/write/NodeTypeRegistryTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/nodetype/write/NodeTypeRegistryTest.java?rev=1735455&view=auto
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/nodetype/write/NodeTypeRegistryTest.java
 (added)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/nodetype/write/NodeTypeRegistryTest.java
 Thu Mar 17 16:44:51 2016
@@ -0,0 +1,116 @@
+/*
+ * 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.nodetype.write;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.collect.ImmutableList.of;
+import static org.apache.jackrabbit.JcrConstants.JCR_MIXINTYPES;
+import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
+import static org.apache.jackrabbit.JcrConstants.NT_FOLDER;
+import static org.apache.jackrabbit.JcrConstants.NT_UNSTRUCTURED;
+import static org.apache.jackrabbit.oak.api.Type.NAME;
+import static 
org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.MIX_INDEXABLE;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.annotation.Nonnull;
+import javax.jcr.NoSuchWorkspaceException;
+import javax.security.auth.login.LoginException;
+
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.jackrabbit.oak.Oak;
+import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.api.ContentRepository;
+import org.apache.jackrabbit.oak.api.ContentSession;
+import org.apache.jackrabbit.oak.api.Root;
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants;
+import org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider;
+import org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.base.Strings;
+import com.google.common.collect.ImmutableList;
+
+public class NodeTypeRegistryTest {
+    private ContentRepository repository = null;
+    private Root root;
+    private ContentSession session = null;
+    
+    static void registerNodeType(@Nonnull Root root, @Nonnull String 
resourceName) throws IOException {
+        checkArgument(!Strings.isNullOrEmpty(resourceName));
+        checkNotNull(root);
+
+        InputStream stream = null;
+
+        try {
+            stream = 
NodeTypeRegistryTest.class.getResourceAsStream(resourceName);
+            NodeTypeRegistry.register(root, stream, 
NodeTypeRegistryTest.class.getName());            
+        } finally {
+            if (stream != null) {
+                stream.close();
+            }
+            
+        }
+    }
+    
+    @Before
+    public void setUp() throws LoginException, NoSuchWorkspaceException {
+        repository = new Oak().with(new InitialContent()).with(new 
OpenSecurityProvider())
+            .with(new TypeEditorProvider()).createContentRepository();
+        session = repository.login(null, null);
+        root = session.getLatestRoot();
+    }
+    
+    @After
+    public void tearDown() throws IOException {
+        if (session != null) {
+            session.close();
+        }
+        if (repository instanceof Closeable) {
+            ((Closeable) repository).close();
+        }
+        repository = null;
+    }
+    
+    @Test(expected = CommitFailedException.class)
+    public void oakIndexableFailing() throws IOException, 
CommitFailedException {
+        registerNodeType(root, "oak3725-1.cnd");
+        
+        Tree test = root.getTree("/").addChild("test");
+        test.setProperty(JCR_PRIMARYTYPE, NT_FOLDER, NAME);            
+        test.addChild("oak:index").setProperty(JCR_PRIMARYTYPE, 
NT_UNSTRUCTURED, NAME);
+        root.commit();
+    }
+    
+    @Test
+    public void oakIndexableSuccessful() throws IOException, 
CommitFailedException {
+        registerNodeType(root, "oak3725-2.cnd");
+        
+        Tree test = root.getTree("/").addChild("test");
+        test.setProperty(JCR_PRIMARYTYPE, NT_FOLDER, NAME);
+        test.setProperty(JCR_MIXINTYPES, of(MIX_INDEXABLE), Type.NAMES);
+        test.addChild("oak:index").setProperty(JCR_PRIMARYTYPE, 
NT_UNSTRUCTURED, NAME);
+        root.commit();
+    }
+}

Copied: 
jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/oak3725-1.cnd
 (from r1735405, 
jackrabbit/oak/trunk/oak-core/src/main/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/builtin_nodetypes.cnd)
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/oak3725-1.cnd?p2=jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/oak3725-1.cnd&p1=jackrabbit/oak/trunk/oak-core/src/main/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/builtin_nodetypes.cnd&r1=1735405&r2=1735455&rev=1735455&view=diff
==============================================================================
    (empty)

Copied: 
jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/oak3725-2.cnd
 (from r1735405, 
jackrabbit/oak/trunk/oak-core/src/main/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/builtin_nodetypes.cnd)
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/oak3725-2.cnd?p2=jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/oak3725-2.cnd&p1=jackrabbit/oak/trunk/oak-core/src/main/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/builtin_nodetypes.cnd&r1=1735405&r2=1735455&rev=1735455&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/builtin_nodetypes.cnd
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/oak3725-2.cnd
 Thu Mar 17 16:44:51 2016
@@ -252,6 +252,10 @@
 [mix:atomicCounter]
   mixin
   - oak:counter (LONG) = '0' protected autocreated
+  
+[mix:indexable]
+  mixin
+  + oak:index (nt:base) = nt:unstructured COPY
 
 
//------------------------------------------------------------------------------
 // U N S T R U C T U R E D   C O N T E N T


Reply via email to