From 37aa6061a4a9c0c02688756c6c60e3e10a0a77f8 Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Tue, 16 Jan 2024 12:51:38 +0200 Subject: [PATCH] add locale config --- .../locale/LocaleConfiguration.java | 20 +++++++++++ .../locale/LocaleProperties.java | 34 +++++++++++++++++++ .../eudat/interceptors/UserInterceptor.java | 16 ++++++--- .../src/main/resources/config/application.yml | 1 + .../web/src/main/resources/config/locale.yml | 4 +++ 5 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 dmp-backend/core/src/main/java/eu/eudat/configurations/locale/LocaleConfiguration.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/configurations/locale/LocaleProperties.java create mode 100644 dmp-backend/web/src/main/resources/config/locale.yml diff --git a/dmp-backend/core/src/main/java/eu/eudat/configurations/locale/LocaleConfiguration.java b/dmp-backend/core/src/main/java/eu/eudat/configurations/locale/LocaleConfiguration.java new file mode 100644 index 000000000..0b95b2650 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/configurations/locale/LocaleConfiguration.java @@ -0,0 +1,20 @@ +package eu.eudat.configurations.locale; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Configuration +@EnableConfigurationProperties(LocaleProperties.class) +public class LocaleConfiguration { + private final LocaleProperties properties; + + @Autowired + public LocaleConfiguration(LocaleProperties properties) { + this.properties = properties; + } + + public LocaleProperties getProperties() { + return properties; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/configurations/locale/LocaleProperties.java b/dmp-backend/core/src/main/java/eu/eudat/configurations/locale/LocaleProperties.java new file mode 100644 index 000000000..64f7d163e --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/configurations/locale/LocaleProperties.java @@ -0,0 +1,34 @@ +package eu.eudat.configurations.locale; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "locale") +public class LocaleProperties { + private String timezone; + private String language; + private String culture; + + public String getTimezone() { + return timezone; + } + + public void setTimezone(String timezone) { + this.timezone = timezone; + } + + public String getLanguage() { + return language; + } + + public void setLanguage(String language) { + this.language = language; + } + + public String getCulture() { + return culture; + } + + public void setCulture(String culture) { + this.culture = culture; + } +} diff --git a/dmp-backend/web/src/main/java/eu/eudat/interceptors/UserInterceptor.java b/dmp-backend/web/src/main/java/eu/eudat/interceptors/UserInterceptor.java index b3ce911b7..43aa1bb47 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/interceptors/UserInterceptor.java +++ b/dmp-backend/web/src/main/java/eu/eudat/interceptors/UserInterceptor.java @@ -9,6 +9,7 @@ import eu.eudat.commons.lock.LockByKeyManager; import eu.eudat.commons.scope.user.UserScope; import eu.eudat.commons.types.user.AdditionalInfoEntity; import eu.eudat.commons.types.usercredential.UserCredentialDataEntity; +import eu.eudat.configurations.locale.LocaleProperties; import eu.eudat.data.UserContactInfoEntity; import eu.eudat.data.UserCredentialEntity; import eu.eudat.data.UserEntity; @@ -57,6 +58,7 @@ public class UserInterceptor implements WebRequestInterceptor { private final JsonHandlingService jsonHandlingService; private final QueryFactory queryFactory; private final LockByKeyManager lockByKeyManager; + private final LocaleProperties localeProperties; @PersistenceContext public EntityManager entityManager; @@ -67,9 +69,10 @@ public class UserInterceptor implements WebRequestInterceptor { CurrentPrincipalResolver currentPrincipalResolver, PlatformTransactionManager transactionManager, UserInterceptorCacheService userInterceptorCacheService, - JsonHandlingService jsonHandlingService, - QueryFactory queryFactory, - LockByKeyManager lockByKeyManager) { + JsonHandlingService jsonHandlingService, + QueryFactory queryFactory, + LockByKeyManager lockByKeyManager, + LocaleProperties localeProperties) { this.userScope = userScope; this.currentPrincipalResolver = currentPrincipalResolver; this.claimExtractor = claimExtractor; @@ -78,6 +81,7 @@ public class UserInterceptor implements WebRequestInterceptor { this.jsonHandlingService = jsonHandlingService; this.queryFactory = queryFactory; this.lockByKeyManager = lockByKeyManager; + this.localeProperties = localeProperties; } @Override @@ -336,7 +340,11 @@ public class UserInterceptor implements WebRequestInterceptor { user.setCreatedAt(Instant.now()); user.setUpdatedAt(Instant.now()); user.setIsActive(IsActive.Active); - user.setAdditionalInfo(this.jsonHandlingService.toJsonSafe(new AdditionalInfoEntity())); //TODO + AdditionalInfoEntity additionalInfoEntity = new AdditionalInfoEntity(); + additionalInfoEntity.setCulture(this.localeProperties.getCulture()); + additionalInfoEntity.setLanguage(this.localeProperties.getLanguage()); + additionalInfoEntity.setTimezone(this.localeProperties.getTimezone()); + user.setAdditionalInfo(this.jsonHandlingService.toJsonSafe(additionalInfoEntity)); this.entityManager.persist(user); UserCredentialEntity credential = this.buildCredential(user.getId(), subjectId); diff --git a/dmp-backend/web/src/main/resources/config/application.yml b/dmp-backend/web/src/main/resources/config/application.yml index 49dc175ed..dc7b597ee 100644 --- a/dmp-backend/web/src/main/resources/config/application.yml +++ b/dmp-backend/web/src/main/resources/config/application.yml @@ -28,5 +28,6 @@ spring: optional:classpath:config/tenant.yml[.yml], optional:classpath:config/tenant-${spring.profiles.active}.yml[.yml], optional:file:../config/tenant-${spring.profiles.active}.yml[.yml], optional:classpath:config/queue.yml[.yml], optional:classpath:config/queue-${spring.profiles.active}.yml[.yml], optional:file:../config/queue-${spring.profiles.active}.yml[.yml], optional:classpath:config/notification.yml[.yml], optional:classpath:config/notification-${spring.profiles.active}.yml[.yml], optional:file:../config/notification-${spring.profiles.active}.yml[.yml], + optional:classpath:config/locale.yml[.yml], optional:classpath:config/locale-${spring.profiles.active}.yml[.yml], optional:file:../config/locale-${spring.profiles.active}.yml[.yml], optional:classpath:config/transformer.yml[.yml], optional:classpath:config/transformer-${spring.profiles.active}.yml[.yml], optional:file:../config/transformer-${spring.profiles.active}.yml[.yml] diff --git a/dmp-backend/web/src/main/resources/config/locale.yml b/dmp-backend/web/src/main/resources/config/locale.yml new file mode 100644 index 000000000..bc862307f --- /dev/null +++ b/dmp-backend/web/src/main/resources/config/locale.yml @@ -0,0 +1,4 @@ +locale: + timezone: UTC + language: en + culture: en-001