@NotNull public static EditorProvider compose( @NotNull Collection<? extends EditorProvider> providers) { checkNotNull(providers); switch (providers.size()) { case 0: return EMPTY_PROVIDER; case 1: return providers.iterator().next(); default: return new CompositeEditorProvider(providers); } }
/** * Turns all currently tracked editors to an editor commit hook and * associates that hook with the repository to be created. This way * a sequence of {@code with()} calls that alternates between editors * and other commit hooks will have all the editors in the correct * order while still being able to leverage the performance gains of * multiple editors iterating over the changes simultaneously. */ private void withEditorHook() { if (!editorProviders.isEmpty()) { commitHooks.add(new EditorHook( CompositeEditorProvider.compose(editorProviders))); editorProviders = newArrayList(); } }
@Nonnull public static EditorProvider compose( @Nonnull Collection<? extends EditorProvider> providers) { checkNotNull(providers); switch (providers.size()) { case 0: return EMPTY_PROVIDER; case 1: return providers.iterator().next(); default: return new CompositeEditorProvider(providers); } }
/** * Turns all currently tracked editors to an editor commit hook and * associates that hook with the repository to be created. This way * a sequence of {@code with()} calls that alternates between editors * and other commit hooks will have all the editors in the correct * order while still being able to leverage the performance gains of * multiple editors iterating over the changes simultaneously. */ private void withEditorHook() { if (!editorProviders.isEmpty()) { commitHooks.add(new EditorHook( CompositeEditorProvider.compose(editorProviders))); editorProviders = newArrayList(); } }
@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()); } }; }
/** * Turns all currently tracked editors to an editor commit hook and * associates that hook with the repository to be created. This way * a sequence of {@code with()} calls that alternates between editors * and other commit hooks will have all the editors in the correct * order while still being able to leverage the performance gains of * multiple editors iterating over the changes simultaneously. */ private void withEditorHook() { if (!editorProviders.isEmpty()) { commitHooks.add(new EditorHook( CompositeEditorProvider.compose(editorProviders))); editorProviders = newArrayList(); } }
private void migrateWithoutCheckpoints() throws CommitFailedException, RepositoryException { final List<CommitHook> hooks = new ArrayList<>(); if (customCommitHooks != null) { hooks.addAll(customCommitHooks); } NodeState sourceRoot = wrapNodeState(source.getRoot(), true, false); NodeBuilder targetRoot = target.getRoot().builder(); copyWorkspace(sourceRoot, targetRoot); if (!versionCopyConfiguration.isCopyAll()) { NodeBuilder versionStorage = VersionHistoryUtil.getVersionStorage(targetRoot); if (!versionStorage.exists()) { // it's possible that this is a new repository and the version storage // hasn't been created/copied yet versionStorage = VersionHistoryUtil.createVersionStorage(targetRoot); } if (!versionCopyConfiguration.skipOrphanedVersionsCopy()) { copyVersionStorage(targetRoot, getVersionStorage(sourceRoot), versionStorage, versionCopyConfiguration); } hooks.add(new EditorHook(new VersionableEditor.Provider(sourceRoot, getWorkspaceName(), versionCopyConfiguration))); } // type validation, reference and indexing hooks hooks.add(new EditorHook(new CompositeEditorProvider( createTypeEditorProvider(), createIndexEditorProvider() ))); target.merge(targetRoot, new LoggingCompositeHook(hooks, null, false), CommitInfo.EMPTY); removeVersions(); }
@Override @Nullable public Editor getRootEditor( NodeState before, NodeState after, NodeBuilder builder, CommitInfo info) throws CommitFailedException { EditorProvider provider = CompositeEditorProvider.compose(getServices()); return provider.getRootEditor(before, after, builder, info); }
private void migrateWithoutCheckpoints() throws CommitFailedException, RepositoryException { final List<CommitHook> hooks = new ArrayList<>(); if (customCommitHooks != null) { hooks.addAll(customCommitHooks); } NodeState sourceRoot = wrapNodeState(source.getRoot(), true, false); NodeBuilder targetRoot = target.getRoot().builder(); copyWorkspace(sourceRoot, targetRoot); if (!versionCopyConfiguration.isCopyAll()) { NodeBuilder versionStorage = VersionHistoryUtil.getVersionStorage(targetRoot); if (!versionStorage.exists()) { // it's possible that this is a new repository and the version storage // hasn't been created/copied yet versionStorage = VersionHistoryUtil.createVersionStorage(targetRoot); } if (!versionCopyConfiguration.skipOrphanedVersionsCopy()) { copyVersionStorage(targetRoot, getVersionStorage(sourceRoot), versionStorage, versionCopyConfiguration); } hooks.add(new EditorHook(new VersionableEditor.Provider(sourceRoot, getWorkspaceName(), versionCopyConfiguration))); } // type validation, reference and indexing hooks hooks.add(new EditorHook(new CompositeEditorProvider( createTypeEditorProvider(), createIndexEditorProvider() ))); target.merge(targetRoot, new LoggingCompositeHook(hooks, null, false), CommitInfo.EMPTY); removeVersions(); }
@Override @CheckForNull public Editor getRootEditor( NodeState before, NodeState after, NodeBuilder builder, CommitInfo info) throws CommitFailedException { EditorProvider provider = CompositeEditorProvider.compose(getServices()); return provider.getRootEditor(before, after, builder, info); }
hooks.add(new EditorHook(new CompositeEditorProvider( new RestrictionEditorProvider(), new GroupEditorProvider(groupsPath), hooks.add(new EditorHook(new CompositeEditorProvider( createTypeEditorProvider(), createIndexEditorProvider()
/** * Combine the globally defined commit hook(s) and the hooks and validators defined by the * various security related configurations. * * @return A commit hook combining repository global commit hook(s) with the pluggable hooks * defined with the security modules and the padded {@code hooks}. */ private CommitHook getCommitHook() { List<CommitHook> hooks = newArrayList(); hooks.add(ResetCommitAttributeHook.INSTANCE); hooks.add(hook); List<CommitHook> postValidationHooks = new ArrayList<CommitHook>(); List<ValidatorProvider> validators = new ArrayList<>(); for (SecurityConfiguration sc : securityProvider.getConfigurations()) { for (CommitHook ch : sc.getCommitHooks(workspaceName)) { if (ch instanceof PostValidationHook) { postValidationHooks.add(ch); } else if (ch != EmptyHook.INSTANCE) { hooks.add(ch); } } validators.addAll(sc.getValidators(workspaceName, subject.getPrincipals(), moveTracker)); } if (!validators.isEmpty()) { hooks.add(new EditorHook(CompositeEditorProvider.compose(validators))); } hooks.addAll(postValidationHooks); return CompositeHook.compose(hooks); }
hooks.add(new EditorHook(new CompositeEditorProvider( new RestrictionEditorProvider(), new GroupEditorProvider(groupsPath), hooks.add(new EditorHook(new CompositeEditorProvider( createTypeEditorProvider(), createIndexEditorProvider()
/** * Combine the globally defined commit hook(s) and the hooks and validators defined by the * various security related configurations. * * @return A commit hook combining repository global commit hook(s) with the pluggable hooks * defined with the security modules and the padded {@code hooks}. */ private CommitHook getCommitHook() { List<CommitHook> hooks = newArrayList(); hooks.add(ResetCommitAttributeHook.INSTANCE); hooks.add(hook); List<CommitHook> postValidationHooks = new ArrayList<CommitHook>(); List<ValidatorProvider> validators = new ArrayList<>(); for (SecurityConfiguration sc : securityProvider.getConfigurations()) { for (CommitHook ch : sc.getCommitHooks(workspaceName)) { if (ch instanceof PostValidationHook) { postValidationHooks.add(ch); } else if (ch != EmptyHook.INSTANCE) { hooks.add(ch); } } validators.addAll(sc.getValidators(workspaceName, subject.getPrincipals(), moveTracker)); } if (!validators.isEmpty()) { hooks.add(new EditorHook(CompositeEditorProvider.compose(validators))); } hooks.addAll(postValidationHooks); return CompositeHook.compose(hooks); }
private static NodeState createInitialContent() { NodeStore store = new MemoryNodeStore(); EditorHook hook = new EditorHook( new CompositeEditorProvider(new NamespaceEditorProvider(), new TypeEditorProvider())); OakInitializer.initialize(store, new InitialContent(), hook); return store.getRoot(); }
/** * Combine the globally defined commit hook(s) and the hooks and validators defined by the * various security related configurations. * * @return A commit hook combining repository global commit hook(s) with the pluggable hooks * defined with the security modules and the padded {@code hooks}. */ private CommitHook getCommitHook() { List<CommitHook> hooks = newArrayList(); hooks.add(ResetCommitAttributeHook.INSTANCE); hooks.add(hook); List<CommitHook> postValidationHooks = new ArrayList<CommitHook>(); List<ValidatorProvider> validators = new ArrayList<>(); for (SecurityConfiguration sc : securityProvider.getConfigurations()) { for (CommitHook ch : sc.getCommitHooks(workspaceName)) { if (ch instanceof PostValidationHook) { postValidationHooks.add(ch); } else if (ch != EmptyHook.INSTANCE) { hooks.add(ch); } } validators.addAll(sc.getValidators(workspaceName, subject.getPrincipals(), moveTracker)); } if (!validators.isEmpty()) { hooks.add(new EditorHook(CompositeEditorProvider.compose(validators))); } hooks.addAll(postValidationHooks); return CompositeHook.compose(hooks); }
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)); }
private CompositeHook createCommitHook() { return new CompositeHook( ResetCommitAttributeHook.INSTANCE, new ConflictHook(new AnnotatingConflictHandler()), new EditorHook(CompositeEditorProvider.compose(singletonList(new ConflictValidatorProvider()))) ); }
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)); }
private CompositeHook createCommitHook() { return new CompositeHook( ResetCommitAttributeHook.INSTANCE, new ConflictHook(new AnnotatingConflictHandler()), new EditorHook(CompositeEditorProvider.compose(singletonList(new ConflictValidatorProvider()))) ); }