FINERACT-2181: Moneyhelper multitenant configuration fix - #4861
Conversation
| // Fallback for cases where tenant context is not available | ||
| return "default"; |
There was a problem hiding this comment.
I'd really not hardcode something like this. You can't be sure that there will be a default tenant in the system.
Throw an exception if we think this is an invalid case rather than hiding the problem.
6cd7598 to
a024c29
Compare
| private static final ConcurrentHashMap<String, MathContext> mathContextCache = new ConcurrentHashMap<>(); | ||
| public static final int PRECISION = 19; | ||
|
|
||
| private static ConfigurationDomainService staticConfigurationDomainService; |
There was a problem hiding this comment.
I was wondering whether we could remove the ConfigurationDomainService all together and remove @Component also.
This could be a utility class which is instantiated with values during the startup:
- Not managed bean
- No any injections
- Value holder only
- Once instance got started, for each tenants automatically we set the value
What do you think?
There was a problem hiding this comment.
But if we setup the values on startup, the global configuration gets kinda meaningless, doesn't it? Its whole purpose is to be able to dynamically override values in fineract without a redeployment/restart.
There was a problem hiding this comment.
rounding-mode is a trap door configuration, you are not allowed to change once it was set.
There was a problem hiding this comment.
Agreed, I think a validation could be useful for that use case. Changing the rounding would cause troubles for previous calculation consistency
There was a problem hiding this comment.
good, let's proceed with it then as Adam suggested. Although please put a comment there so anybody coming after us knows why it's only fetched once at startup.
91432ce to
9650d6e
Compare
|
ed4bcec to
db17169
Compare
db17169 to
b7c3111
Compare
| private static RoundingMode roundingMode = null; | ||
| private static MathContext mathContext; | ||
| public static final int PRECISION = 19; | ||
| private static final RoundingMode DEFAULT_ROUNDING_MODE = RoundingMode.HALF_EVEN; |
There was a problem hiding this comment.
I am not a big fan of hardcoded "default" values... I would prefer throwing error if it was not set, so it will be blocker if someone tries something nasty!
| return roundingModeProperty.getValue().intValue(); | ||
| } | ||
| } catch (Exception e) { | ||
| log.warn("Failed to read rounding mode from configuration: {}", e.getMessage()); |
There was a problem hiding this comment.
I am not a big fan of swallowing this error...
| } | ||
|
|
||
| // Default to HALF_UP if configuration is not available | ||
| int defaultRoundingMode = RoundingMode.HALF_UP.ordinal(); |
There was a problem hiding this comment.
I dont think we should go with default, fallback value, but even if we would, it is inconsistent to use HALF-UP here and HALF-EVEN in the MoneyHelper... :/
If we are unable to fetch the details of it, then let it fails!
| } | ||
|
|
||
| } catch (Exception e) { | ||
| log.error("Critical error during MoneyHelper initialization for all tenants", e); |
There was a problem hiding this comment.
Dont swallow the issue...let it fails!
| } | ||
|
|
||
| } catch (Exception e) { | ||
| log.error("Critical error during MoneyHelper initialization for all tenants", e); |
There was a problem hiding this comment.
Dont swallow the issue...let it fails!
|
|
||
| } catch (Exception e) { | ||
| failureCount++; | ||
| log.error("Failed to initialize MoneyHelper for tenant '{}'", tenant.getTenantIdentifier(), e); |
There was a problem hiding this comment.
Dont swallow the issue...let it fails!
…o be a utility class
b7c3111 to
d42ffb7
Compare
d42ffb7 to
88596e2
Compare
Description
There were possible rounding issue during the multitenant configuration, when different tenants use different rounding modes. This fix targets to fix that
Ignore if these details are present on the associated Apache Fineract JIRA ticket.
Checklist
Please make sure these boxes are checked before submitting your pull request - thanks!
FYI our guidelines for code reviews are at https://cwiki.apache.org/confluence/display/FINERACT/Code+Review+Guide.