@Override
public Tenant create(Tenant tenant) throws EntityAlreadyExistsException, InvalidEntityException
{
if (this.dao.findBySlug(TENANT_TABLE_NAME, tenant.getSlug()) != null) {
throw new EntityAlreadyExistsException();
}
this.dao.begin();
TenantConfiguration configuration = tenant.getConfiguration();
try {
String configurationAsJson = convertConfigurationToJSON(configuration);
UUID id = UUID.randomUUID();
tenant.setId(id);
this.dao.createEntity(tenant, TENANT_TABLE_NAME);
this.dao.create(tenant, configuration.getVersion(), configurationAsJson);
this.dao.createOrUpdateAddons(tenant);
return tenant;
} catch (JsonProcessingException e) {
throw new RuntimeException("Failed to create tenant", e);
} finally {
this.dao.commit();
}
}