cancel
Showing results for 
Search instead for 
Did you mean: 

Multitenant and AbstractLifecycleBean

Not applicable
Hi,
I created a class that extends AbstractLifecycleBean (overriding onBootstrap method) for execute my startup code. It works.
But I must run my code for each tenant.
How can I execute a method for each tenant at startup?
I read docs and wiki, but nothing…

Thanks

          -ft
2 REPLIES 2

janv
Employee
Employee
One option is to inject the TenantAdminService and loop through the tenants, although you should consider how many tenants you may have and how long each method call may take per tenant.

Here's an example snippet:


        if ((tenantAdminService != null) && (tenantAdminService.isEnabled()))
        {
            for (Tenant tenant : tenantAdminService.getAllTenants())
            {
                AuthenticationUtil.runAs(new RunAsWork<Void>()
                {
                    public Void doWork() throws Exception
                    {
                        // do some work here
                        // ….

                        return null;
                    }
                }, tenantAdminService.getDomainUser(AuthenticationUtil.getSystemUserName(), tenant.getTenantDomain()));
            }
        }

If you scan through the existing source code and look for "getAllTenants" then you will see some similar examples.

Regards,
Jan

Not applicable
Hi,
thanks for reply
I have tried a similar code, but the row
tenantAdminService.getDomainUser(AuthenticationUtil.getSystemUserName(), tenant.getTenantDomain()))
was different.
I will try your suggestion.

Thanks!!!!!

       -ft