Search in sources :

Example 1 with DownloadService

use of org.alfresco.service.cmr.download.DownloadService in project alfresco-repository by Alfresco.

the class DownloadsCleanupJob method execute.

/*
     * @see org.quartz.Job#execute(org.quartz.JobExecutionContext)
     */
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    JobDataMap jobData = context.getJobDetail().getJobDataMap();
    // extract the services and max age to use
    final DownloadService downloadService = (DownloadService) jobData.get(KEY_DOWNLOAD_SERVICE);
    final TenantAdminService tenantAdminService = (TenantAdminService) jobData.get(KEY_TENANT_ADMIN_SERVICE);
    final int maxAgeInMinutes = Integer.parseInt((String) jobData.get(KEY_MAX_AGE));
    final int batchSize = Integer.parseInt((String) jobData.get(BATCH_SIZE));
    final boolean cleanAllSysDownloadFolders = Boolean.parseBoolean((String) jobData.get(CLEAN_All_SYS_DOWNLOAD_FOLDERS));
    final DateTime before = new DateTime().minusMinutes(maxAgeInMinutes);
    AuthenticationUtil.runAs(new RunAsWork<Object>() {

        public Object doWork() throws Exception {
            downloadService.deleteDownloads(before.toDate(), batchSize, cleanAllSysDownloadFolders);
            return null;
        }
    }, AuthenticationUtil.getSystemUserName());
    if ((tenantAdminService != null) && tenantAdminService.isEnabled()) {
        List<Tenant> tenants = tenantAdminService.getAllTenants();
        for (Tenant tenant : tenants) {
            TenantUtil.runAsSystemTenant(new TenantRunAsWork<Object>() {

                public Object doWork() throws Exception {
                    downloadService.deleteDownloads(before.toDate(), batchSize, cleanAllSysDownloadFolders);
                    return null;
                }
            }, tenant.getTenantDomain());
        }
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) Tenant(org.alfresco.repo.tenant.Tenant) TenantAdminService(org.alfresco.repo.tenant.TenantAdminService) DownloadService(org.alfresco.service.cmr.download.DownloadService) DateTime(org.joda.time.DateTime) JobExecutionException(org.quartz.JobExecutionException)

Aggregations

Tenant (org.alfresco.repo.tenant.Tenant)1 TenantAdminService (org.alfresco.repo.tenant.TenantAdminService)1 DownloadService (org.alfresco.service.cmr.download.DownloadService)1 DateTime (org.joda.time.DateTime)1 JobDataMap (org.quartz.JobDataMap)1 JobExecutionException (org.quartz.JobExecutionException)1