diff --git a/sources/api/pom.xml b/sources/api/pom.xml index eab8d6e..bd533ea 100644 --- a/sources/api/pom.xml +++ b/sources/api/pom.xml @@ -26,13 +26,13 @@ tools.dynamia.modules tools.dynamia.modules.saas.parent - 3.4.1 + 3.4.2 tools.dynamia.modules.saas.api DynamiaModules - SaaS API https://www.dynamia.tools/modules/saas - 3.4.1 + 3.4.2 diff --git a/sources/core/pom.xml b/sources/core/pom.xml index 8de5fda..e277807 100644 --- a/sources/core/pom.xml +++ b/sources/core/pom.xml @@ -22,10 +22,10 @@ tools.dynamia.modules tools.dynamia.modules.saas.parent - 3.4.1 + 3.4.2 tools.dynamia.modules.saas - 3.4.1 + 3.4.2 DynamiaModules - SaaS Core https://www.dynamia.tools/modules/saas @@ -49,12 +49,12 @@ tools.dynamia.modules tools.dynamia.modules.saas.api - 3.4.1 + 3.4.2 tools.dynamia.modules tools.dynamia.modules.saas.jpa - 3.4.1 + 3.4.2 junit diff --git a/sources/core/src/main/java/tools/dynamia/modules/saas/AccountLocaleProvider.java b/sources/core/src/main/java/tools/dynamia/modules/saas/AccountLocaleProvider.java index c4e001a..c63ad6f 100644 --- a/sources/core/src/main/java/tools/dynamia/modules/saas/AccountLocaleProvider.java +++ b/sources/core/src/main/java/tools/dynamia/modules/saas/AccountLocaleProvider.java @@ -24,16 +24,40 @@ import java.util.Locale; +/** + * AccountLocaleProvider is an implementation of {@link LocaleProvider} for SaaS environments. + *

+ * Provides the default {@link Locale} based on the current account session context. + * The priority for this provider is set to 10, making it suitable for account-level locale resolution. + *

