Search in sources :

Example 1 with TenantAdminService

use of org.alfresco.repo.tenant.TenantAdminService 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 2 with TenantAdminService

use of org.alfresco.repo.tenant.TenantAdminService 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 3 with TenantAdminService

use of org.alfresco.repo.tenant.TenantAdminService in project alfresco-repository by Alfresco.

the class DictionaryModelTypeTest method before.

@Before
public void before() throws Exception {
    TestTransaction.flagForCommit();
    this.nodeService = (NodeService) this.applicationContext.getBean("nodeService");
    this.contentService = (ContentService) this.applicationContext.getBean("contentService");
    this.authenticationService = (MutableAuthenticationService) this.applicationContext.getBean("authenticationService");
    this.actionService = (ActionService) this.applicationContext.getBean("actionService");
    this.transactionService = (TransactionService) this.applicationContext.getBean("transactionComponent");
    // Authenticate as the admin user for dictionaryModelType
    // "System" user should also be allowed to create models
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    // Create the store and get the root node
    this.storeRef = this.nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
    this.rootNodeRef = this.nodeService.getRootNode(this.storeRef);
    // Get the required services
    this.dictionaryService = (DictionaryService) this.applicationContext.getBean("dictionaryService");
    this.namespaceService = (NamespaceService) this.applicationContext.getBean("namespaceService");
    this.cociService = (CheckOutCheckInService) this.applicationContext.getBean("checkOutCheckInService");
    this.dictionaryDAO = (DictionaryDAO) this.applicationContext.getBean("dictionaryDAO");
    this.nodeService = (NodeService) this.applicationContext.getBean("NodeService");
    this.policyComponent = (PolicyComponent) this.applicationContext.getBean("policyComponent");
    TenantAdminService tenantAdminService = (TenantAdminService) this.applicationContext.getBean("tenantAdminService");
    MessageService messageService = (MessageService) this.applicationContext.getBean("messageService");
    TestTransaction.end();
    TestTransaction.start();
    TestTransaction.flagForCommit();
    DictionaryRepositoryBootstrap bootstrap = new DictionaryRepositoryBootstrap();
    bootstrap.setContentService(this.contentService);
    bootstrap.setDictionaryDAO(this.dictionaryDAO);
    bootstrap.setTransactionService(this.transactionService);
    bootstrap.setTenantAdminService(tenantAdminService);
    bootstrap.setNodeService(this.nodeService);
    bootstrap.setNamespaceService(this.namespaceService);
    bootstrap.setMessageService(messageService);
    bootstrap.setPolicyComponent(policyComponent);
    RepositoryLocation location = new RepositoryLocation();
    location.setStoreProtocol(this.storeRef.getProtocol());
    location.setStoreId(this.storeRef.getIdentifier());
    location.setQueryLanguage(RepositoryLocation.LANGUAGE_PATH);
    // NOTE: we are not setting the path for now .. in doing so we are searching the root node only
    List<RepositoryLocation> locations = new ArrayList<RepositoryLocation>();
    locations.add(location);
    bootstrap.setRepositoryModelsLocations(locations);
    // register with dictionary service
    bootstrap.register();
    TestTransaction.end();
    TestTransaction.start();
}
Also used : TenantAdminService(org.alfresco.repo.tenant.TenantAdminService) ArrayList(java.util.ArrayList) MessageService(org.alfresco.repo.i18n.MessageService) Before(org.junit.Before)

Example 4 with TenantAdminService

use of org.alfresco.repo.tenant.TenantAdminService in project alfresco-repository by Alfresco.

the class AlfrescoTenant method before.

/**
 * Create the tenant.
 */
@Override
protected void before() throws Throwable {
    final ApplicationContext appCtx = getApplicationContext();
    RetryingTransactionHelper transactionHelper = appCtx.getBean("retryingTransactionHelper", RetryingTransactionHelper.class);
    final TenantAdminService tenantAdminService = appCtx.getBean("tenantAdminService", TenantAdminService.class);
    transactionHelper.doInTransaction(new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            tenantAdminService.createTenant(tenantName, ADMIN_PASSWORD.toCharArray());
            return null;
        }
    });
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) TenantAdminService(org.alfresco.repo.tenant.TenantAdminService) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper)

Example 5 with TenantAdminService

use of org.alfresco.repo.tenant.TenantAdminService in project alfresco-repository by Alfresco.

the class AlfrescoTenant method after.

/**
 * Remove the tenant
 */
@Override
protected void after() {
    final ApplicationContext appCtx = getApplicationContext();
    RetryingTransactionHelper transactionHelper = appCtx.getBean("retryingTransactionHelper", RetryingTransactionHelper.class);
    final TenantAdminService tenantAdminService = appCtx.getBean("tenantAdminService", TenantAdminService.class);
    transactionHelper.doInTransaction(new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            tenantAdminService.deleteTenant(tenantName);
            return null;
        }
    });
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) TenantAdminService(org.alfresco.repo.tenant.TenantAdminService) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper)

Aggregations

TenantAdminService (org.alfresco.repo.tenant.TenantAdminService)5 Tenant (org.alfresco.repo.tenant.Tenant)2 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)2 JobDataMap (org.quartz.JobDataMap)2 JobExecutionException (org.quartz.JobExecutionException)2 ApplicationContext (org.springframework.context.ApplicationContext)2 ArrayList (java.util.ArrayList)1 MessageService (org.alfresco.repo.i18n.MessageService)1 DownloadService (org.alfresco.service.cmr.download.DownloadService)1 DateTime (org.joda.time.DateTime)1 Before (org.junit.Before)1 SimpleTrigger (org.quartz.SimpleTrigger)1 Trigger (org.quartz.Trigger)1