Skip to content

Commit 4a68a31

Browse files
committed
restore API
1 parent e8d44ba commit 4a68a31

23 files changed

+148
-124
lines changed

.github/workflows/gradle.yaml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
unit-test:
1515
name: Unit Test
16-
runs-on: windows-latest
16+
runs-on: ubuntu-latest
1717
needs: pre-process
1818
if: needs.pre-process.outputs.were-only-docs-updated != 'yes'
1919
steps:
@@ -22,8 +22,8 @@ jobs:
2222
- name: Set up JDK
2323
uses: actions/setup-java@v3
2424
with:
25-
distribution: 'adopt'
26-
java-version: '8'
25+
distribution: 'adopt-openj9'
26+
java-version: '11'
2727
cache: 'gradle'
2828
- name: Unit test
2929
run: |
@@ -103,6 +103,7 @@ jobs:
103103
run: |
104104
git clone --branch=master https://github.com/vmware/singleton.git server
105105
cd $GITHUB_WORKSPACE/server/g11n-ws && ./gradlew build -x test
106+
ls -l $GITHUB_WORKSPACE/server/publish/
106107
find $GITHUB_WORKSPACE/server/publish/ -name 'singleton-[0~9]*.jar' -exec mv '{}' $GITHUB_WORKSPACE/server/publish/singleton.jar \;
107108
- uses: actions/upload-artifact@v4
108109
with:
@@ -141,7 +142,12 @@ jobs:
141142
cp ./build/libs/*.jar $GITHUB_WORKSPACE/devops/autotest/client/java/lib/
142143
cd $GITHUB_WORKSPACE/devops/autotest/client/java
143144
./gradlew build -x test
145+
pwd
146+
ls -l src/main/resources/l10n
144147
docker cp src/main/resources/l10n singleton:/
145-
cd target
148+
cd target
149+
sleep 10
150+
docker ps
151+
#curl -k https://localhost:8090/i18n/api/v2/formatting/patterns/locales/en?scope=numbers,dates,currencies,plurals,measurements
146152
java -cp '.:./*' org.testng.TestNG -d test-output testng.xml
147153

src/main/java/com/vmware/vipclient/i18n/base/cache/MessageCacheItem.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ public MessageCacheItem() {
1515

1616
}
1717

18-
public MessageCacheItem(Map<String, Object> dataMap) {
18+
public MessageCacheItem(Map<String, String> dataMap) {
1919
if (dataMap != null)
2020
this.cachedData.putAll(dataMap);
2121
}
2222

23-
public MessageCacheItem (Map<String, Object> dataMap, String etag, long timestamp, Long maxAgeMillis) {
23+
public MessageCacheItem (Map<String, String> dataMap, String etag, long timestamp, Long maxAgeMillis) {
2424
this.setCacheItem(dataMap, etag, timestamp, maxAgeMillis);
2525
}
2626

27-
private final Map<String, Object> cachedData = new HashMap<>();
27+
private final Map<String, String> cachedData = new HashMap<>();
2828

29-
public synchronized void setCacheItem(Map<String, Object> dataToCache, String etag, long timestamp, Long maxAgeMillis) {
29+
public synchronized void setCacheItem(Map<String, String> dataToCache, String etag, long timestamp, Long maxAgeMillis) {
3030
if (dataToCache != null)
3131
this.cachedData.putAll(dataToCache);
3232
this.setCacheItem(etag, timestamp, maxAgeMillis);
@@ -43,7 +43,7 @@ public synchronized void setCacheItem (MessageCacheItem cacheItem) {
4343
this.setCacheItem(cacheItem.getCachedData(), cacheItem.getEtag(), cacheItem.getTimestamp(), cacheItem.getMaxAgeMillis());
4444
}
4545

46-
public Map<String, Object> getCachedData() {
46+
public Map<String, String> getCachedData() {
4747
return cachedData;
4848
}
4949
}

src/main/java/com/vmware/vipclient/i18n/base/instances/TranslationMessage.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,19 @@ private String getMessageWithArgs(String resourceBundle, Locale locale, final St
129129
String source = null;
130130
try {
131131
source = resourceBundle != null ? ResourceBundle.getBundle(resourceBundle).getString(key) :
132-
(String) getMessages(Locale.forLanguageTag(ConstantsKeys.SOURCE), component, false).getMessages().get(key);
132+
getMessages(Locale.forLanguageTag(ConstantsKeys.SOURCE), component, false).getMessages().get(key);
133133
}catch(Exception e){
134134
logger.error(e.getMessage());
135135
}
136136
if (source!=null && !source.isEmpty()) {
137-
String collectedSource = (String) getMessages(LocaleUtility.getSourceLocale(), component, false).getMessages().get(key);
137+
String collectedSource = getMessages(LocaleUtility.getSourceLocale(), component, false).getMessages().get(key);
138138
if (!source.equals(collectedSource)) {
139139
return FormatUtils.formatMsg(source, LocaleUtility.getSourceLocale(), args);
140140
}
141141
}
142142

143143
ComponentService.TranslationsDTO msgsItemDTO = getMessages(messageLocale, component, true);
144-
String message = (String) msgsItemDTO.getMessages().get(key);
144+
String message = msgsItemDTO.getMessages().get(key);
145145
if (message == null || message.isEmpty()) {
146146
if (source != null)
147147
return source;
@@ -213,19 +213,19 @@ private String getMultiVersionMessageWithArgs(String resourceBundle, Locale loca
213213
String source = null;
214214
try {
215215
source = resourceBundle != null ? ResourceBundle.getBundle(resourceBundle).getString(key) :
216-
(String) getMultiVersionMessagesOfKey(Locale.forLanguageTag(ConstantsKeys.SOURCE), version, component, key,false).getMessages().get(version);
216+
getMultiVersionMessagesOfKey(Locale.forLanguageTag(ConstantsKeys.SOURCE), version, component, key,false).getMessages().get(version);
217217
}catch(Exception e){
218218
logger.error(e.getMessage());
219219
}
220220
if (source!=null && !source.isEmpty()) {
221-
String collectedSource = (String) getMultiVersionMessagesOfKey(LocaleUtility.getSourceLocale(), version, component, key,false).getMessages().get(version);
221+
String collectedSource = getMultiVersionMessagesOfKey(LocaleUtility.getSourceLocale(), version, component, key,false).getMessages().get(version);
222222
if (!source.equals(collectedSource)) {
223223
return FormatUtils.formatMsg(source, LocaleUtility.getSourceLocale(), args);
224224
}
225225
}
226226

227227
ComponentService.TranslationsDTO msgsItemDTO = getMultiVersionMessagesOfKey(messageLocale, version, component, key,true);
228-
String message = (String) msgsItemDTO.getMessages().get(version);
228+
String message = msgsItemDTO.getMessages().get(version);
229229
if (message == null || message.isEmpty()) {
230230
if (source != null)
231231
return source;
@@ -487,7 +487,7 @@ public boolean postString(final Locale locale, final String component,
487487
* source's key
488488
* @deprecated Replaced by {@link #getMessages(Locale, String)}
489489
*/
490-
@Deprecated public Map<String, Object> getStrings(final Locale locale,
490+
@Deprecated public Map<String, String> getStrings(final Locale locale,
491491
final String component) {
492492
this.logger.trace("Start to execute TranslationMessage.getStrings");
493493
MessagesDTO dto = new MessagesDTO();
@@ -513,11 +513,11 @@ public boolean postString(final Locale locale, final String component,
513513
* <li>The source messages</li>
514514
* </ul>
515515
*/
516-
public Map<String, Object> getMessages(final Locale locale, final String component) {
516+
public Map<String, String> getMessages(final Locale locale, final String component) {
517517
return getMessages(null, locale, component);
518518
}
519519

520-
public Map<String, Object> getMessages(String resourceBundle, final Locale locale, final String component) {
520+
public Map<String, String> getMessages(String resourceBundle, final Locale locale, final String component) {
521521
Locale messageLocale = locale;
522522
if (messageLocale == null) {
523523
messageLocale = LocaleUtility.getDefaultLocale();
@@ -527,18 +527,18 @@ public Map<String, Object> getMessages(String resourceBundle, final Locale local
527527
throw new VIPJavaClientException(ConstantsMsg.COMPONENT_CANNOT_EMPTY);
528528
}
529529

530-
Map<String, Object> messages = new LinkedHashMap<>();
530+
Map<String, String> messages = new LinkedHashMap<>();
531531

532-
Map<String,Object> sources = resourceBundle != null ? getSourcesFromBundle(resourceBundle):
532+
Map<String, String> sources = resourceBundle != null ? getSourcesFromBundle(resourceBundle):
533533
getMessages(Locale.forLanguageTag(ConstantsKeys.SOURCE), component, false).getMessages();
534534

535535
if(!sources.isEmpty()) {
536-
Map<String, Object> collectedSources = getMessages(LocaleUtility.getSourceLocale(), component, false).getMessages();
536+
Map<String, String> collectedSources = getMessages(LocaleUtility.getSourceLocale(), component, false).getMessages();
537537
if(!collectedSources.isEmpty()){
538-
Map<String, Object> translations = getMessages(messageLocale, component, true).getMessages();
538+
Map<String, String> translations = getMessages(messageLocale, component, true).getMessages();
539539
for (String key : sources.keySet()) {
540-
String source = (String) sources.get(key);
541-
String collectedSource = (String) collectedSources.get(key);
540+
String source = sources.get(key);
541+
String collectedSource = collectedSources.get(key);
542542
if (!source.equals(collectedSource)) {
543543
messages.put(key, source);
544544
} else {
@@ -549,14 +549,14 @@ public Map<String, Object> getMessages(String resourceBundle, final Locale local
549549
messages = sources;
550550
}
551551
}else{
552-
Map<String, Object> translations = getMessages(messageLocale, component, true).getMessages();
552+
Map<String, String> translations = getMessages(messageLocale, component, true).getMessages();
553553
messages = translations;
554554
}
555555
return messages;
556556
}
557557

558-
private Map<String, Object> getSourcesFromBundle(String resourceBundle){
559-
Map<String, Object> sources = new LinkedHashMap<>();
558+
private Map<String, String> getSourcesFromBundle(String resourceBundle){
559+
Map<String, String> sources = new LinkedHashMap<>();
560560
ResourceBundle bundle = ResourceBundle.getBundle(resourceBundle);
561561
for(String key: bundle.keySet()){
562562
sources.put(key, bundle.getString(key));
@@ -595,10 +595,10 @@ private ComponentService.TranslationsDTO getMultiVersionMessagesOfKey(final Loca
595595
* Key is loale; value is also a map whose key is component and value is the messages belong to
596596
* this component.
597597
*/
598-
public Map<Locale, Map<String, Map<String, Object>>> getStrings(final Set<Locale> locales,
598+
public Map<Locale, Map<String, Map<String, String>>> getStrings(final Set<Locale> locales,
599599
final Set<String> components) {
600600
this.logger.info("Start to execute TranslationMessage.getStrings of multiple components of multiple locales.");
601-
Map<Locale, Map<String, Map<String, Object>>> retMap = new HashMap<>();
601+
Map<Locale, Map<String, Map<String, String>>> retMap = new HashMap<>();
602602
if (null == locales || locales.isEmpty() || null == components || components.isEmpty()) {
603603
this.logger.error(ConstantsMsg.WRONG_PARAMETER + "locales: {}, components: {}.", locales, components);
604604
return retMap;

src/main/java/com/vmware/vipclient/i18n/filters/VIPComponentFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void doFilter(ServletRequest request, ServletResponse response,
4242
logger.debug("locale: " + locale);
4343
String messages = "{}";
4444
if (!StringUtil.isEmpty(component) && !StringUtil.isEmpty(locale) && !LocaleUtility.isDefaultLocale(locale)) {
45-
Map<String, Object> ctmap = translation.getStrings(LocaleUtility.fmtToMappedLocale(locale),
45+
Map<String, String> ctmap = translation.getStrings(LocaleUtility.fmtToMappedLocale(locale),
4646
component);
4747
if (ctmap != null) {
4848
JSONObject jsonObject = new JSONObject(ctmap);

src/main/java/com/vmware/vipclient/i18n/l2/plural/parser/PluralRules.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.List;
1919
import java.util.Locale;
2020
import java.util.Map;
21+
import java.util.stream.Collectors;
2122
import java.util.Set;
2223
import java.util.regex.Pattern;
2324

@@ -90,7 +91,7 @@ public static PluralRules parse(String rule) throws ParseException {
9091
return rule.length() == 0 ? DEFAULT : new PluralRules(parseRuleChain(rule));
9192
}
9293

93-
public static PluralRules parse(Map<String, Object> rules) throws ParseException {
94+
public static PluralRules parse(Map<String, String> rules) throws ParseException {
9495
return rules == null || rules.size() == 0 ? DEFAULT : new PluralRules(parseRuleChain(rules));
9596
}
9697

@@ -110,7 +111,7 @@ public static PluralRules getInstance(String rule) {
110111
}
111112
}
112113

113-
public static PluralRules getInstance(Map<String, Object> rule) {
114+
public static PluralRules getInstance(Map<String, String> rule) {
114115
try {
115116
return parse(rule);
116117
} catch (Exception e) {
@@ -896,7 +897,7 @@ private static RuleList parseRuleChain(String description) throws ParseException
896897
return result.finish();
897898
}
898899

899-
private static RuleList parseRuleChain(Map<String, Object> rules) throws ParseException {
900+
private static RuleList parseRuleChain(Map<String, String> rules) throws ParseException {
900901
RuleList result = new RuleList();
901902
for (String keyWord : rules.keySet()) {
902903
Rule rule = parseRule((keyWord + ":" + rules.get(keyWord)).trim());
@@ -1250,7 +1251,8 @@ public static PluralRules forLocale(Locale locale, PluralType type) {
12501251
} catch (NullPointerException e) {
12511252
logger.info("Lack plural pattern!");
12521253
}
1253-
return getInstance(pluralRules.toMap());
1254+
return getInstance(pluralRules.toMap().entrySet().stream()
1255+
.collect(Collectors.toMap(Map.Entry::getKey, e -> (String)e.getValue())));
12541256
}
12551257

12561258
}

src/main/java/com/vmware/vipclient/i18n/messages/api/opt/ProductOpt.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010

1111
public interface ProductOpt {
1212
void getSupportedLocales(MessageCacheItem cacheItem);
13-
List<Object> getComponents();
13+
List<String> getComponents();
1414
}

src/main/java/com/vmware/vipclient/i18n/messages/api/opt/local/LocalLocaleOpt.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.HashMap;
2222
import java.util.Map;
2323
import java.util.Set;
24+
import java.util.stream.Collectors;
2425

2526
import static com.vmware.i18n.pattern.service.impl.PatternServiceImpl.localeAliasesMap;
2627
import static com.vmware.i18n.pattern.service.impl.PatternServiceImpl.localePathMap;
@@ -70,11 +71,11 @@ private Map<String, String> getLanguagesNamesFromBundle(String locale) {
7071
}
7172
try {
7273
String languagesJsonStr = PatternUtil.getLanguageFromLib(normalizedLocale);
73-
JSONObject jsonObject = new JSONObject(languagesJsonStr);
74-
Map<String, Object> languagesData = jsonObject.toMap();
74+
JSONObject languagesData = new JSONObject(languagesJsonStr);
7575
if (languagesData != null) {
7676
logger.debug("Found the languages' names from local bundle for locale [{}].\n", locale);
77-
return (Map<String, String>) languagesData.get(PatternKeys.LANGUAGES);
77+
return ((JSONObject) languagesData.get(PatternKeys.LANGUAGES)).toMap().entrySet().stream()
78+
.collect(Collectors.toMap(Map.Entry::getKey, e -> (String)e.getValue()));
7879
}else{
7980
logger.warn("Didn't find the languages' names from local bundle for locale [{}].\n", locale);
8081
}

src/main/java/com/vmware/vipclient/i18n/messages/api/opt/local/LocalMessagesOpt.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.io.InputStream;
2424
import java.io.InputStreamReader;
2525
import java.util.Map;
26+
import java.util.stream.Collectors;
2627

2728
public class LocalMessagesOpt implements Opt, MessageOpt {
2829

@@ -47,7 +48,8 @@ public void getComponentMessages(MessageCacheItem cacheItem) {
4748
try {
4849
is = getInputStream();
4950
JSONObject jsonObject = new JSONObject(new JSONTokener(new InputStreamReader(is, "UTF-8")));
50-
Map<String, Object> messages = ((JSONObject) jsonObject.get("messages")).toMap();
51+
Map<String, String> messages = ((JSONObject) jsonObject.get("messages")).toMap().entrySet().stream()
52+
.collect(Collectors.toMap(Map.Entry::getKey, e -> (String)e.getValue()));
5153
cacheItem.setCacheItem(messages, null, System.currentTimeMillis(), null);
5254
} catch (Exception e) {
5355
String msg = "Failed to get offline messages for product: " + dto.getProductID() + " " + dto.getVersion() +

src/main/java/com/vmware/vipclient/i18n/messages/api/opt/local/LocalPatternOpt.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.slf4j.LoggerFactory;
1616

1717
import java.util.Map;
18+
import java.util.stream.Collectors;
1819

1920
import static com.vmware.i18n.pattern.service.impl.PatternServiceImpl.localeAliasesMap;
2021
import static com.vmware.i18n.pattern.service.impl.PatternServiceImpl.localePathMap;

src/main/java/com/vmware/vipclient/i18n/messages/api/opt/local/LocalProductOpt.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ public void getSupportedLocales(MessageCacheItem cacheItem) {
5353
logger.debug("Fetching the list of supported locales failed: " + e.getMessage());
5454
return;
5555
}
56-
Map<String, Object> languageTagMap = new HashMap<>();
56+
Map<String, String> languageTagMap = new HashMap<>();
5757
for (String languageTag : supportedLocales) {
5858
languageTagMap.put(languageTag, languageTag);
5959
}
6060
cacheItem.setCacheItem(languageTagMap, null, System.currentTimeMillis(), null);
6161
}
6262

63-
public List<Object> getComponents() {
64-
List<Object> components = new ArrayList<Object>();
63+
public List<String> getComponents() {
64+
List<String> components = new ArrayList<String>();
6565
try {
6666
Path path = Paths.get(VIPCfg.getInstance().getOfflineResourcesBaseUrl());
6767
List<URI> uris = FileUtil.getAllResources(path);
@@ -95,7 +95,7 @@ private void getSupportedLocales(Path path, List<String> supportedLocales) throw
9595
}
9696
}
9797

98-
private void getComponents(Path path, List<Object> components) throws IOException {
98+
private void getComponents(Path path, List<String> components) throws IOException {
9999
try (Stream<Path> listOfFiles = Files.list(path).filter(p -> !Files.isRegularFile(p))) {
100100
listOfFiles.forEach(s -> {
101101
components.add(s.getFileName().toString());

0 commit comments

Comments
 (0)