update configurations
This commit is contained in:
parent
adfc2f5dac
commit
0c2d2e2f6a
|
@ -65,7 +65,7 @@
|
|||
<dependency>
|
||||
<groupId>gr.cite</groupId>
|
||||
<artifactId>cache</artifactId>
|
||||
<version>2.1.0</version>
|
||||
<version>2.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>gr.cite</groupId>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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: ------
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
spring:
|
||||
datasource:
|
||||
maxIdle: 10
|
||||
minIdle: 5
|
||||
maxActive: 10
|
||||
jpa:
|
||||
show-sql: true
|
||||
properties:
|
||||
hibernate:
|
||||
show_sql: true
|
||||
format_sql: false
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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:}
|
|
@ -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"
|
|
@ -37,3 +37,5 @@ idpclient:
|
|||
- type: azp
|
||||
Authorities:
|
||||
- type: authorities
|
||||
ExternalProviderName:
|
||||
- type: identity_provider
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
web:
|
||||
security:
|
||||
idp:
|
||||
resource:
|
||||
jwt:
|
||||
audiences: [ "dmp_annotation" ]
|
|
@ -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:}
|
||||
issuer-uri: ${IDP_ISSUER_URI}
|
||||
validIssuer: ${IDP_ISSUER_URI}
|
|
@ -1,3 +1,13 @@
|
|||
server:
|
||||
port: ${WEB_PORT}
|
||||
forward-headers-strategy: NONE
|
||||
tomcat:
|
||||
threads:
|
||||
max: 20
|
||||
max-connections: 10000
|
||||
|
||||
spring:
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 10MB
|
||||
max-request-size: 10MB
|
|
@ -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<FormattingUserprofileCacheCacheService.UserFormattingProfileCacheValue> {
|
||||
|
||||
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<UserFormattingProfileCacheValue> 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));
|
||||
}});
|
||||
}
|
||||
}
|
|
@ -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 {
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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 {
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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 {
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue