From 7431ec678b93decb21cc480c1a0030542ad74292 Mon Sep 17 00:00:00 2001 From: Kohei Suzuki Date: Tue, 7 Nov 2023 11:35:11 +0100 Subject: [PATCH] Add netty dependency in pom.xml and number of retry for converter in backend --- backend/pom.xml | 5 +++++ .../backend/converter/ConvertService.java | 21 ++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/backend/pom.xml b/backend/pom.xml index 41095a0..bb205a2 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -88,6 +88,11 @@ icu4j 73.2 + + io.netty + netty-resolver-dns + 4.1.100.Final + kotokoapp diff --git a/backend/src/main/java/de/neuefische/koheis/backend/converter/ConvertService.java b/backend/src/main/java/de/neuefische/koheis/backend/converter/ConvertService.java index 86bd877..4dc61fa 100644 --- a/backend/src/main/java/de/neuefische/koheis/backend/converter/ConvertService.java +++ b/backend/src/main/java/de/neuefische/koheis/backend/converter/ConvertService.java @@ -32,6 +32,7 @@ public String convertKanjiToKana(GooRequest gooRequest) { .bodyValue(gooRequest) .retrieve() .toEntity(GooResponse.class) + .retry(3) .block(); assert responseEntity != null; @@ -51,15 +52,19 @@ public String convertKanaToAlphabet(String kana) { public Conversion convertTranslationToConversion(Translation translation) { String translated = translation.getJapanese(); - if (translated.matches("^[\\u4E00-\\u9FFF]+$")) { - String kana = convertKanjiToKana(getGooRequest(translated, "hiragana")); - String alphabet = convertKanaToAlphabet(kana); - return new Conversion(translated, kana, alphabet); - } else if ((translated.matches("^[\\u3040-\\u309F]+$")) || (translation.getJapanese().matches("^[\\u30A0-\\u30FF]+$"))) { - String alphabet = convertKanaToAlphabet(translated); - return new Conversion("", translated, alphabet); + if (translated != null) { + if (translated.matches("^[\\u4E00-\\u9FFF]+$")) { + String kana = convertKanjiToKana(getGooRequest(translated, "hiragana")); + String alphabet = convertKanaToAlphabet(kana); + return new Conversion(translated, kana, alphabet); + } else if ((translated.matches("^[\\u3040-\\u309F]+$")) || (translation.getJapanese().matches("^[\\u30A0-\\u30FF]+$"))) { + String alphabet = convertKanaToAlphabet(translated); + return new Conversion("", translated, alphabet); + } else { + return new Conversion("", "", ""); + } } else { - return new Conversion("", "", ""); + return new Conversion("could not be translated", "", ""); } }