You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by "DaanHoogland (via GitHub)" <gi...@apache.org> on 2023/06/07 13:14:45 UTC

[GitHub] [cloudstack] DaanHoogland commented on a diff in pull request #7605: Format quota email currency values

DaanHoogland commented on code in PR #7605:
URL: https://github.com/apache/cloudstack/pull/7605#discussion_r1221570663


##########
framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaAlertManagerImpl.java:
##########
@@ -208,8 +212,21 @@ public void sendQuotaAlert(DeferredQuotaEmail emailToBeSent) {
                 userNames = userNames.substring(0, userNames.length() - 1);
             }
 
-            final Map<String, String> subjectOptionMap = generateOptionMap(account, userNames, accountDomain, balance, usage, emailType, false);
-            final Map<String, String> bodyOptionMap = generateOptionMap(account, userNames, accountDomain, balance, usage, emailType, true);
+            String currencyLocale = _configDao.getValue(QuotaConfig.QuotaCurrencyLocale.key());
+            String currencySymbol = ObjectUtils.defaultIfNull(_configDao.getValue(QuotaConfig.QuotaCurrencySymbol.key()), QuotaConfig.QuotaCurrencySymbol.defaultValue());
+
+            NumberFormat localeFormat = null;
+
+            if (currencyLocale != null) {
+                Locale locale = Locale.forLanguageTag(currencyLocale);
+                localeFormat = NumberFormat.getNumberInstance(locale);
+            }

Review Comment:
   can you extract this?



##########
utils/src/main/java/com/cloud/utils/NumbersUtil.java:
##########
@@ -147,6 +149,26 @@ public static long parseInterval(String str, long defaultValue) {
         }
     }
 
+    /**
+     * Formats a BigDecimal with the number formatter.
+     * @return
+     * <li>null if value is null;</li>
+     * <li>value.toString() if the numberFormat is null;</li>
+     * <li>the value formatted if both parameters are not null;</li>
+     */
+    public static String getBigDecimalFormattedToNumberFormatIfBothNotNull(BigDecimal value, NumberFormat numberFormat) {

Review Comment:
   I would not make the name this complicated
   ```suggestion
       public static String formatBigDecimalAccordingToNumberFormat(BigDecimal value, NumberFormat numberFormat) {
   ```
   all the null have good definition in the code and the javadoc.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org