Search in sources :

Example 1 with SiteServiceImpl

use of org.alfresco.repo.site.SiteServiceImpl in project alfresco-repository by Alfresco.

the class RenameSiteAuthorityDisplayName method renameDispayNames.

/**
 * Rename display names of authorities of sites.
 *
 * @param siteInfos
 *            list of sites
 */
private void renameDispayNames(final List<SiteInfo> siteInfos) {
    final String tenantDomain = tenantAdminService.getCurrentUserDomain();
    final Iterator<SiteInfo> pathItr = siteInfos.listIterator();
    BatchProcessWorkProvider<SiteInfo> siteWorkProvider = new BatchProcessWorkProvider<SiteInfo>() {

        @Override
        public int getTotalEstimatedWorkSize() {
            return siteInfos.size();
        }

        @Override
        public Collection<SiteInfo> getNextWork() {
            int batchCount = 0;
            List<SiteInfo> nodes = new ArrayList<SiteInfo>(BATCH_SIZE);
            while (pathItr.hasNext() && batchCount++ != BATCH_SIZE) {
                nodes.add(pathItr.next());
            }
            return nodes;
        }
    };
    // prepare the batch processor and worker object
    BatchProcessor<SiteInfo> siteBatchProcessor = new BatchProcessor<SiteInfo>("RenameSiteAuthorityDisplayName", this.transactionHelper, siteWorkProvider, BATCH_THREADS, BATCH_SIZE, this.applicationEventPublisher, progress_logger, BATCH_SIZE * 10);
    BatchProcessWorker<SiteInfo> worker = new BatchProcessWorker<SiteInfo>() {

        @Override
        public String getIdentifier(SiteInfo entry) {
            return entry.getShortName();
        }

        @Override
        public void beforeProcess() throws Throwable {
            // Disable rules
            ruleService.disableRules();
            // Authentication
            String systemUser = AuthenticationUtil.getSystemUserName();
            systemUser = tenantAdminService.getDomainUser(systemUser, tenantDomain);
            AuthenticationUtil.setRunAsUser(systemUser);
        }

        @Override
        public void afterProcess() throws Throwable {
            // Enable rules
            ruleService.enableRules();
            // Clear authentication
            AuthenticationUtil.clearCurrentSecurityContext();
        }

        @Override
        public void process(SiteInfo siteInfo) throws Throwable {
            // Set all the permissions of site
            Set<AccessPermission> sitePermissions = permissionService.getAllSetPermissions(siteInfo.getNodeRef());
            for (AccessPermission sitePermission : sitePermissions) {
                // Use only GROUP authority
                if (sitePermission.getAuthorityType() == AuthorityType.GROUP) {
                    String authorityName = sitePermission.getAuthority();
                    String currDisplayName = authorityService.getAuthorityDisplayName(authorityName);
                    String necessaryName = ((SiteServiceImpl) siteService).getSiteRoleGroup(siteInfo.getShortName(), sitePermission.getPermission(), false);
                    String alternativeName = ((SiteServiceImpl) siteService).getSiteRoleGroup(siteInfo.getShortName(), sitePermission.getPermission(), true);
                    // check for correct displayName
                    if ((!necessaryName.equalsIgnoreCase(currDisplayName)) || (!alternativeName.equalsIgnoreCase(currDisplayName))) {
                        // fix incorrect display name
                        authorityService.setAuthorityDisplayName(authorityName, necessaryName);
                    }
                }
            }
        }
    };
    siteBatchProcessor.process(worker, true);
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) ArrayList(java.util.ArrayList) AccessPermission(org.alfresco.service.cmr.security.AccessPermission) SiteServiceImpl(org.alfresco.repo.site.SiteServiceImpl) BatchProcessWorkProvider(org.alfresco.repo.batch.BatchProcessWorkProvider) BatchProcessWorker(org.alfresco.repo.batch.BatchProcessor.BatchProcessWorker) BatchProcessor(org.alfresco.repo.batch.BatchProcessor)

Aggregations

ArrayList (java.util.ArrayList)1 BatchProcessWorkProvider (org.alfresco.repo.batch.BatchProcessWorkProvider)1 BatchProcessor (org.alfresco.repo.batch.BatchProcessor)1 BatchProcessWorker (org.alfresco.repo.batch.BatchProcessor.BatchProcessWorker)1 SiteServiceImpl (org.alfresco.repo.site.SiteServiceImpl)1 AccessPermission (org.alfresco.service.cmr.security.AccessPermission)1 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)1