use of org.alfresco.module.org_alfresco_module_rm.security.Role in project records-management by Alfresco.
the class BootstrapTestDataGet method patchLoadedData.
/**
* Temp method to patch AMP'ed data
*
* @param searchService
* @param nodeService
* @param recordsManagementService
* @param recordsManagementActionService
*/
public static void patchLoadedData(final SearchService searchService, final NodeService nodeService, final RecordsManagementService recordsManagementService, final RecordsManagementActionService recordsManagementActionService, final PermissionService permissionService, final AuthorityService authorityService, final RecordsManagementSecurityService recordsManagementSecurityService, final RecordsManagementSearchBehaviour recordManagementSearchBehaviour, final DispositionService dispositionService, final RecordFolderService recordFolderService) {
AuthenticationUtil.RunAsWork<Object> runAsWork = new AuthenticationUtil.RunAsWork<Object>() {
public Object doWork() {
java.util.List<NodeRef> rmRoots = recordsManagementService.getFilePlans();
logger.info("Bootstraping " + rmRoots.size() + " rm roots ...");
for (NodeRef rmRoot : rmRoots) {
if (permissionService.getInheritParentPermissions(rmRoot)) {
logger.info("Updating permissions for rm root: " + rmRoot);
permissionService.setInheritParentPermissions(rmRoot, false);
}
String allRoleShortName = RMAuthority.ALL_ROLES_PREFIX + rmRoot.getId();
String allRoleGroupName = authorityService.getName(AuthorityType.GROUP, allRoleShortName);
if (!authorityService.authorityExists(allRoleGroupName)) {
logger.info("Creating all roles group for root node: " + rmRoot.toString());
// Create "all" role group for root node
String allRoles = authorityService.createAuthority(AuthorityType.GROUP, allRoleShortName, RMAuthority.ALL_ROLES_DISPLAY_NAME, new HashSet<String>(Arrays.asList(RMAuthority.ZONE_APP_RM)));
// Put all the role groups in it
Set<Role> roles = recordsManagementSecurityService.getRoles(rmRoot);
for (Role role : roles) {
logger.info(" - adding role group " + role.getRoleGroupName() + " to all roles group");
authorityService.addAuthority(allRoles, role.getRoleGroupName());
}
// Set the permissions
permissionService.setPermission(rmRoot, allRoles, RMPermissionModel.READ_RECORDS, true);
}
}
// Make sure all the containers do not inherit permissions
ResultSet rs = searchService.query(SPACES_STORE, SearchService.LANGUAGE_FTS_ALFRESCO, "TYPE:\"rma:recordsManagementContainer\"");
try {
logger.info("Bootstraping " + rs.length() + " record containers ...");
for (NodeRef container : rs.getNodeRefs()) {
String containerName = (String) nodeService.getProperty(container, ContentModel.PROP_NAME);
// Set permissions
if (permissionService.getInheritParentPermissions(container)) {
logger.info("Updating permissions for record container: " + containerName);
permissionService.setInheritParentPermissions(container, false);
}
}
} finally {
rs.close();
}
// fix up the test dataset to fire initial events for disposition schedules
rs = searchService.query(SPACES_STORE, SearchService.LANGUAGE_FTS_ALFRESCO, "TYPE:\"rma:recordFolder\"");
try {
logger.info("Bootstraping " + rs.length() + " record folders ...");
for (NodeRef recordFolder : rs.getNodeRefs()) {
String folderName = (String) nodeService.getProperty(recordFolder, ContentModel.PROP_NAME);
// Set permissions
if (permissionService.getInheritParentPermissions(recordFolder)) {
logger.info("Updating permissions for record folder: " + folderName);
permissionService.setInheritParentPermissions(recordFolder, false);
}
if (!nodeService.hasAspect(recordFolder, ASPECT_DISPOSITION_LIFECYCLE)) {
// See if the folder has a disposition schedule that needs to be applied
DispositionSchedule ds = dispositionService.getDispositionSchedule(recordFolder);
if (ds != null) {
// Fire action to "set-up" the folder correctly
logger.info("Setting up bootstraped record folder: " + folderName);
recordFolderService.setupRecordFolder(recordFolder);
}
}
// fixup the search behaviour aspect for the record folder
logger.info("Setting up search aspect for record folder: " + folderName);
recordManagementSearchBehaviour.fixupSearchAspect(recordFolder);
}
} finally {
rs.close();
}
return null;
}
};
AuthenticationUtil.runAs(runAsWork, AuthenticationUtil.getAdminUserName());
}
Aggregations