Search in sources :

Example 1 with Tenant

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;
}
Also used : Tenant(org.alfresco.repo.tenant.Tenant) TenantRunAsWork(org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork) RunAsWork(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork) NamespaceDefinition(org.alfresco.service.cmr.dictionary.NamespaceDefinition) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) DictionaryException(org.alfresco.service.cmr.dictionary.DictionaryException)

Example 2 with Tenant

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());
        }
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) JobExecutionException(org.quartz.JobExecutionException) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) Tenant(org.alfresco.repo.tenant.Tenant) TenantAdminService(org.alfresco.repo.tenant.TenantAdminService) SimpleTrigger(org.quartz.SimpleTrigger)

Example 3 with Tenant

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

Example 4 with Tenant

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);
                }
            }
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Tenant(org.alfresco.repo.tenant.Tenant) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) FileExistsException(org.alfresco.service.cmr.model.FileExistsException) NoSuchPersonException(org.alfresco.service.cmr.security.NoSuchPersonException)

Aggregations

Tenant (org.alfresco.repo.tenant.Tenant)4 TenantAdminService (org.alfresco.repo.tenant.TenantAdminService)2 JobDataMap (org.quartz.JobDataMap)2 JobExecutionException (org.quartz.JobExecutionException)2 RunAsWork (org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork)1 TenantRunAsWork (org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork)1 AspectDefinition (org.alfresco.service.cmr.dictionary.AspectDefinition)1 DictionaryException (org.alfresco.service.cmr.dictionary.DictionaryException)1 NamespaceDefinition (org.alfresco.service.cmr.dictionary.NamespaceDefinition)1 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)1 DownloadService (org.alfresco.service.cmr.download.DownloadService)1 FileExistsException (org.alfresco.service.cmr.model.FileExistsException)1 FileNotFoundException (org.alfresco.service.cmr.model.FileNotFoundException)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 NoSuchPersonException (org.alfresco.service.cmr.security.NoSuchPersonException)1 DateTime (org.joda.time.DateTime)1 SimpleTrigger (org.quartz.SimpleTrigger)1 Trigger (org.quartz.Trigger)1