Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions .github/workflows/gradle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,32 +59,32 @@ jobs:
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2

codacy-analysis-cli:
name: Codacy Analysis CLI
runs-on: ubuntu-latest
needs: pre-process
if: needs.pre-process.outputs.were-only-docs-updated != 'yes'
permissions:
actions: read
contents: read
security-events: write
steps:
- name: Checkout code
uses: actions/checkout@main
- name: Run Codacy Analysis CLI
uses: codacy/codacy-analysis-cli-action@master
with:
output: results.sarif
format: sarif
# Adjust severity of non-security issues
gh-code-scanning-compat: true
# This will handover control about PR rejection to the GitHub side
max-allowed-issues: 2147483647
# Upload the SARIF file generated in the previous step
- name: Upload SARIF results file
uses: github/codeql-action/upload-sarif@main
with:
sarif_file: results.sarif
# codacy-analysis-cli:
# name: Codacy Analysis CLI
# runs-on: ubuntu-latest
# needs: pre-process
# if: needs.pre-process.outputs.were-only-docs-updated != 'yes'
# permissions:
# actions: read
# contents: read
# security-events: write
# steps:
# - name: Checkout code
# uses: actions/checkout@main
# - name: Run Codacy Analysis CLI
# uses: codacy/codacy-analysis-cli-action@master
# with:
# output: results.sarif
# format: sarif
# Adjust severity of non-security issues
# gh-code-scanning-compat: true
# This will handover control about PR rejection to the GitHub side
# max-allowed-issues: 2147483647
# Upload the SARIF file generated in the previous step
# - name: Upload SARIF results file
# uses: github/codeql-action/upload-sarif@main
# with:
# sarif_file: results.sarif

preflight-smoke-test-check:
name: Preflight Smoke Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import com.vmware.vipclient.i18n.I18nFactory;
import com.vmware.vipclient.i18n.l2.common.PatternCategory;
import com.vmware.vipclient.i18n.util.JSONUtils;

import org.json.JSONObject;

