Shared tenant entities

Hello,
I wonder if there is a better way to “share” tenant entities. Let’s consider a template entity. The tenants can make there own templates, but we also want to provide some default templates.

What we do now is copy the default templates for every new tenant. This of course also has some downsides, e.g. in terms of maintenance, if the default templates changes.

Is there a better way to have “tenant entities” that are also shared?

Hi @klaus ,
You can make like this, add shared field in your templateEntity:

public class TemplateEntity extend StandardTenantEntity {
   private Boolean shared = Boolean.FALSE;
   //other fields here
}

And if is template shared you should set:

template.setTenantId(TenantProvider.NO_TENANT)

and when you fetch templates

public List<TemplateEntity> getTemplates(String tenantId){
        return systemAuthenticator.runWithSystem(() -> {
            return dataManager.load(TemplateEntity.class)
                    .query("select e from TemplateEntity e where e.tenantId=:tenantId or e.shared=true")
                    .parameter("tennantId", tenantId)
                    .list();
        });
}

try like this, may be it helpful for you.

Thanks,
Nurmuhammad

1 Like

@nurmuhammad.abdurash Thanks, that looks good, I will try it out!