use of org.alfresco.repo.tenant.Tenant in project alfresco-repository by Alfresco.
the class ModelValidatorImpl method canDeleteModel.
/**
* {@inheritDoc}
*/
@Override
public boolean canDeleteModel(final QName modelName) {
boolean canDeleteModel = true;
// TODO add model locking during delete (would need to be tenant-aware & cluster-aware) to avoid potential
// for concurrent addition of new content/workflow as model is being deleted
final Collection<NamespaceDefinition> namespaceDefs;
final Collection<TypeDefinition> typeDefs;
final Collection<AspectDefinition> aspectDefs;
try {
namespaceDefs = dictionaryDAO.getNamespaces(modelName);
typeDefs = dictionaryDAO.getTypes(modelName);
aspectDefs = dictionaryDAO.getAspects(modelName);
// TODO - in case of MT we do not currently allow deletion of an overridden model (with usages) ... but could allow if (re-)inherited model is equivalent to an incremental update only ?
canDeleteModel &= canDeleteModel(namespaceDefs, typeDefs, aspectDefs, null);
if (canDeleteModel) {
if (tenantService.isEnabled() && tenantService.isTenantUser() == false) {
// TODO should fix this up - won't scale
// shared model - need to check all tenants (whether enabled or disabled) unless they have overridden
List<Tenant> tenants = tenantAdminService.getAllTenants();
for (final Tenant tenant : tenants) {
// validate model delete within context of tenant domain
canDeleteModel &= AuthenticationUtil.runAs(new RunAsWork<Boolean>() {
public Boolean doWork() {
boolean canDelete = canDeleteModel(namespaceDefs, typeDefs, aspectDefs, tenant);
return canDelete;
}
}, tenantService.getDomainUser(AuthenticationUtil.getSystemUserName(), tenant.getTenantDomain()));
if (!canDeleteModel) {
break;
}
}
}
}
} catch (DictionaryException e) {
if (logger.isDebugEnabled()) {
logger.debug("Dictionary model '" + modelName + "' does not exist ... skip delete validation : " + e);
}
// we must return true here - there is no model
canDeleteModel = true;
}
return canDeleteModel;
}
use of org.alfresco.repo.tenant.Tenant in project alfresco-repository by Alfresco.
the class FeedNotifierJob method execute.
/**
* Calls the feed notifier to do its work
*/
public void execute(JobExecutionContext context) throws JobExecutionException {
JobDataMap jobData = context.getJobDetail().getJobDataMap();
final FeedNotifier feedNotifier = (FeedNotifier) jobData.get(KEY_FEED_NOTIFIER);
final TenantAdminService tenantAdminService = (TenantAdminService) jobData.get(KEY_TENANT_ADMIN_SERVICE);
Long repeatInterval = null;
Trigger trigger = context.getTrigger();
if (trigger instanceof SimpleTrigger) {
repeatInterval = ((SimpleTrigger) trigger).getRepeatInterval();
}
final int repeatIntervalMins = new Long(repeatInterval == null ? 0L : repeatInterval / 1000 / 60).intValue();
AuthenticationUtil.runAs(new RunAsWork<Object>() {
public Object doWork() throws Exception {
feedNotifier.execute(repeatIntervalMins);
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 {
feedNotifier.execute(repeatIntervalMins);
return null;
}
}, tenant.getTenantDomain());
}
}
}
use of org.alfresco.repo.tenant.Tenant 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());
}
}
}
use of org.alfresco.repo.tenant.Tenant in project alfresco-repository by Alfresco.
the class HomeFolderProviderSynchronizer method onBootstrap.
@Override
protected void onBootstrap(ApplicationEvent event) {
if (enabled()) {
final String overrideProviderName = getOverrideHomeFolderProviderName();
// Scan users in default and each Tenant
scanPeople(AuthenticationUtil.getSystemUserName(), TenantService.DEFAULT_DOMAIN, overrideProviderName);
if (tenantAdminService.isEnabled()) {
List<Tenant> tenants = tenantAdminService.getAllTenants();
for (Tenant tenant : tenants) {
if (tenant.isEnabled()) {
final String tenantDomain = tenant.getTenantDomain();
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Object>() {
public NodeRef doWork() throws Exception {
scanPeople(AuthenticationUtil.getSystemUserName(), tenantDomain, overrideProviderName);
return null;
}
}, tenantDomain);
}
}
}
}
}
Aggregations