FINERACT-2181: Money helper exception handling

This commit is contained in:
Adam Saghy
2025-07-21 18:03:33 +02:00
parent 27bf6d05d5
commit 59409550a7
4 changed files with 32 additions and 76 deletions
@@ -35,7 +35,7 @@ import org.springframework.stereotype.Service;
* A JDBC implementation of {@link TenantDetailsService} for loading a tenants details by a
* <code>tenantIdentifier</code>.
*/
@Service
@Service("tenantDetailsService")
public class JdbcTenantDetailsService implements TenantDetailsService {
private final JdbcTemplate jdbcTemplate;
@@ -33,7 +33,6 @@ import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
public final class MoneyHelper {
public static final int PRECISION = 19;
private static final RoundingMode DEFAULT_ROUNDING_MODE = RoundingMode.HALF_EVEN;
private static final ConcurrentHashMap<String, RoundingMode> roundingModeCache = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<String, MathContext> mathContextCache = new ConcurrentHashMap<>();
@@ -62,7 +61,7 @@ public final class MoneyHelper {
// Clear math context cache to force recreation with new rounding mode
mathContextCache.remove(tenantIdentifier);
log.info("Initialized rounding mode for tenant {}: {}", tenantIdentifier, roundingMode.name());
log.info("Initialized rounding mode for tenant `{}`: {}", tenantIdentifier, roundingMode.name());
}
/**
@@ -77,9 +76,7 @@ public final class MoneyHelper {
RoundingMode roundingMode = roundingModeCache.get(tenantId);
if (roundingMode == null) {
// For integration tests and development, use default if not initialized
log.warn("Rounding mode not initialized for tenant: {}. Using default: {}", tenantId, DEFAULT_ROUNDING_MODE);
return DEFAULT_ROUNDING_MODE;
throw new IllegalStateException("Rounding mode is not initialized for tenant: " + tenantId);
}
return roundingMode;
}