Search in sources :

Example 11 with ApplyDiff

use of org.apache.jackrabbit.oak.spi.state.ApplyDiff in project jackrabbit-oak by apache.

the class PrivilegeInitializer method initialize.

@Override
public void initialize(@Nonnull NodeBuilder builder) {
    NodeBuilder system = builder.child(JcrConstants.JCR_SYSTEM);
    system.setProperty(JcrConstants.JCR_PRIMARYTYPE, NodeTypeConstants.NT_REP_SYSTEM, Type.NAME);
    if (!system.hasChildNode(REP_PRIVILEGES)) {
        NodeBuilder privileges = system.child(REP_PRIVILEGES);
        privileges.setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_REP_PRIVILEGES, Type.NAME);
        // squeeze node state before it is passed to store (OAK-2411)
        NodeState base = squeeze(builder.getNodeState());
        NodeStore store = new MemoryNodeStore(base);
        try {
            Root systemRoot = rootProvider.createSystemRoot(store, null);
            new PrivilegeDefinitionWriter(systemRoot).writeBuiltInDefinitions();
        } catch (RepositoryException e) {
            log.error("Failed to register built-in privileges", e);
            throw new RuntimeException(e);
        }
        NodeState target = store.getRoot();
        target.compareAgainstBaseState(base, new ApplyDiff(builder));
    }
}
Also used : ApplyDiff(org.apache.jackrabbit.oak.spi.state.ApplyDiff) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) Root(org.apache.jackrabbit.oak.api.Root) RepositoryException(javax.jcr.RepositoryException) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Aggregations

ApplyDiff (org.apache.jackrabbit.oak.spi.state.ApplyDiff)11 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)10 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)7 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)6 Root (org.apache.jackrabbit.oak.api.Root)5 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)5 NamespaceEditorProvider (org.apache.jackrabbit.oak.plugins.name.NamespaceEditorProvider)4 TypeEditorProvider (org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider)4 CompositeEditorProvider (org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider)4 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)4 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Nonnull (javax.annotation.Nonnull)2 RepositoryException (javax.jcr.RepositoryException)2 InitialContent (org.apache.jackrabbit.oak.InitialContent)2 Oak (org.apache.jackrabbit.oak.Oak)2 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)2 FilteringNodeState (org.apache.jackrabbit.oak.plugins.migration.FilteringNodeState)2 ReportingNodeState (org.apache.jackrabbit.oak.plugins.migration.report.ReportingNodeState)2 OpenSecurityProvider (org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider)2