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());
}
}
}
Aggregations