Search in sources :

Example 1 with ActivityPostDAO

use of org.alfresco.repo.domain.activities.ActivityPostDAO in project alfresco-repository by Alfresco.

the class TemporarySites method after.

@Override
protected void after() {
    final RetryingTransactionHelper transactionHelper = (RetryingTransactionHelper) appContextRule.getApplicationContext().getBean("retryingTransactionHelper");
    final SiteService siteService = appContextRule.getApplicationContext().getBean("siteService", SiteService.class);
    final ActivityPostDAO postDAO = appContextRule.getApplicationContext().getBean("postDAO", ActivityPostDAO.class);
    final NodeArchiveService nodeArchiveService = (NodeArchiveService) appContextRule.getApplicationContext().getBean("nodeArchiveService");
    // Run as admin to ensure all sites can be deleted irrespective of which user created them.
    AuthenticationUtil.runAs(new RunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            transactionHelper.doInTransaction(new RetryingTransactionCallback<Void>() {

                @Override
                public Void execute() throws Throwable {
                    for (SiteInfo site : temporarySites) {
                        final String shortName = site.getShortName();
                        if (siteService.getSite(shortName) != null) {
                            log.debug("Deleting temporary site " + shortName);
                            siteService.deleteSite(shortName);
                        }
                    }
                    for (String username : temporarySiteUsers) {
                        log.debug("Deleting temporary site user " + username);
                        deletePerson(username);
                    }
                    // Clean all the post feeds
                    int deletedCnt = 0;
                    Date keepDate = new Date(System.currentTimeMillis() + (120 * 1000L));
                    for (ActivityPostEntity.STATUS status : ActivityPostEntity.STATUS.values()) {
                        deletedCnt += postDAO.deletePosts(keepDate, status);
                    }
                    log.debug("Deleted " + deletedCnt + " post feeds.");
                    return null;
                }
            });
            transactionHelper.doInTransaction(new RetryingTransactionCallback<Void>() {

                @Override
                public Void execute() throws Throwable {
                    for (SiteInfo site : temporarySites) {
                        log.debug("Purging temporary site from trashcan: " + site.getShortName());
                        nodeArchiveService.purgeArchivedNode(nodeArchiveService.getArchivedNode(site.getNodeRef()));
                    }
                    return null;
                }
            });
            return null;
        }
    }, AuthenticationUtil.getAdminUserName());
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) ActivityPostEntity(org.alfresco.repo.domain.activities.ActivityPostEntity) SiteService(org.alfresco.service.cmr.site.SiteService) ActivityPostDAO(org.alfresco.repo.domain.activities.ActivityPostDAO) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) NodeArchiveService(org.alfresco.repo.node.archive.NodeArchiveService)

Aggregations

ActivityPostDAO (org.alfresco.repo.domain.activities.ActivityPostDAO)1 ActivityPostEntity (org.alfresco.repo.domain.activities.ActivityPostEntity)1 NodeArchiveService (org.alfresco.repo.node.archive.NodeArchiveService)1 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)1 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)1 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)1 SiteService (org.alfresco.service.cmr.site.SiteService)1