import java.util.Locale;
Expand Down Expand Up @@ -78,7 +80,8 @@ public String formatDate(Object obj, String pattern, String timeZone, Locale loc
PatternMessage p = (PatternMessage) factory.getMessageInstance(PatternMessage.class);
JSONObject localeFormatData = p.getPatternMessage(locale);
if(localeFormatData != null)
dateFormatData = (JSONObject) localeFormatData.get(PatternCategory.DATES.toString());
dateFormatData = (JSONObject) JSONUtils.getFromJSONObject(localeFormatData, PatternCategory.DATES.toString());
// dateFormatData = (JSONObject) localeFormatData.get(PatternCategory.DATES.toString());
if (dateFormatData == null) {
throw new RuntimeException("Can't format " + obj + " without pattern data!");
}
Expand Down Expand Up @@ -106,7 +109,8 @@ public String formatDate(Object obj, String pattern, String timeZone, String lan
PatternMessage p = (PatternMessage) factory.getMessageInstance(PatternMessage.class);
JSONObject localeFormatData = p.getPatternMessage(language, region);
if(localeFormatData != null)
dateFormatData = (JSONObject) localeFormatData.get(PatternCategory.DATES.toString());
dateFormatData = (JSONObject) JSONUtils.getFromJSONObject(localeFormatData, PatternCategory.DATES.toString());
// dateFormatData = (JSONObject) localeFormatData.get(PatternCategory.DATES.toString());
if (dateFormatData == null) {
throw new RuntimeException("Can't format " + obj + " without pattern data!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,10 @@ public boolean postStrings(final Locale locale, final String component,
sourcesList.addAll(sources);
List<JSONObject> removedList = new ArrayList<>();
for (JSONObject jo : sourcesList) {
String key = (String) jo.get(ConstantsKeys.KEY);
String source = (String) jo.get(ConstantsKeys.SOURCE);
String key = (String) JSONUtils.getFromJSONObject(jo, ConstantsKeys.KEY);
String source = (String) JSONUtils.getFromJSONObject(jo, ConstantsKeys.SOURCE);
// String key = (String) jo.get(ConstantsKeys.KEY);
// String source = (String) jo.get(ConstantsKeys.SOURCE);
dto.setKey(key);
dto.setSource(source);
dto.setLocale(ConstantsKeys.LATEST);
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/com/vmware/vipclient/i18n/formats/DateFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.vmware.vipclient.i18n.exceptions.VIPJavaClientException;
import com.vmware.vipclient.i18n.messages.api.url.URLUtils;
import com.vmware.vipclient.i18n.util.ConstantsKeys;
import com.vmware.vipclient.i18n.util.JSONUtils;

public class DateFormat extends BaseFormat {
private Logger logger = LoggerFactory.getLogger(DateFormat.class);
Expand Down Expand Up @@ -54,12 +55,16 @@ private String getFormatFromRemote(String longDate, String pattern) {
try {
retJson = new JSONObject(retJsonStr);
if (retJson != null) {
JSONObject dataJson = (JSONObject) retJson
.get(ConstantsKeys.DATA);
JSONObject dataJson = (JSONObject) JSONUtils.getFromJSONObject(retJson, ConstantsKeys.DATA);
// JSONObject dataJson = (JSONObject) retJson
// .get(ConstantsKeys.DATA);
if (dataJson != null) {
format = dataJson.get(ConstantsKeys.FORMATTED_DATE) == null ? ""
: dataJson.get(ConstantsKeys.FORMATTED_DATE)
format = JSONUtils.getFromJSONObject(dataJson, ConstantsKeys.FORMATTED_DATE) == null ? ""
: JSONUtils.getFromJSONObject(dataJson, ConstantsKeys.FORMATTED_DATE)
.toString();
// format = dataJson.get(ConstantsKeys.FORMATTED_DATE) == null ? ""
// : dataJson.get(ConstantsKeys.FORMATTED_DATE)
// .toString();
}
}
} catch (JSONException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.vmware.vipclient.i18n.exceptions.VIPJavaClientException;
import com.vmware.vipclient.i18n.messages.api.url.URLUtils;
import com.vmware.vipclient.i18n.util.ConstantsKeys;
import com.vmware.vipclient.i18n.util.JSONUtils;

public class NumberFormat extends BaseFormat {
Logger logger = LoggerFactory.getLogger(NumberFormat.class);
Expand Down Expand Up @@ -54,12 +55,16 @@ private String getFormatFromRemote(String number, String scale) {
try {
retJson = new JSONObject(retJsonStr);
if (retJson != null) {
JSONObject dataJson = (JSONObject) retJson
.get(ConstantsKeys.DATA);
JSONObject dataJson = (JSONObject) JSONUtils.getFromJSONObject(retJson, ConstantsKeys.DATA);
// JSONObject dataJson = (JSONObject) retJson
// .get(ConstantsKeys.DATA);
if (dataJson != null) {
format = dataJson.get(ConstantsKeys.FORMATTED_NUMBER) == null ? ""
: dataJson.get(ConstantsKeys.FORMATTED_NUMBER)
format = JSONUtils.getFromJSONObject(dataJson,ConstantsKeys.FORMATTED_NUMBER) == null ? ""
: JSONUtils.getFromJSONObject(dataJson,ConstantsKeys.FORMATTED_NUMBER)
.toString();
// format = dataJson.get(ConstantsKeys.FORMATTED_NUMBER) == null ? ""
// : dataJson.get(ConstantsKeys.FORMATTED_NUMBER)
// .toString();
}
}
} catch (JSONException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.json.JSONObject;

import com.vmware.vipclient.i18n.l2.common.PatternKeys;
import com.vmware.vipclient.i18n.util.JSONUtils;

public class IntegerDigitsParser {
private JSONObject numberSymbols;
Expand All @@ -17,7 +18,8 @@ public IntegerDigitsParser(JSONObject numberSymbols) {

public String groupIntegerDigits(String integerDigits, int groupingSize) {
if (integerDigits.length() > groupingSize) {
String localizedGroupSep = (String) numberSymbols.get(PatternKeys.GROUP);
String localizedGroupSep = (String) JSONUtils.getFromJSONObject(numberSymbols, PatternKeys.GROUP);
// String localizedGroupSep = (String) numberSymbols.get(PatternKeys.GROUP);
String reverseNumStr = new StringBuilder(integerDigits).reverse().toString();
StringBuilder groupedReverseNumStr = new StringBuilder(reverseNumStr);
int index;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.vmware.vipclient.i18n.l2.common.PatternCategory;
import com.vmware.vipclient.i18n.l2.common.PatternKeys;
import com.vmware.vipclient.i18n.messages.service.PatternService;
import com.vmware.vipclient.i18n.util.JSONUtils;

public class PluralRules implements Serializable {
static Logger logger = LoggerFactory.getLogger(PluralRules.class);
Expand Down Expand Up @@ -1247,7 +1248,8 @@ public static PluralRules forLocale(Locale locale, PluralType type) {
try {
JSONObject pluralPattern = new PatternService().getPatternsByCategory(locale.toLanguageTag(),
PatternCategory.PLURALS.toString());
pluralRules = (JSONObject) pluralPattern.get(PatternKeys.PLURALRULES);
pluralRules = (JSONObject) JSONUtils.getFromJSONObject(pluralPattern, PatternKeys.PLURALRULES);
// pluralRules = (JSONObject) pluralPattern.get(PatternKeys.PLURALRULES);
} catch (NullPointerException e) {
logger.info("Lack plural pattern!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import com.vmware.vipclient.i18n.l2.common.PatternKeys;
import com.vmware.vipclient.i18n.l2.text.NumberFormat;
import com.vmware.vipclient.i18n.util.ConstantsKeys;
import com.vmware.vipclient.i18n.util.JSONUtils;

import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -57,7 +59,8 @@ public String format(Object value, String currencyCode, Integer fractionSize, St
validateCurrencyCode(currencyCode);
numberFormatData = getCurrencyRelatedData(localeFormatData, currencyCode);
} else {
numberFormatData = (JSONObject) localeFormatData.get(PatternCategory.NUMBERS.toString());
numberFormatData = (JSONObject) JSONUtils.getFromJSONObject(localeFormatData, PatternCategory.NUMBERS.toString());
// numberFormatData = (JSONObject) localeFormatData.get(PatternCategory.NUMBERS.toString());
}
if (numberFormatData == null) {
// return (String) value;
Expand All @@ -66,15 +69,19 @@ public String format(Object value, String currencyCode, Integer fractionSize, St
NumberFormat numberFormat = NumberFormat.getInstance(numberFormatData, style);
formatNumber = numberFormat.format(value, fractionSize);
if (style == NumberFormat.PERCENTSTYLE) {
String percentSymbol = (String) ((JSONObject) numberFormatData.get(PatternKeys.NUMBERSYMBOLS))
.get(PatternKeys.PERCENTSIGN);
String percentSymbol = (String) JSONUtils.getFromJSONObject(((JSONObject) JSONUtils.getFromJSONObject(numberFormatData, PatternKeys.NUMBERSYMBOLS))
, PatternKeys.PERCENTSIGN);
//String percentSymbol = (String) ((JSONObject) numberFormatData.get(PatternKeys.NUMBERSYMBOLS))
// .get(PatternKeys.PERCENTSIGN);
formatNumber = formatNumber.replace(String.valueOf(ConstantChars.PERCENTSIGN), percentSymbol);
} else if (style == NumberFormat.CURRENCYSTYLE) {
JSONObject currencyData = (JSONObject) numberFormatData.get(PatternKeys.CURRENCY);
JSONObject currencyData = (JSONObject) JSONUtils.getFromJSONObject(numberFormatData, PatternKeys.CURRENCY);
// JSONObject currencyData = (JSONObject) numberFormatData.get(PatternKeys.CURRENCY);
// String narrowCurrencySymbol = (String) currencyData.get(PatternKeys.NARROWCURRENCYSYMBOL);
// String currencySymbol = narrowCurrencySymbol != null? narrowCurrencySymbol : (String)
// currencyData.get(PatternKeys.CURRENCYSYMBOL);
String currencySymbol = (String) currencyData.get(PatternKeys.CURRENCYSYMBOL);
String currencySymbol = (String) JSONUtils.getFromJSONObject(currencyData, PatternKeys.CURRENCYSYMBOL);
// String currencySymbol = (String) currencyData.get(PatternKeys.CURRENCYSYMBOL);
formatNumber = formatNumber.replace(String.valueOf(ConstantChars.CURRENCY_SIGN),
currencySymbol);
}
Expand Down Expand Up @@ -113,7 +120,8 @@ public String format(Object value, String currencyCode, Integer fractionSize, Lo
}
numberFormatData = getCurrencyRelatedData(localeFormatData, actualCurrencyCode);
} else {
numberFormatData = (JSONObject) localeFormatData.get(PatternCategory.NUMBERS.toString());
numberFormatData = (JSONObject) JSONUtils.getFromJSONObject(localeFormatData, PatternCategory.NUMBERS.toString());
// numberFormatData = (JSONObject) localeFormatData.get(PatternCategory.NUMBERS.toString());
}
if (numberFormatData == null) {
// return (String) value;
Expand All @@ -122,15 +130,19 @@ public String format(Object value, String currencyCode, Integer fractionSize, Lo
NumberFormat numberFormat = NumberFormat.getInstance(numberFormatData, style);
formatNumber = numberFormat.format(value, fractionSize);
if (style == NumberFormat.PERCENTSTYLE) {
String percentSymbol = (String) ((JSONObject) numberFormatData.get(PatternKeys.NUMBERSYMBOLS))
.get(PatternKeys.PERCENTSIGN);
String percentSymbol = (String) JSONUtils.getFromJSONObject(((JSONObject) JSONUtils.getFromJSONObject(numberFormatData, PatternKeys.NUMBERSYMBOLS))
,PatternKeys.PERCENTSIGN);
// String percentSymbol = (String) ((JSONObject) numberFormatData.get(PatternKeys.NUMBERSYMBOLS))
// .get(PatternKeys.PERCENTSIGN);
formatNumber = formatNumber.replace(String.valueOf(ConstantChars.PERCENTSIGN), percentSymbol);
} else if (style == NumberFormat.CURRENCYSTYLE) {
JSONObject currencyData = (JSONObject) numberFormatData.get(PatternKeys.CURRENCY);
JSONObject currencyData = (JSONObject) JSONUtils.getFromJSONObject(numberFormatData, PatternKeys.CURRENCY);
// JSONObject currencyData = (JSONObject) numberFormatData.get(PatternKeys.CURRENCY);
// String narrowCurrencySymbol = (String) currencyData.get(PatternKeys.NARROWCURRENCYSYMBOL);
// String currencySymbol = narrowCurrencySymbol != null? narrowCurrencySymbol : (String)
// currencyData.get(PatternKeys.CURRENCYSYMBOL);
String currencySymbol = (String) currencyData.get(PatternKeys.CURRENCYSYMBOL);
String currencySymbol = (String) JSONUtils.getFromJSONObject(currencyData, PatternKeys.CURRENCYSYMBOL);
// String currencySymbol = (String) currencyData.get(PatternKeys.CURRENCYSYMBOL);
formatNumber = formatNumber.replace(String.valueOf(ConstantChars.CURRENCY_SIGN),
currencySymbol);
}
Expand All @@ -139,17 +151,24 @@ public String format(Object value, String currencyCode, Integer fractionSize, Lo

private JSONObject getCurrencyRelatedData(JSONObject allCategoriesData, String currencyCode) {
JSONObject currencyFormatData = new JSONObject();
JSONObject numberFormatData = (JSONObject) allCategoriesData.get(PatternCategory.NUMBERS.toString());
JSONObject currencyData = (JSONObject) ((JSONObject) allCategoriesData.get(PatternKeys.CURRENCIES))
.get(currencyCode);
JSONObject numberFormatData = (JSONObject) JSONUtils.getFromJSONObject(allCategoriesData, PatternCategory.NUMBERS.toString());
JSONObject currencyData = (JSONObject) JSONUtils.getFromJSONObject(((JSONObject) JSONUtils.getFromJSONObject(allCategoriesData, PatternKeys.CURRENCIES))
, currencyCode);
// JSONObject numberFormatData = (JSONObject) allCategoriesData.get(PatternCategory.NUMBERS.toString());
// JSONObject currencyData = (JSONObject) ((JSONObject) allCategoriesData.get(PatternKeys.CURRENCIES))
// .get(currencyCode);
if (currencyData == null) {
throw new IllegalArgumentException("Unsupported currency code " + currencyCode + ".");
}
JSONObject currencySupplementalData = (JSONObject) ((JSONObject) allCategoriesData
.get(PatternCategory.SUPPLEMENTAL.toString())).get(PatternKeys.CURRENCIES);
JSONObject currencySupplementalData = (JSONObject) JSONUtils.getFromJSONObject(((JSONObject) JSONUtils.getFromJSONObject(allCategoriesData
, PatternCategory.SUPPLEMENTAL.toString())), PatternKeys.CURRENCIES);
//JSONObject currencySupplementalData = (JSONObject) ((JSONObject) allCategoriesData
// .get(PatternCategory.SUPPLEMENTAL.toString())).get(PatternKeys.CURRENCIES);
JSONObject fractionData = null;
try {
fractionData = (JSONObject) ((JSONObject) currencySupplementalData.get(PatternKeys.FRACTIONS)).get(currencyCode);
fractionData = (JSONObject) JSONUtils.getFromJSONObject(((JSONObject) JSONUtils.getFromJSONObject(currencySupplementalData,
PatternKeys.FRACTIONS)), currencyCode);
// fractionData = (JSONObject) ((JSONObject) currencySupplementalData.get(PatternKeys.FRACTIONS)).get(currencyCode);
} catch (org.json.JSONException e) {
logger.info("NumberFormatService - Can't find fractionData, null will be set");
}
Expand Down
Loading
Loading