private NodeData initJcrSystemNode(NodeData root) throws RepositoryException
{
boolean addACL = !accessControlType.equals(AccessControlPolicy.DISABLE);
PlainChangesLog changesLog = new PlainChangesLogImpl();
TransientNodeData jcrSystem;
if (addACL)
{
InternalQName[] mixins = new InternalQName[]{Constants.EXO_OWNEABLE, Constants.EXO_PRIVILEGEABLE};
jcrSystem =
TransientNodeData.createNodeData(root, Constants.JCR_SYSTEM, Constants.NT_UNSTRUCTURED, mixins,
Constants.SYSTEM_UUID);
AccessControlList acl = jcrSystem.getACL();
TransientPropertyData primaryType =
TransientPropertyData.createPropertyData(jcrSystem, Constants.JCR_PRIMARYTYPE, PropertyType.NAME, false,
new TransientValueData(jcrSystem.getPrimaryTypeName()));
changesLog.add(ItemState.createAddedState(jcrSystem)).add(ItemState.createAddedState(primaryType));
// jcr:mixinTypes
List<ValueData> mixValues = new ArrayList<ValueData>();
for (InternalQName mixin : mixins)
{
mixValues.add(new TransientValueData(mixin));
}
TransientPropertyData exoMixinTypes =
TransientPropertyData.createPropertyData(jcrSystem, Constants.JCR_MIXINTYPES, PropertyType.NAME, true,
mixValues);
TransientPropertyData exoOwner =
TransientPropertyData.createPropertyData(jcrSystem, Constants.EXO_OWNER, PropertyType.STRING, false,
new TransientValueData(acl.getOwner()));
List<ValueData> permsValues = new ArrayList<ValueData>();
for (int i = 0; i < acl.getPermissionEntries().size(); i++)
{
AccessControlEntry entry = acl.getPermissionEntries().get(i);
permsValues.add(new TransientValueData(entry));
}
TransientPropertyData exoPerms =
TransientPropertyData.createPropertyData(jcrSystem, Constants.EXO_PERMISSIONS,
ExtendedPropertyType.PERMISSION, true, permsValues);
changesLog.add(ItemState.createAddedState(exoMixinTypes)).add(ItemState.createAddedState(exoOwner)).add(
ItemState.createAddedState(exoPerms));
changesLog.add(new ItemState(jcrSystem, ItemState.MIXIN_CHANGED, false, null));
}
else
{
jcrSystem =
TransientNodeData.createNodeData(root, Constants.JCR_SYSTEM, Constants.NT_UNSTRUCTURED,
Constants.SYSTEM_UUID);
TransientPropertyData primaryType =
TransientPropertyData.createPropertyData(jcrSystem, Constants.JCR_PRIMARYTYPE, PropertyType.NAME, false,
new TransientValueData(jcrSystem.getPrimaryTypeName()));
changesLog.add(ItemState.createAddedState(jcrSystem)).add(ItemState.createAddedState(primaryType));
}
// init version storage
AccessControlList acl = new AccessControlList();
acl.removePermissions(SystemIdentity.ANY);
acl.addPermissions(SystemIdentity.ANY, new String[]{PermissionType.READ});
for (AccessControlEntry entry : jcrSystem.getACL().getPermissionEntries())
{
String identity = entry.getIdentity();
String permission = entry.getPermission();
if (!identity.equals(SystemIdentity.ANY) || !permission.equals(PermissionType.READ))
{
acl.addPermissions(identity, new String[]{permission});
}
}
TransientNodeData versionStorageNodeData =
TransientNodeData.createNodeData(jcrSystem, Constants.JCR_VERSIONSTORAGE, Constants.EXO_VERSIONSTORAGE,
Constants.VERSIONSTORAGE_UUID, acl);
TransientPropertyData vsPrimaryType =
TransientPropertyData.createPropertyData(versionStorageNodeData, Constants.JCR_PRIMARYTYPE, PropertyType.NAME,
false, new TransientValueData(versionStorageNodeData.getPrimaryTypeName()));
TransientPropertyData exoMixinTypes =
TransientPropertyData.createPropertyData(versionStorageNodeData, Constants.JCR_MIXINTYPES, PropertyType.NAME,
true, new TransientValueData(Constants.EXO_PRIVILEGEABLE));
List<ValueData> permsValues = new ArrayList<ValueData>();
for (int i = 0; i < acl.getPermissionEntries().size(); i++)
{
AccessControlEntry entry = acl.getPermissionEntries().get(i);
permsValues.add(new TransientValueData(entry));
}
TransientPropertyData exoPerms =
TransientPropertyData.createPropertyData(versionStorageNodeData, Constants.EXO_PERMISSIONS,
ExtendedPropertyType.PERMISSION, true, permsValues);
changesLog.add(ItemState.createAddedState(versionStorageNodeData));
changesLog.add(ItemState.createAddedState(vsPrimaryType));
changesLog.add(ItemState.createAddedState(exoMixinTypes));
changesLog.add(ItemState.createAddedState(exoPerms));
changesLog.add(new ItemState(versionStorageNodeData, ItemState.MIXIN_CHANGED, false, null));
dataManager.save(new TransactionChangesLog(changesLog));
return jcrSystem;
}