/** * 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); } } }
/** * Register the node type definitions contained in the specified {@code input} * using the given {@link Root}. * * @param root The {@code Root} to register the node types. * @param input The input stream containing the node type defintions to be registered. * @param systemId An informative id of the given input. */ public static void register(Root root, InputStream input, String systemId) { new NodeTypeRegistry(root).registerNodeTypes(input, systemId); }
/** * 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); } } }
/** * Register the node type definitions contained in the specified {@code input} * using the given {@link Root}. * * @param root The {@code Root} to register the node types. * @param input The input stream containing the node type defintions to be registered. * @param systemId An informative id of the given input. */ public static void register(Root root, InputStream input, String systemId) { new NodeTypeRegistry(root).registerNodeTypes(input, systemId); }
/** * 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); } } }
/** * Register the node type definitions contained in the specified {@code input} * using the given {@link Root}. * * @param root The {@code Root} to register the node types. * @param input The input stream containing the node type defintions to be registered. * @param systemId An informative id of the given input. */ public static void register(Root root, InputStream input, String systemId) { new NodeTypeRegistry(root).registerNodeTypes(input, systemId); }
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 queryAugmentorMismatchedNodeType() throws Exception { NodeTypeRegistry.register(root, IOUtils.toInputStream(TestUtil.TEST_NODE_TYPE), "test nodeType"); Tree props = createIndex(TestUtil.NT_TEST); TestUtil.enableForFullText(props, "foo1", false);
NodeTypeRegistry.register(root, IOUtils.toInputStream(TestUtil.TEST_NODE_TYPE), "test nodeType"); Tree props = createIndex(TestUtil.NT_TEST); TestUtil.enableForFullText(props, propName);
@Test public void fulltextIndexUsingAugmentors() throws Exception { NodeTypeRegistry.register(root, IOUtils.toInputStream(TestUtil.TEST_NODE_TYPE), "test nodeType"); Tree props = createIndex(TestUtil.NT_TEST); TestUtil.enableForFullText(props, "foo1");
@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 propertyIndexUsingAugmentors() 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 indexAugmentorMismatchedNodeType() throws Exception { NodeTypeRegistry.register(root, IOUtils.toInputStream(TestUtil.TEST_NODE_TYPE), "test nodeType"); Tree props = createIndex(TestUtil.NT_TEST); TestUtil.enableForFullText(props, "foo1");
@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);