From 0c2d2e2f6a4a69e8e13d95fbb284e317244bcda6 Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Thu, 28 Mar 2024 14:57:51 +0200 Subject: [PATCH] update configurations --- annotation-service/annotation-web/pom.xml | 2 +- .../web/interceptors/UserInterceptor.java | 11 +- .../src/main/resources/config/application.yml | 4 +- .../src/main/resources/config/cache.yml | 37 +--- .../src/main/resources/config/db-devel.yml | 7 +- .../src/main/resources/config/db.yml | 6 +- .../src/main/resources/config/email.yml | 14 -- .../src/main/resources/config/formatting.yml | 6 - .../src/main/resources/config/idpclaims.yml | 2 + .../src/main/resources/config/permissions.yml | 27 ++- .../main/resources/config/security-devel.yml | 6 + .../src/main/resources/config/security.yml | 16 +- .../src/main/resources/config/server.yml | 12 +- ...ormattingUserprofileCacheCacheService.java | 93 ---------- .../annotation/config/email/EmailConfig.java | 9 - .../config/email/EmailProperties.java | 17 -- .../FormattingServiceConfiguration.java | 9 - .../FormattingServiceProperties.java | 38 ---- .../FormattingUserprofileCacheOptions.java | 10 - .../service/formatting/FormattingService.java | 26 --- .../formatting/FormattingServiceImpl.java | 171 ------------------ 21 files changed, 54 insertions(+), 469 deletions(-) delete mode 100644 annotation-service/annotation-web/src/main/resources/config/email.yml delete mode 100644 annotation-service/annotation-web/src/main/resources/config/formatting.yml create mode 100644 annotation-service/annotation-web/src/main/resources/config/security-devel.yml delete mode 100644 annotation-service/annotation/src/main/java/gr/cite/annotation/cache/FormattingUserprofileCacheCacheService.java delete mode 100644 annotation-service/annotation/src/main/java/gr/cite/annotation/config/email/EmailConfig.java delete mode 100644 annotation-service/annotation/src/main/java/gr/cite/annotation/config/email/EmailProperties.java delete mode 100644 annotation-service/annotation/src/main/java/gr/cite/annotation/config/formatting/FormattingServiceConfiguration.java delete mode 100644 annotation-service/annotation/src/main/java/gr/cite/annotation/config/formatting/FormattingServiceProperties.java delete mode 100644 annotation-service/annotation/src/main/java/gr/cite/annotation/config/formatting/FormattingUserprofileCacheOptions.java delete mode 100644 annotation-service/annotation/src/main/java/gr/cite/annotation/service/formatting/FormattingService.java delete mode 100644 annotation-service/annotation/src/main/java/gr/cite/annotation/service/formatting/FormattingServiceImpl.java diff --git a/annotation-service/annotation-web/pom.xml b/annotation-service/annotation-web/pom.xml index 729d1ce10..9e2b1e0f0 100644 --- a/annotation-service/annotation-web/pom.xml +++ b/annotation-service/annotation-web/pom.xml @@ -65,7 +65,7 @@ gr.cite cache - 2.1.0 + 2.2.0 gr.cite diff --git a/annotation-service/annotation-web/src/main/java/gr/cite/annotation/web/interceptors/UserInterceptor.java b/annotation-service/annotation-web/src/main/java/gr/cite/annotation/web/interceptors/UserInterceptor.java index 918705a1d..33b21485a 100644 --- a/annotation-service/annotation-web/src/main/java/gr/cite/annotation/web/interceptors/UserInterceptor.java +++ b/annotation-service/annotation-web/src/main/java/gr/cite/annotation/web/interceptors/UserInterceptor.java @@ -31,11 +31,8 @@ public class UserInterceptor implements WebRequestInterceptor { private final UserScope userScope; private final ClaimExtractor claimExtractor; private final CurrentPrincipalResolver currentPrincipalResolver; - private final PlatformTransactionManager transactionManager; private final UserInterceptorCacheService userInterceptorCacheService; - private final JsonHandlingService jsonHandlingService; private final QueryFactory queryFactory; - private final LockByKeyManager lockByKeyManager; @PersistenceContext public EntityManager entityManager; @@ -44,19 +41,13 @@ public class UserInterceptor implements WebRequestInterceptor { UserScope userScope, ClaimExtractor claimExtractor, CurrentPrincipalResolver currentPrincipalResolver, - PlatformTransactionManager transactionManager, UserInterceptorCacheService userInterceptorCacheService, - JsonHandlingService jsonHandlingService, - QueryFactory queryFactory, - LockByKeyManager lockByKeyManager) { + QueryFactory queryFactory) { this.userScope = userScope; this.currentPrincipalResolver = currentPrincipalResolver; this.claimExtractor = claimExtractor; - this.transactionManager = transactionManager; this.userInterceptorCacheService = userInterceptorCacheService; - this.jsonHandlingService = jsonHandlingService; this.queryFactory = queryFactory; - this.lockByKeyManager = lockByKeyManager; } @Override diff --git a/annotation-service/annotation-web/src/main/resources/config/application.yml b/annotation-service/annotation-web/src/main/resources/config/application.yml index fd750fd10..8ed82b873 100644 --- a/annotation-service/annotation-web/src/main/resources/config/application.yml +++ b/annotation-service/annotation-web/src/main/resources/config/application.yml @@ -14,7 +14,5 @@ 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/locale.yml[.yml], optional:classpath:config/locale-${spring.profiles.active}.yml[.yml], optional:file:../config/locale-${spring.profiles.active}.yml[.yml], optional:classpath:config/cors.yml[.yml], optional:classpath:config/cors-${spring.profiles.active}.yml[.yml], optional:file:../config/cors-${spring.profiles.active}.yml[.yml], - optional:classpath:config/email.yml[.yml], optional:classpath:config/email-${spring.profiles.active}.yml[.yml], optional:file:../config/email-${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/cipher.yml[.yml], optional:classpath:config/cipher-${spring.profiles.active}.yml[.yml], optional:file:../config/cipher-${spring.profiles.active}.yml[.yml], - optional:classpath:config/formatting.yml[.yml], optional:classpath:config/formatting-${spring.profiles.active}.yml[.yml], optional:file:../config/formatting-${spring.profiles.active}.yml[.yml] + optional:classpath:config/cipher.yml[.yml], optional:classpath:config/cipher-${spring.profiles.active}.yml[.yml], optional:file:../config/cipher-${spring.profiles.active}.yml[.yml] diff --git a/annotation-service/annotation-web/src/main/resources/config/cache.yml b/annotation-service/annotation-web/src/main/resources/config/cache.yml index 5b30dee77..c49b230c5 100644 --- a/annotation-service/annotation-web/src/main/resources/config/cache.yml +++ b/annotation-service/annotation-web/src/main/resources/config/cache.yml @@ -7,53 +7,32 @@ cache: initialCapacity: 100 maximumSize: 500 enableRecordStats: false - expireAfterWriteMinutes: 10 - expireAfterAccessMinutes: 10 - refreshAfterWriteMinutes: 10 + expireAfterWriteSeconds: 600 - names: [ tenantByCode ] allowNullValues: true initialCapacity: 100 maximumSize: 500 enableRecordStats: false - expireAfterWriteMinutes: 10 - expireAfterAccessMinutes: 10 - refreshAfterWriteMinutes: 10 + expireAfterWriteSeconds: 600 - names: [ tenantById ] allowNullValues: true initialCapacity: 100 maximumSize: 500 enableRecordStats: false - expireAfterWriteMinutes: 10 - expireAfterAccessMinutes: 10 - refreshAfterWriteMinutes: 10 + expireAfterWriteSeconds: 600 - names: [ userBySubjectId ] allowNullValues: true initialCapacity: 100 maximumSize: 500 enableRecordStats: false - expireAfterWriteMinutes: 5 - expireAfterAccessMinutes: 5 - refreshAfterWriteMinutes: 5 + expireAfterWriteSeconds: 320 - names: [ userAccessTenant ] allowNullValues: true initialCapacity: 100 maximumSize: 500 enableRecordStats: false - expireAfterWriteMinutes: 5 - expireAfterAccessMinutes: 5 - refreshAfterWriteMinutes: 5 - - names: [ formattingUserProfile ] - allowNullValues: true - initialCapacity: 100 - maximumSize: 500 - enableRecordStats: false - expireAfterWriteMinutes: 1 - expireAfterAccessMinutes: 1 - refreshAfterWriteMinutes: 1 + expireAfterWriteSeconds: 320 mapCaches: - - names: [ cacheB ] - allowNullValues: true - storeByValue: true apiKey: name: apikey keyPattern: resolve_$keyhash$:v0 @@ -69,9 +48,3 @@ cache: userAllowedTenant: name: userAccessTenant keyPattern: user_access_tenant_$user_id$_$tenant_id$:v0 - formattingUserProfileCache: - name: formattingUserProfile - keyPattern: formatting_user_profile$user_id$:v0 - template: - name: template - key-pattern: ------ diff --git a/annotation-service/annotation-web/src/main/resources/config/db-devel.yml b/annotation-service/annotation-web/src/main/resources/config/db-devel.yml index 22a089fbd..e5299bb04 100644 --- a/annotation-service/annotation-web/src/main/resources/config/db-devel.yml +++ b/annotation-service/annotation-web/src/main/resources/config/db-devel.yml @@ -1,7 +1,10 @@ spring: + datasource: + maxIdle: 10 + minIdle: 5 + maxActive: 10 jpa: show-sql: true properties: hibernate: - show_sql: true - format_sql: false + format_sql: false \ No newline at end of file diff --git a/annotation-service/annotation-web/src/main/resources/config/db.yml b/annotation-service/annotation-web/src/main/resources/config/db.yml index 12f21a0f9..d8c511a44 100644 --- a/annotation-service/annotation-web/src/main/resources/config/db.yml +++ b/annotation-service/annotation-web/src/main/resources/config/db.yml @@ -1,7 +1,11 @@ spring: jpa: properties: + org: + hibernate: + flushMode: MANUAL hibernate: + globally_quoted_identifiers: true ddl-auto: validate dialect: org.hibernate.dialect.PostgreSQLDialect hibernate: @@ -16,7 +20,7 @@ spring: hikari: connection-timeout: 30000 minimum-idle: 3 - maximum-pool-size: 5 + maximum-pool-size: 10 idle-timeout: 600000 max-lifetime: 1800000 diff --git a/annotation-service/annotation-web/src/main/resources/config/email.yml b/annotation-service/annotation-web/src/main/resources/config/email.yml deleted file mode 100644 index fb7c94ba0..000000000 --- a/annotation-service/annotation-web/src/main/resources/config/email.yml +++ /dev/null @@ -1,14 +0,0 @@ -spring: - mail: - host: ${MAIL_HOST:} - port: ${MAIL_PORT:} - username: ${MAIL_USERNAME:} - password: ${MAIL_PASSWORD:} - properties: - mail: - smtp: - auth: ${MAIL_AUTH:} - starttls: - enable: ${MAIL_TLS:} -email: - address: ${MAIL_ADDRESS:} \ No newline at end of file diff --git a/annotation-service/annotation-web/src/main/resources/config/formatting.yml b/annotation-service/annotation-web/src/main/resources/config/formatting.yml deleted file mode 100644 index abdc31184..000000000 --- a/annotation-service/annotation-web/src/main/resources/config/formatting.yml +++ /dev/null @@ -1,6 +0,0 @@ -formatting: - options: - integer-format: "%,d" - decimal-digits-round: 2 - decimal-format: "#0.00" - date-time-format: "YYYY-MM-dd'T'HH:mm:ss" diff --git a/annotation-service/annotation-web/src/main/resources/config/idpclaims.yml b/annotation-service/annotation-web/src/main/resources/config/idpclaims.yml index 3372e4ca7..97ff4a10e 100644 --- a/annotation-service/annotation-web/src/main/resources/config/idpclaims.yml +++ b/annotation-service/annotation-web/src/main/resources/config/idpclaims.yml @@ -37,3 +37,5 @@ idpclient: - type: azp Authorities: - type: authorities + ExternalProviderName: + - type: identity_provider \ No newline at end of file diff --git a/annotation-service/annotation-web/src/main/resources/config/permissions.yml b/annotation-service/annotation-web/src/main/resources/config/permissions.yml index 59115ee60..7b7fb2ed1 100644 --- a/annotation-service/annotation-web/src/main/resources/config/permissions.yml +++ b/annotation-service/annotation-web/src/main/resources/config/permissions.yml @@ -5,26 +5,26 @@ permissions: # Tenants BrowseTenant: roles: - - ic-sti-superuser + - Admin clients: [ ] allowAnonymous: false allowAuthenticated: false EditTenant: roles: - - ic-sti-superuser + - Admin clients: [ ] allowAnonymous: false allowAuthenticated: false DeleteTenant: roles: - - ic-sti-superuser + - Admin claims: [ ] clients: [ ] allowAnonymous: false allowAuthenticated: false AllowNoTenant: roles: - - ic-sti-superuser + - Admin claims: [ ] clients: [ ] allowAnonymous: false @@ -32,21 +32,19 @@ permissions: # Users BrowseUser: roles: - - ic-sti-superuser - - tenantadmin + - Admin clients: [ ] allowAnonymous: true allowAuthenticated: false EditUser: roles: - - admin - - ic-sti-superuser + - Admin clients: [ ] allowAnonymous: false allowAuthenticated: false DeleteUser: roles: - - ic-sti-superuser + - Admin claims: [ ] clients: [ ] allowAnonymous: false @@ -54,20 +52,19 @@ permissions: # UserContactInfo BrowseUserContactInfo: roles: - - ic-sti-superuser + - Admin clients: [ ] allowAnonymous: true allowAuthenticated: false EditUserContactInfo: roles: - - ic-sti-superuser - - user + - Admin clients: [ ] allowAnonymous: false allowAuthenticated: false DeleteUserContactInfo: roles: - - ic-sti-superuser + - Admin claims: [ ] clients: [ ] allowAnonymous: false @@ -94,13 +91,13 @@ permissions: #Tenant Configuration BrowseTenantConfiguration: roles: - - ic-sti-superuser + - Admin clients: [ ] allowAnonymous: false allowAuthenticated: false EditTenantConfiguration: roles: - - ic-sti-superuser + - Admin clients: [ ] allowAnonymous: false allowAuthenticated: false diff --git a/annotation-service/annotation-web/src/main/resources/config/security-devel.yml b/annotation-service/annotation-web/src/main/resources/config/security-devel.yml new file mode 100644 index 000000000..7692e66d9 --- /dev/null +++ b/annotation-service/annotation-web/src/main/resources/config/security-devel.yml @@ -0,0 +1,6 @@ +web: + security: + idp: + resource: + jwt: + audiences: [ "dmp_annotation" ] \ No newline at end of file diff --git a/annotation-service/annotation-web/src/main/resources/config/security.yml b/annotation-service/annotation-web/src/main/resources/config/security.yml index 3024921aa..8f41034ac 100644 --- a/annotation-service/annotation-web/src/main/resources/config/security.yml +++ b/annotation-service/annotation-web/src/main/resources/config/security.yml @@ -2,19 +2,13 @@ web: security: enabled: true authorized-endpoints: [ api ] - allowed-endpoints: [ public, dataset, master-item, test ] + allowed-endpoints: [ public ] idp: api-key: - enabled: true - authorization-header: Authorization - client-id: ${IDP_APIKEY_CLIENT_ID} - client-secret: ${IDP_APIKEY_CLIENT_SECRET} - scope: ${IDP_APIKEY_SCOPE} + enabled: false resource: - token-type: JWT - opaque: - client-id: ${IDP_OPAQUE_CLIENT_ID} - client-secret: ${IDP_OPAQUE_CLIENT_SECRET} + token-type: JWT #| opaque jwt: claims: [ role, x-role ] - issuer-uri: ${IDP_ISSUER_URI:} \ No newline at end of file + issuer-uri: ${IDP_ISSUER_URI} + validIssuer: ${IDP_ISSUER_URI} \ No newline at end of file diff --git a/annotation-service/annotation-web/src/main/resources/config/server.yml b/annotation-service/annotation-web/src/main/resources/config/server.yml index bc9a15d9f..9a4a97cbc 100644 --- a/annotation-service/annotation-web/src/main/resources/config/server.yml +++ b/annotation-service/annotation-web/src/main/resources/config/server.yml @@ -1,3 +1,13 @@ server: port: ${WEB_PORT} - forward-headers-strategy: NONE \ No newline at end of file + forward-headers-strategy: NONE + tomcat: + threads: + max: 20 + max-connections: 10000 + + spring: + servlet: + multipart: + max-file-size: 10MB + max-request-size: 10MB \ No newline at end of file diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/cache/FormattingUserprofileCacheCacheService.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/cache/FormattingUserprofileCacheCacheService.java deleted file mode 100644 index 346050a47..000000000 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/cache/FormattingUserprofileCacheCacheService.java +++ /dev/null @@ -1,93 +0,0 @@ -package gr.cite.annotation.cache; - -import gr.cite.annotation.config.formatting.FormattingUserprofileCacheOptions; -import gr.cite.annotation.event.UserTouchedEvent; -import gr.cite.tools.cache.CacheService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.event.EventListener; -import org.springframework.stereotype.Service; - -import java.util.HashMap; -import java.util.Locale; -import java.util.UUID; - -@Service -public class FormattingUserprofileCacheCacheService extends CacheService { - - public static class UserFormattingProfileCacheValue { - - public UserFormattingProfileCacheValue() { - } - - public UserFormattingProfileCacheValue(UUID userId, String zone, String culture, String language) { - this.userId = userId; - this.zone = zone; - this.culture = culture; - this.language = language; - } - - private UUID userId; - private String zone; - private String culture; - private String language; - - public String getZone() { - return zone; - } - - public void setZone(String zone) { - this.zone = zone; - } - - public String getCulture() { - return culture; - } - - public void setCulture(String culture) { - this.culture = culture; - } - - public String getLanguage() { - return language; - } - - public void setLanguage(String language) { - this.language = language; - } - - public UUID getUserId() { - return userId; - } - - public void setUserId(UUID userId) { - this.userId = userId; - } - } - - @Autowired - public FormattingUserprofileCacheCacheService(FormattingUserprofileCacheOptions options) { - super(options); - } - - @EventListener - public void handleUserTouchedEvent(UserTouchedEvent event) { - if (event.getUserId() != null) this.evict(this.buildKey(event.getUserId())); - } - - @Override - protected Class valueClass() { - return UserFormattingProfileCacheValue.class; - } - - @Override - public String keyOf(UserFormattingProfileCacheValue value) { - return this.buildKey(value.getUserId()); - } - - - public String buildKey(UUID userId) { - return this.generateKey(new HashMap<>() {{ - put("$user_id$", userId.toString().toLowerCase(Locale.ROOT)); - }}); - } -} diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/config/email/EmailConfig.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/config/email/EmailConfig.java deleted file mode 100644 index acb6a8b79..000000000 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/config/email/EmailConfig.java +++ /dev/null @@ -1,9 +0,0 @@ -package gr.cite.annotation.config.email; - -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -@Configuration -@EnableConfigurationProperties(EmailProperties.class) -public class EmailConfig { -} diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/config/email/EmailProperties.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/config/email/EmailProperties.java deleted file mode 100644 index 65e80a319..000000000 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/config/email/EmailProperties.java +++ /dev/null @@ -1,17 +0,0 @@ -package gr.cite.annotation.config.email; - -import org.springframework.boot.context.properties.ConfigurationProperties; - -@ConfigurationProperties(prefix = "email") -public class EmailProperties { - - private final String address; - - public EmailProperties(String address) { - this.address = address; - } - - public String getAddress() { - return address; - } -} diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/config/formatting/FormattingServiceConfiguration.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/config/formatting/FormattingServiceConfiguration.java deleted file mode 100644 index 20b43545f..000000000 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/config/formatting/FormattingServiceConfiguration.java +++ /dev/null @@ -1,9 +0,0 @@ -package gr.cite.annotation.config.formatting; - -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -@Configuration -@EnableConfigurationProperties(FormattingServiceProperties.class) -public class FormattingServiceConfiguration { -} diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/config/formatting/FormattingServiceProperties.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/config/formatting/FormattingServiceProperties.java deleted file mode 100644 index e9427a2c6..000000000 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/config/formatting/FormattingServiceProperties.java +++ /dev/null @@ -1,38 +0,0 @@ -package gr.cite.annotation.config.formatting; - -import org.springframework.boot.context.properties.ConfigurationProperties; - -@ConfigurationProperties(prefix = "formatting.options") -public class FormattingServiceProperties { - - private final String integerFormat; - - private final String decimalFormat; - - private final String dateTimeFormat; - - private final Integer decimalDigitsRound; - - public FormattingServiceProperties(String integerFormat, String decimalFormat, String dateTimeFormat, Integer decimalDigitsRound) { - this.integerFormat = integerFormat; - this.decimalFormat = decimalFormat; - this.dateTimeFormat = dateTimeFormat; - this.decimalDigitsRound = decimalDigitsRound; - } - - public String getIntegerFormat() { - return integerFormat; - } - - public String getDecimalFormat() { - return decimalFormat; - } - - public String getDateTimeFormat() { - return dateTimeFormat; - } - - public Integer getDecimalDigitsRound() { - return decimalDigitsRound; - } -} \ No newline at end of file diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/config/formatting/FormattingUserprofileCacheOptions.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/config/formatting/FormattingUserprofileCacheOptions.java deleted file mode 100644 index 7c473bfeb..000000000 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/config/formatting/FormattingUserprofileCacheOptions.java +++ /dev/null @@ -1,10 +0,0 @@ -package gr.cite.annotation.config.formatting; - -import gr.cite.tools.cache.CacheOptions; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -@Configuration -@ConfigurationProperties(prefix = "cache.formatting-user-profile-cache") -public class FormattingUserprofileCacheOptions extends CacheOptions { -} diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/service/formatting/FormattingService.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/service/formatting/FormattingService.java deleted file mode 100644 index da1b8646f..000000000 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/service/formatting/FormattingService.java +++ /dev/null @@ -1,26 +0,0 @@ -package gr.cite.annotation.service.formatting; - -import java.time.Instant; -import java.util.Locale; -import java.util.TimeZone; -import java.util.UUID; - -public interface FormattingService { - - String format(int value, UUID userId, String format, Locale locale); - - String format(int value, String format, Locale locale); - - String format(long value, UUID userId, String format, Locale locale); - - String format(long value, String format, Locale locale); - - String format(double value, UUID userId, Integer decimals, String format, Locale locale); - - String format(double value, Integer decimals, String format, Locale locale); - - String format(Instant value, UUID userId, TimeZone timezone, String format, Locale locale); - - String format(Instant value, TimeZone timeZone, String format, Locale locale); -} - diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/service/formatting/FormattingServiceImpl.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/service/formatting/FormattingServiceImpl.java deleted file mode 100644 index 5229e52e4..000000000 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/service/formatting/FormattingServiceImpl.java +++ /dev/null @@ -1,171 +0,0 @@ -package gr.cite.annotation.service.formatting; - -import gr.cite.annotation.cache.FormattingUserprofileCacheCacheService; -import gr.cite.annotation.config.formatting.FormattingServiceProperties; -import gr.cite.annotation.convention.ConventionService; -import gr.cite.annotation.locale.LocaleService; -import gr.cite.tools.data.query.QueryFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; -import org.springframework.web.context.annotation.RequestScope; - -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.text.DecimalFormat; -import java.text.DecimalFormatSymbols; -import java.text.NumberFormat; -import java.time.Instant; -import java.time.ZoneId; -import java.time.ZoneOffset; -import java.time.format.DateTimeFormatter; -import java.time.format.FormatStyle; -import java.util.Locale; -import java.util.TimeZone; -import java.util.UUID; - -@Component -@RequestScope -public class FormattingServiceImpl implements FormattingService { - - private final QueryFactory queryFactory; - private final ConventionService conventionService; - private final LocaleService localeService; - private final FormattingServiceProperties properties; - private final FormattingUserprofileCacheCacheService formattingUserprofileCacheCacheService; - - @Autowired - public FormattingServiceImpl(QueryFactory queryFactory, - ConventionService conventionService, - LocaleService localeService, - FormattingServiceProperties properties, - FormattingUserprofileCacheCacheService formattingUserprofileCacheCacheService - ) { - this.queryFactory = queryFactory; - this.conventionService = conventionService; - this.localeService = localeService; - this.properties = properties; - this.formattingUserprofileCacheCacheService = formattingUserprofileCacheCacheService; - } - - public String format(int value, UUID userId, String format, Locale locale) { - return this.formatNonDecimal(value, userId, format, locale); - } - - private String formatNonDecimal(Number value,UUID userId, String format, Locale locale) { - Locale localeToUse = this.localeService.culture(); - if (locale != null) { - localeToUse = locale; - } else if (userId != null) { - FormattingUserprofileCacheCacheService.UserFormattingProfileCacheValue profile = this.getUserProfile(userId); - if (profile != null) { - localeToUse = this.localeService.cultureSafe(profile.getCulture()); - } - } - - String formatToUse = !this.conventionService.isNullOrEmpty(format) ? format : this.properties.getIntegerFormat(); - return this.formatNonDecimal(value, formatToUse, localeToUse); - } - - public String format(int value, String format, Locale locale) { - return this.formatNonDecimal(value, format, locale); - } - - private String formatNonDecimal(Number value, String format, Locale locale) { - if (this.conventionService.isNullOrEmpty(format) && locale != null) return NumberFormat.getInstance(locale).format(value); - else if (!this.conventionService.isNullOrEmpty(format) && locale == null) return String.format(format, value); - else if (!this.conventionService.isNullOrEmpty(format) && locale != null) return String.format(locale, format, value); - - return NumberFormat.getInstance(Locale.ROOT).format(value); - } - - public String format(long value, UUID userId, String format, Locale locale) { - return this.formatNonDecimal(value, userId, format, locale); - } - - public String format(long value, String format, Locale locale) { - return this.formatNonDecimal(value, format, locale); - } - - public String format(double value, UUID userId, Integer decimals, String format, Locale locale) { - Locale localeToUse = this.localeService.culture(); - if (locale != null) { - localeToUse = locale; - } else if (userId != null) { - FormattingUserprofileCacheCacheService.UserFormattingProfileCacheValue profile = this.getUserProfile(userId); - if (profile != null) { - localeToUse = this.localeService.cultureSafe(profile.getCulture()); - } - } - - String formatToUse = !this.conventionService.isNullOrEmpty(format) ? format : this.properties.getDecimalFormat(); - int decimalsToUse = decimals != null ? decimals : this.properties.getDecimalDigitsRound(); - return this.format(value, decimalsToUse, formatToUse, localeToUse); - } - - public String format(double value, Integer decimals, String format, Locale locale) { - double val = value; - if (decimals != null) { - BigDecimal bd = new BigDecimal(Double.toString(value)); - bd = bd.setScale(decimals, RoundingMode.HALF_UP); - val = bd.doubleValue(); - } - - if (this.conventionService.isNullOrEmpty(format) && locale != null) return NumberFormat.getInstance(locale).format(val); - else if (!this.conventionService.isNullOrEmpty(format) && locale == null) return new DecimalFormat(format).format(val); - else if (!this.conventionService.isNullOrEmpty(format) && locale != null) return new DecimalFormat(format, new DecimalFormatSymbols(locale)).format(val); - - return NumberFormat.getInstance(Locale.ROOT).format(val); - } - - public String format(Instant value, UUID userId, TimeZone timezone, String format, Locale locale) { - FormattingUserprofileCacheCacheService.UserFormattingProfileCacheValue profile = null; - if (userId != null && (locale == null || timezone == null)) { - profile = this.getUserProfile(userId); - } - - Locale localeToUse = this.localeService.culture(); - if (locale != null) { - localeToUse = locale; - } else if (userId != null) { - localeToUse = this.localeService.cultureSafe(profile.getCulture()); - } - - TimeZone timezoneToUse = this.localeService.timezone(); - if (timezone != null) { - timezoneToUse = timezone; - } else if (userId != null) { - timezoneToUse = this.localeService.timezoneSafe(profile.getZone()); - } - - String formatToUse = !this.conventionService.isNullOrEmpty(format) ? format : this.properties.getDateTimeFormat(); - return this.format(value, timezoneToUse, formatToUse, localeToUse); - } - - public String format(Instant value, TimeZone timeZone, String format, Locale locale) { - ZoneId zoneId = ZoneId.from(ZoneOffset.UTC); - - if (timeZone != null) { - zoneId = timeZone.toZoneId(); - } - if (this.conventionService.isNullOrEmpty(format) && locale != null) DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL, FormatStyle.MEDIUM).withLocale(locale).withZone(zoneId).format(value); - else if (!this.conventionService.isNullOrEmpty(format) && locale == null) return DateTimeFormatter.ofPattern(format).withZone(zoneId).format(value); - else if (!this.conventionService.isNullOrEmpty(format) && locale != null) return DateTimeFormatter.ofPattern(format, locale).withZone(zoneId).format(value); - - return DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL, FormatStyle.MEDIUM).withZone(zoneId).format(value); - } - - private FormattingUserprofileCacheCacheService.UserFormattingProfileCacheValue getUserProfile(UUID userId) { - FormattingUserprofileCacheCacheService.UserFormattingProfileCacheValue cacheValue = this.formattingUserprofileCacheCacheService.lookup(this.formattingUserprofileCacheCacheService.buildKey(userId)); - if (cacheValue != null) { - return cacheValue; - } else { -// UserEntity user = this.queryFactory.query(UserQuery.class).ids(userId).firstAs(new BaseFieldSet().ensure(User._culture).ensure(User._language).ensure(User._timezone).ensure(User._id)); -// if (user == null) return null; -// cacheValue = new FormattingUserprofileCacheCacheService.UserFormattingProfileCacheValue(userId, user.getTimezone(), user.getCulture(), user.getLanguage()); -// this.formattingUserprofileCacheCacheService.put(cacheValue); - - return cacheValue; - } - } -} -