add locale config

This commit is contained in:
Efstratios Giannopoulos 2024-01-16 12:51:38 +02:00
parent 1828e28485
commit 37aa6061a4
5 changed files with 71 additions and 4 deletions

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -9,6 +9,7 @@ import eu.eudat.commons.lock.LockByKeyManager;
import eu.eudat.commons.scope.user.UserScope; import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.commons.types.user.AdditionalInfoEntity; import eu.eudat.commons.types.user.AdditionalInfoEntity;
import eu.eudat.commons.types.usercredential.UserCredentialDataEntity; import eu.eudat.commons.types.usercredential.UserCredentialDataEntity;
import eu.eudat.configurations.locale.LocaleProperties;
import eu.eudat.data.UserContactInfoEntity; import eu.eudat.data.UserContactInfoEntity;
import eu.eudat.data.UserCredentialEntity; import eu.eudat.data.UserCredentialEntity;
import eu.eudat.data.UserEntity; import eu.eudat.data.UserEntity;
@ -57,6 +58,7 @@ public class UserInterceptor implements WebRequestInterceptor {
private final JsonHandlingService jsonHandlingService; private final JsonHandlingService jsonHandlingService;
private final QueryFactory queryFactory; private final QueryFactory queryFactory;
private final LockByKeyManager lockByKeyManager; private final LockByKeyManager lockByKeyManager;
private final LocaleProperties localeProperties;
@PersistenceContext @PersistenceContext
public EntityManager entityManager; public EntityManager entityManager;
@ -67,9 +69,10 @@ public class UserInterceptor implements WebRequestInterceptor {
CurrentPrincipalResolver currentPrincipalResolver, CurrentPrincipalResolver currentPrincipalResolver,
PlatformTransactionManager transactionManager, PlatformTransactionManager transactionManager,
UserInterceptorCacheService userInterceptorCacheService, UserInterceptorCacheService userInterceptorCacheService,
JsonHandlingService jsonHandlingService, JsonHandlingService jsonHandlingService,
QueryFactory queryFactory, QueryFactory queryFactory,
LockByKeyManager lockByKeyManager) { LockByKeyManager lockByKeyManager,
LocaleProperties localeProperties) {
this.userScope = userScope; this.userScope = userScope;
this.currentPrincipalResolver = currentPrincipalResolver; this.currentPrincipalResolver = currentPrincipalResolver;
this.claimExtractor = claimExtractor; this.claimExtractor = claimExtractor;
@ -78,6 +81,7 @@ public class UserInterceptor implements WebRequestInterceptor {
this.jsonHandlingService = jsonHandlingService; this.jsonHandlingService = jsonHandlingService;
this.queryFactory = queryFactory; this.queryFactory = queryFactory;
this.lockByKeyManager = lockByKeyManager; this.lockByKeyManager = lockByKeyManager;
this.localeProperties = localeProperties;
} }
@Override @Override
@ -336,7 +340,11 @@ public class UserInterceptor implements WebRequestInterceptor {
user.setCreatedAt(Instant.now()); user.setCreatedAt(Instant.now());
user.setUpdatedAt(Instant.now()); user.setUpdatedAt(Instant.now());
user.setIsActive(IsActive.Active); 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); this.entityManager.persist(user);
UserCredentialEntity credential = this.buildCredential(user.getId(), subjectId); UserCredentialEntity credential = this.buildCredential(user.getId(), subjectId);

View File

@ -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/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/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/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] optional:classpath:config/transformer.yml[.yml], optional:classpath:config/transformer-${spring.profiles.active}.yml[.yml], optional:file:../config/transformer-${spring.profiles.active}.yml[.yml]

View File

@ -0,0 +1,4 @@
locale:
timezone: UTC
language: en
culture: en-001