From 52024924ae744aafd683ab97bcdf719644f9f26d Mon Sep 17 00:00:00 2001 From: srishti Date: Thu, 1 Feb 2024 12:51:06 +0100 Subject: [PATCH] EA-3717 address sonarq --- .../api/translation/tests/web/LangDetectionRestIT.java | 4 ++-- .../web/service/LangDetectionPreProcessor.java | 8 +++++++- .../translation/web/service/LangDetectionWebService.java | 4 ++-- .../translation/web/service/TranslationPreProcessor.java | 7 ++++++- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/translation-tests/src/integration-test/java/eu/europeana/api/translation/tests/web/LangDetectionRestIT.java b/translation-tests/src/integration-test/java/eu/europeana/api/translation/tests/web/LangDetectionRestIT.java index d5f7a221..419b6f1b 100644 --- a/translation-tests/src/integration-test/java/eu/europeana/api/translation/tests/web/LangDetectionRestIT.java +++ b/translation-tests/src/integration-test/java/eu/europeana/api/translation/tests/web/LangDetectionRestIT.java @@ -66,7 +66,7 @@ void langDetection() throws Exception { assertNotNull(result); JSONObject json = new JSONObject(result); JSONArray langs = json.getJSONArray(TranslationAppConstants.LANGS); - assertTrue(langs.length() == 3); + assertEquals(3,langs.length()); String serviceFieldValue = json.getString(TranslationAppConstants.SERVICE); assertNotNull(serviceFieldValue); } @@ -106,7 +106,7 @@ void langDetectionGoogle() throws Exception { assertNotNull(result); JSONObject json = new JSONObject(result); JSONArray langs = json.getJSONArray(TranslationAppConstants.LANGS); - assertTrue(langs.length() == 2); + assertEquals(2, langs.length()); String serviceFieldValue = json.getString(TranslationAppConstants.SERVICE); assertNotNull(serviceFieldValue); } diff --git a/translation-web/src/main/java/eu/europeana/api/translation/web/service/LangDetectionPreProcessor.java b/translation-web/src/main/java/eu/europeana/api/translation/web/service/LangDetectionPreProcessor.java index 69942e12..c85881b6 100644 --- a/translation-web/src/main/java/eu/europeana/api/translation/web/service/LangDetectionPreProcessor.java +++ b/translation-web/src/main/java/eu/europeana/api/translation/web/service/LangDetectionPreProcessor.java @@ -6,6 +6,11 @@ import java.util.List; +/** + * Pre processing class for the Language detection flow + * @author srishti singh + * @since 31 Jan 2024 + */ public class LangDetectionPreProcessor implements LanguageDetectionService { @Override @@ -20,6 +25,7 @@ public String getServiceId() { @Override public void setServiceId(String serviceId) { + // leave empty } @@ -30,7 +36,7 @@ public List detectLang(List texts, String langHint) throws Langu @Override public void close() { - + // leave empty, nothing to close } @Override diff --git a/translation-web/src/main/java/eu/europeana/api/translation/web/service/LangDetectionWebService.java b/translation-web/src/main/java/eu/europeana/api/translation/web/service/LangDetectionWebService.java index 93422fe3..b70f99d0 100644 --- a/translation-web/src/main/java/eu/europeana/api/translation/web/service/LangDetectionWebService.java +++ b/translation-web/src/main/java/eu/europeana/api/translation/web/service/LangDetectionWebService.java @@ -76,8 +76,8 @@ private List accumulateLanguages(List texts, List langDe List languages = new ArrayList<>(texts.size()); int j =0; - for (int i = 0; i < texts.size(); i++) { - if (eligibleValues.contains(texts.get(i))) { + for (String text : texts) { + if (eligibleValues.contains(text)) { languages.add(langDetected.get(j)); j++; } else { diff --git a/translation-web/src/main/java/eu/europeana/api/translation/web/service/TranslationPreProcessor.java b/translation-web/src/main/java/eu/europeana/api/translation/web/service/TranslationPreProcessor.java index 030b88c0..cee1fbd1 100644 --- a/translation-web/src/main/java/eu/europeana/api/translation/web/service/TranslationPreProcessor.java +++ b/translation-web/src/main/java/eu/europeana/api/translation/web/service/TranslationPreProcessor.java @@ -7,6 +7,11 @@ import java.util.List; +/** + * Pre processing class for the Translation flow + * @author srishti singh + * @since 31 Jan 2024 + */ public class TranslationPreProcessor implements TranslationService { @Override @@ -31,7 +36,7 @@ public void translate(List translationStrings) throws Translatio @Override public void close() { - + // leave empty, nothing to close } @Override