@Service(RepositoryInitializer.class)
public class InitialContent implements RepositoryInitializer {
@Override
public void initialize(NodeStore store) {
NodeStoreBranch branch = store.branch();
NodeBuilder root = branch.getRoot().builder();
root.setProperty(JCR_PRIMARYTYPE, "rep:root", Type.NAME);
if (!root.hasChildNode(JCR_SYSTEM)) {
NodeBuilder system = root.child(JCR_SYSTEM);
system.setProperty(JCR_PRIMARYTYPE, "rep:system", Type.NAME);
system.child(JCR_VERSIONSTORAGE)
.setProperty(JCR_PRIMARYTYPE, "rep:versionStorage", Type.NAME);
system.child("jcr:nodeTypes")
.setProperty(JCR_PRIMARYTYPE, "rep:nodeTypes", Type.NAME);
system.child("jcr:activities")
.setProperty(JCR_PRIMARYTYPE, "rep:Activities", Type.NAME);
}
if (!root.hasChildNode("oak:index")) {
NodeBuilder index = root.child("oak:index");
index.setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, Type.NAME); // TODO: use proper node type
index.child("uuid")
.setProperty(JCR_PRIMARYTYPE, "oak:queryIndexDefinition", Type.NAME)
.setProperty("type", "p2")
.setProperty("propertyNames", "jcr:uuid")
.setProperty("reindex", true)
.setProperty("unique", true);
index.child("nodetype")
.setProperty(JCR_PRIMARYTYPE, "oak:queryIndexDefinition", Type.NAME)
.setProperty("type", "p2")
.setProperty("reindex", true)
.setProperty(PropertyStates.createProperty(
"propertyNames",
ImmutableList.of(JCR_PRIMARYTYPE, JCR_MIXINTYPES),
Type.STRINGS));
}
try {
branch.setRoot(root.getNodeState());
branch.merge();
} catch (CommitFailedException e) {
throw new RuntimeException(e); // TODO: shouldn't need the wrapper
}
BuiltInNodeTypes.register(new RootImpl(store));