/** * Registers built in node types using the given {@link Root}. * * @param root the {@link Root} instance. */ private static void registerBuiltIn(final Root root) { try { InputStream stream = InitialContent.class.getResourceAsStream("builtin_nodetypes.cnd"); try { NodeTypeRegistry.register(root, stream, "built-in node types"); } finally { stream.close(); } } catch (IOException e) { throw new IllegalStateException("Unable to read built-in node types", e); } } }
/** * Registers built in node types using the given {@link Root}. * * @param root the {@link Root} instance. */ private static void registerBuiltIn(final Root root) { try { InputStream stream = InitialContent.class.getResourceAsStream("builtin_nodetypes.cnd"); try { NodeTypeRegistry.register(root, stream, "built-in node types"); } finally { stream.close(); } } catch (IOException e) { throw new IllegalStateException("Unable to read built-in node types", e); } } }
/** * Registers built in node types using the given {@link Root}. * * @param root the {@link Root} instance. */ private static void registerBuiltIn(final Root root) { try { InputStream stream = InitialContent.class.getResourceAsStream("builtin_nodetypes.cnd"); try { NodeTypeRegistry.register(root, stream, "built-in node types"); } finally { stream.close(); } } catch (IOException e) { throw new IllegalStateException("Unable to read built-in node types", e); } } }
static boolean registerCugNodeTypes(@NotNull final Root root) { try { ReadOnlyNodeTypeManager ntMgr = new ReadOnlyNodeTypeManager() { @Override protected Tree getTypes() { return root.getTree(NodeTypeConstants.NODE_TYPES_PATH); } }; if (!ntMgr.hasNodeType(NT_REP_CUG_POLICY)) { try (InputStream stream = CugConfiguration.class.getResourceAsStream("cug_nodetypes.cnd")) { NodeTypeRegistry.register(root, stream, "cug node types"); return true; } } } catch (IOException | RepositoryException e) { throw new IllegalStateException("Unable to read cug node types", e); } return false; } }
static boolean registerCugNodeTypes(@NotNull final Root root) { try { ReadOnlyNodeTypeManager ntMgr = new ReadOnlyNodeTypeManager() { @Override protected Tree getTypes() { return root.getTree(NodeTypeConstants.NODE_TYPES_PATH); } }; if (!ntMgr.hasNodeType(NT_REP_CUG_POLICY)) { try (InputStream stream = CugConfiguration.class.getResourceAsStream("cug_nodetypes.cnd")) { NodeTypeRegistry.register(root, stream, "cug node types"); return true; } } } catch (IOException | RepositoryException e) { throw new IllegalStateException("Unable to read cug node types", e); } return false; } }
static void registerNodeType(@NotNull Root root, @NotNull 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(); } } }
private void registerTestNodeTypes() throws IOException, CommitFailedException { optionalEditorProvider.delegate = new TypeEditorProvider(); NodeTypeRegistry.register(root, IOUtils.toInputStream(testNodeTypes, "utf-8"), "test nodeType"); // Flush the changes to nodetypes root.commit(); }
@NotNull @Override public RepositoryInitializer getRepositoryInitializer() { String cnd = "<rep='internal'>\n" + "["+MIX_REP_THREE_ROLES_POLICY+"] \n mixin\n " + " +"+REP_3_ROLES_POLICY+" ("+NT_REP_THREE_ROLES_POLICY+") protected IGNORE\n\n" + "["+NT_REP_THREE_ROLES_POLICY+"] > "+ AccessControlConstants.NT_REP_POLICY+"\n" + " - "+REP_READERS +" (STRING) multiple protected IGNORE\n" + " - "+REP_EDITORS+" (STRING) multiple protected IGNORE\n" + " - "+REP_OWNERS+" (STRING) multiple protected IGNORE"; System.out.println(cnd); return builder -> { NodeState base = builder.getNodeState(); NodeStore store = new MemoryNodeStore(base); Root root = getRootProvider().createSystemRoot(store, new EditorHook(new CompositeEditorProvider(new NamespaceEditorProvider(), new TypeEditorProvider()))); try { if (!ReadOnlyNodeTypeManager.getInstance(root, NamePathMapper.DEFAULT).hasNodeType(MIX_REP_THREE_ROLES_POLICY)) { NodeTypeRegistry.register(root, new ByteArrayInputStream(cnd.getBytes()), "oak exercise"); NodeState target = store.getRoot(); target.compareAgainstBaseState(base, new ApplyDiff(builder)); } } catch (RepositoryException e) { log.error(e.getMessage()); } }; }
@Test public void queryHook() throws Exception { NodeTypeRegistry.register(root, IOUtils.toInputStream(TestUtil.TEST_NODE_TYPE), "test nodeType"); Tree props = createIndex(TestUtil.NT_TEST); TestUtil.enableForFullText(props, "foo");
@Test public void newNodeTypesFoundLater() throws Exception{ String idxName = "hybridtest"; Tree idx = createIndex(root.getTree("/"), idxName, ImmutableSet.of("foo", "bar")); TestUtil.enableIndexingMode(idx, FulltextIndexConstants.IndexingMode.SYNC); root.commit(); setTraversalEnabled(false); createPath("/a").setProperty("foo", "bar"); root.commit(); assertQuery("select [jcr:path] from [nt:base] where [foo] = 'bar'", of("/a")); optionalEditorProvider.delegate = new TypeEditorProvider(false); NodeTypeRegistry.register(root, IOUtils.toInputStream(TestUtil.TEST_NODE_TYPE), "test nodeType"); root.refresh(); Tree b = createPath("/b"); b.setProperty(JcrConstants.JCR_PRIMARYTYPE, "oak:TestNode", Type.NAME); b.setProperty("bar", "foo"); root.commit(); assertQuery("select [jcr:path] from [nt:base] where [bar] = 'foo'", of("/b")); }
@Override public void initialize(@NotNull NodeBuilder builder) { super.initialize(builder); // registering additional node types for wider testing InputStream stream = null; try { stream = LuceneIndexAggregation2Test.class .getResourceAsStream("test_nodetypes.cnd"); NodeState base = builder.getNodeState(); NodeStore store = new MemoryNodeStore(base); Root root = RootFactory.createSystemRoot(store, new EditorHook( new CompositeEditorProvider(new NamespaceEditorProvider(), new TypeEditorProvider())), null, null, null); NodeTypeRegistry.register(root, stream, "testing node types"); NodeState target = store.getRoot(); target.compareAgainstBaseState(base, new ApplyDiff(builder)); } catch (Exception e) { LOG.error("Error while registering required node types. Failing here", e); fail("Error while registering required node types"); } finally { printNodeTypes(builder); if (stream != null) { try { stream.close(); } catch (IOException e) { LOG.debug("Ignoring exception on stream closing.", e); } } } }
@Test public void indexHookCallbackFrequency() throws Exception { NodeTypeRegistry.register(root, IOUtils.toInputStream(TestUtil.TEST_NODE_TYPE), "test nodeType"); Tree props = createIndex(TestUtil.NT_TEST); TestUtil.enablePropertyIndex(props, "foo1", false);
@Test public void aggregateAndIncludeRelativePropertyByDefault() throws Exception{ NodeTypeRegistry.register(root, IOUtils.toInputStream(TestUtil.TEST_NODE_TYPE), "test nodeType"); Tree idx = createIndex("test1", of("propa", "propb")); Tree props = TestUtil.newRulePropTree(idx, TestUtil.NT_TEST); Tree prop = props.addChild(TestUtil.unique("prop")); prop.setProperty(FulltextIndexConstants.PROP_NAME, "jcr:title"); prop.setProperty(FulltextIndexConstants.PROP_PROPERTY_INDEX, true); Tree prop1 = props.addChild(TestUtil.unique("prop")); prop1.setProperty(FulltextIndexConstants.PROP_NAME, "original/jcr:content/type"); prop1.setProperty(FulltextIndexConstants.PROP_PROPERTY_INDEX, true); newNodeAggregator(idx) .newRuleWithName(NT_FILE, newArrayList(JCR_CONTENT, JCR_CONTENT + "/*")) .newRuleWithName(TestUtil.NT_TEST, newArrayList("/*")); root.commit(); Tree test = root.getTree("/").addChild("test"); Tree a = createNodeWithType(test, "a", TestUtil.NT_TEST); Tree af = createFileNode(a, "original", "hello", "text/plain"); af.setProperty("type", "jpg"); af.setProperty("class", "image"); //Should be included root.commit(); // hello and image would be index by aggregation but // jpg should also be included as it has not been excluded assertQuery("select [jcr:path] from [oak:TestNode] where contains(*, 'hello')", asList("/test/a")); assertQuery("select [jcr:path] from [oak:TestNode] where contains(*, 'image')", asList("/test/a")); assertQuery("select [jcr:path] from [oak:TestNode] where contains(*, 'jpg')", asList("/test/a")); //Check that property index is being used assertThat(explain("select [jcr:path] from [oak:TestNode] where [original/jcr:content/type] = 'foo'"), containsString("original/jcr:content/type:foo")); }
@Test public void propertyNonExistenceQuery() throws Exception { NodeTypeRegistry.register(root, IOUtils.toInputStream(TestUtil.TEST_NODE_TYPE), "test nodeType"); Tree idx = createIndex("test1", of("propa", "propb")); Tree props = TestUtil.newRulePropTree(idx, TestUtil.NT_TEST); Tree prop = props.addChild(TestUtil.unique("prop")); prop.setProperty(PROP_NAME, "propa"); prop.setProperty(PROP_PROPERTY_INDEX, true); prop.setProperty(LuceneIndexConstants.PROP_NULL_CHECK_ENABLED, true); root.commit(); Tree test = root.getTree("/").addChild("test"); createNodeWithType(test, "a", "oak:TestNode").setProperty("propa", "a"); createNodeWithType(test, "b", "oak:TestNode").setProperty("propa", "c"); createNodeWithType(test, "c", "oak:TestNode").setProperty("propb", "e"); root.commit(); String propabQuery = "select [jcr:path] from [oak:TestNode] where [propa] is null"; assertThat(explain(propabQuery), containsString("lucene:test1(/oak:index/test1) :nullProps:propa")); assertQuery(propabQuery, asList("/test/c")); }
@Test public void propertyExistenceQuery2() throws Exception { NodeTypeRegistry.register(root, IOUtils.toInputStream(TestUtil.TEST_NODE_TYPE), "test nodeType"); Tree idx = createIndex("test1", of("propa", "propb")); Tree props = TestUtil.newRulePropTree(idx, TestUtil.NT_TEST); Tree prop = props.addChild(TestUtil.unique("prop")); prop.setProperty(PROP_NAME, "propa"); prop.setProperty(PROP_PROPERTY_INDEX, true); prop.setProperty(LuceneIndexConstants.PROP_NOT_NULL_CHECK_ENABLED, true); root.commit(); Tree test = root.getTree("/").addChild("test"); createNodeWithType(test, "a", "oak:TestNode").setProperty("propa", "a"); createNodeWithType(test, "b", "oak:TestNode").setProperty("propa", "c"); createNodeWithType(test, "c", "oak:TestNode").setProperty("propb", "e"); root.commit(); String propabQuery = "select [jcr:path] from [oak:TestNode] where [propa] is not null"; assertThat(explain(propabQuery), containsString("lucene:test1(/oak:index/test1) :notNullProps:propa")); assertQuery(propabQuery, asList("/test/a", "/test/b")); }
@Test public void aggregationAndExcludeProperty() throws Exception { NodeTypeRegistry.register(root, IOUtils.toInputStream(TestUtil.TEST_NODE_TYPE), "test nodeType"); Tree idx = createIndex("test1", of("propa", "propb")); Tree props = TestUtil.newRulePropTree(idx, TestUtil.NT_TEST);
public static void registerNodeType(NodeBuilder builder, String nodeTypeDefn) { // Taken from // org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent NodeState base = ModifiedNodeState.squeeze(builder.getNodeState()); NodeStore store = new MemoryNodeStore(base); Root root = RootFactory.createSystemRoot(store, new EditorHook(new CompositeEditorProvider(new NamespaceEditorProvider(), new TypeEditorProvider())), null, null, null); NodeTypeRegistry.register(root, IOUtils.toInputStream(nodeTypeDefn), "test node types"); NodeState target = store.getRoot(); target.compareAgainstBaseState(base, new ApplyDiff(builder)); }
public static void registerNodeType(NodeBuilder builder, String nodeTypeDefn){ //Taken from org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent NodeState base = ModifiedNodeState.squeeze(builder.getNodeState()); NodeStore store = new MemoryNodeStore(base); Root root = RootFactory.createSystemRoot( store, new EditorHook(new CompositeEditorProvider( new NamespaceEditorProvider(), new TypeEditorProvider())), null, null, null); NodeTypeRegistry.register(root, IOUtils.toInputStream(nodeTypeDefn), "test node types"); NodeState target = store.getRoot(); target.compareAgainstBaseState(base, new ApplyDiff(builder)); }
" [oak:TestTypeC] > oak:TestMixA\n" + " - * (UNDEFINED) multiple"; NodeTypeRegistry.register(root, IOUtils.toInputStream(testNodeTypes, "utf-8"), "test nodeType");
NodeTypeRegistry.register(root, IOUtils.toInputStream(TestUtil.TEST_NODE_TYPE), "test nodeType"); root.refresh();