+ * If the account session or locale cannot be resolved, this provider returns null. + * + * @author Mario + */ @Provider public class AccountLocaleProvider implements LocaleProvider { - + /** + * Logger for this provider, using SLF4J. + */ private final LoggingService logger = new SLF4JLoggingService(AccountLocaleProvider.class); + /** + * Returns the priority of this provider. Lower values indicate higher priority. + * + * @return the priority value (10) + */ @Override public int getPriority() { return 10; } + /** + * Returns the default {@link Locale} for the current account session. + *

+ * Attempts to retrieve the account locale from the current session. If unavailable, returns null. + * + * @return the account's default Locale, or null if not available + */ @Override public Locale getDefaultLocale() { try { diff --git a/sources/core/src/main/java/tools/dynamia/modules/saas/AccountSessionHolder.java b/sources/core/src/main/java/tools/dynamia/modules/saas/AccountSessionHolder.java index 7152e98..ef4f089 100644 --- a/sources/core/src/main/java/tools/dynamia/modules/saas/AccountSessionHolder.java +++ b/sources/core/src/main/java/tools/dynamia/modules/saas/AccountSessionHolder.java @@ -31,6 +31,7 @@ import tools.dynamia.modules.saas.services.AccountService; import java.io.Serializable; +import java.time.ZoneId; import java.util.Locale; /** @@ -45,6 +46,7 @@ public class AccountSessionHolder implements Serializable { private transient AccountService service; private Locale accountLocale; + private ZoneId accountTimeZone; private Long currentId; private AccountDTO currentDTO; @@ -82,7 +84,8 @@ public void setCurrent(final Account account) { try { DomainUtils.lookupCrudService().executeWithinTransaction(() -> { var current = getService().getAccountById(account.getId()); - accountLocale = current.getLocale() != null ? Locale.forLanguageTag(current.getLocale()) : null; + loadAccountLocale(current); + loadAccountTimeZone(current); currentId = current.getId(); currentDTO = current.toDTO(); }); @@ -92,6 +95,22 @@ public void setCurrent(final Account account) { } } + private void loadAccountTimeZone(Account current) { + try { + accountTimeZone = current.getTimeZone() != null ? ZoneId.of(current.getTimeZone()) : null; + } catch (Exception e) { + accountTimeZone = null; + } + } + + private void loadAccountLocale(Account current) { + try { + accountLocale = current.getLocale() != null ? Locale.forLanguageTag(current.getLocale()) : null; + } catch (Exception e) { + accountLocale = null; + } + } + public AccountDTO toDTO() { return currentDTO; @@ -114,4 +133,11 @@ private AccountService getService() { } return service; } + + public ZoneId getAccountTimeZone() { + if (accountTimeZone == null) { + accountTimeZone = ZoneId.systemDefault(); + } + return accountTimeZone; + } } diff --git a/sources/core/src/main/java/tools/dynamia/modules/saas/AccountTimeZoneProvider.java b/sources/core/src/main/java/tools/dynamia/modules/saas/AccountTimeZoneProvider.java new file mode 100644 index 0000000..2be0f1d --- /dev/null +++ b/sources/core/src/main/java/tools/dynamia/modules/saas/AccountTimeZoneProvider.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2023 Dynamia Soluciones IT S.A.S - NIT 900302344-1 + * Colombia / South America + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tools.dynamia.modules.saas; + +import tools.dynamia.commons.TimeZoneProvider; +import tools.dynamia.commons.logger.LoggingService; +import tools.dynamia.commons.logger.SLF4JLoggingService; +import tools.dynamia.integration.sterotypes.Provider; + +import java.time.ZoneId; + +/** + * AccountTimeZoneProvider is an implementation of {@link TimeZoneProvider} for SaaS environments. + *

+ * Provides the default {@link ZoneId} based on the current account session context. + * The priority for this provider is set to 10, making it suitable for account-level time zone resolution. + *

+ * If the account session or time zone cannot be resolved, this provider returns null. + * + * @author Mario + */ +@Provider +public class AccountTimeZoneProvider implements TimeZoneProvider { + /** + * Logger for this provider, using SLF4J. + */ + private final LoggingService logger = new SLF4JLoggingService(AccountTimeZoneProvider.class); + + /** + * Returns the priority of this provider. Lower values indicate higher priority. + * + * @return the priority value (10) + */ + @Override + public int getPriority() { + return 10; + } + + /** + * Returns the default {@link ZoneId} for the current account session. + *

+ * Attempts to retrieve the account time zone from the current session. If unavailable, returns null. + * + * @return the account's default ZoneId, or null if not available + */ + @Override + public ZoneId getDefaultTimeZone() { + try { + return AccountSessionHolder.get().getAccountTimeZone(); + } catch (Exception e) { + return null; + } + } +} diff --git a/sources/jpa/pom.xml b/sources/jpa/pom.xml index c3fa1a8..026622b 100644 --- a/sources/jpa/pom.xml +++ b/sources/jpa/pom.xml @@ -22,7 +22,7 @@ tools.dynamia.modules.saas.parent tools.dynamia.modules - 3.4.1 + 3.4.2 4.0.0 DynamiaModules - SaaS JPA @@ -33,7 +33,7 @@ tools.dynamia.modules tools.dynamia.modules.saas.api - 3.4.1 + 3.4.2 tools.dynamia diff --git a/sources/pom.xml b/sources/pom.xml index 567b689..934947d 100644 --- a/sources/pom.xml +++ b/sources/pom.xml @@ -21,7 +21,7 @@ 4.0.0 tools.dynamia.modules tools.dynamia.modules.saas.parent - 3.4.1 + 3.4.2 pom DynamiaModules - SaaS DynamiaTools extension to create SaaS applications with accounts control and multi tenants in same @@ -59,7 +59,7 @@ - 5.4.0 + 5.4.1 7.4.0 21 3.14.0 @@ -68,7 +68,7 @@ 6.5.0 5.14.0 - 3.5.3 + 3.5.5 diff --git a/sources/remote/pom.xml b/sources/remote/pom.xml index 6c9dc39..b5abb69 100644 --- a/sources/remote/pom.xml +++ b/sources/remote/pom.xml @@ -22,7 +22,7 @@ tools.dynamia.modules.saas.parent tools.dynamia.modules - 3.4.1 + 3.4.2 4.0.0 @@ -35,7 +35,7 @@ tools.dynamia.modules tools.dynamia.modules.saas.jpa - 3.4.1 + 3.4.2 diff --git a/sources/ui/pom.xml b/sources/ui/pom.xml index 85760b6..4266483 100644 --- a/sources/ui/pom.xml +++ b/sources/ui/pom.xml @@ -22,10 +22,10 @@ tools.dynamia.modules tools.dynamia.modules.saas.parent - 3.4.1 + 3.4.2 tools.dynamia.modules.saas.ui - 3.4.1 + 3.4.2 DynamiaModules - SaaS UI https://www.dynamia.tools/modules/saas