From 007421189e727d48c5bac3437b1632ce0fbbc6b1 Mon Sep 17 00:00:00 2001 From: Mario Serrano Date: Thu, 9 Dec 2021 17:28:59 -0500 Subject: [PATCH] default account env var --- .../saas/services/impl/AccountServiceAPIImpl.java | 12 ++++++++++++ .../saas/services/impl/AccountServiceImpl.java | 9 ++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/sources/core/src/main/java/tools/dynamia/modules/saas/services/impl/AccountServiceAPIImpl.java b/sources/core/src/main/java/tools/dynamia/modules/saas/services/impl/AccountServiceAPIImpl.java index e8aa247..d7ca3fa 100644 --- a/sources/core/src/main/java/tools/dynamia/modules/saas/services/impl/AccountServiceAPIImpl.java +++ b/sources/core/src/main/java/tools/dynamia/modules/saas/services/impl/AccountServiceAPIImpl.java @@ -18,6 +18,7 @@ package tools.dynamia.modules.saas.services.impl; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import tools.dynamia.commons.SimpleCache; @@ -62,6 +63,9 @@ public class AccountServiceAPIImpl extends AbstractService implements AccountSer @Autowired private AccountContext accountContext; + @Autowired + private Environment environment; + private final SimpleCache accountCache = new SimpleCache<>(); private final SimpleCache domainCache = new SimpleCache<>(); @@ -92,6 +96,8 @@ public AccountDTO getAccount(Long accountId) { if (dto == null) { Account account = crudService().findSingle(Account.class, QueryParameters.with("id", accountId).add("status", QueryConditions.isNotNull())); + + if (account != null) { dto = account.toDTO(); accountCache.add(accountId, dto); @@ -285,6 +291,12 @@ public Long getAccountIdByDomain(String domain) { accountId = account.getId(); } } + if (account == null && "true".equals(environment.getProperty("useDefaultAccount"))) { + account = service.getDefaultAccount(); + accountId = account.getId(); + } + + if (accountId != null) { domainCache.add(domain, accountId); } diff --git a/sources/core/src/main/java/tools/dynamia/modules/saas/services/impl/AccountServiceImpl.java b/sources/core/src/main/java/tools/dynamia/modules/saas/services/impl/AccountServiceImpl.java index 7d454ae..81a694d 100644 --- a/sources/core/src/main/java/tools/dynamia/modules/saas/services/impl/AccountServiceImpl.java +++ b/sources/core/src/main/java/tools/dynamia/modules/saas/services/impl/AccountServiceImpl.java @@ -20,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextRefreshedEvent; +import org.springframework.core.env.Environment; import org.springframework.orm.jpa.EntityManagerFactoryInfo; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; @@ -60,6 +61,9 @@ public class AccountServiceImpl implements AccountService, ApplicationListener