wordstudent

Word learning program
git clone git://git.wimdupont.com/wordstudent.git
Log | Files | Refs | LICENSE

commit 259b833021896ffc9af25a2738625b0ea790232b
parent 77fb4ffa54183ae22d8514a79d1c4dc49f2d9b8b
Author: WimDupont <WimDupont@users.noreply.gitlab.com>
Date:   Wed, 19 Jan 2022 21:26:11 +0100

don't save if word not found

Diffstat:
Msrc/main/java/com/wimdupont/client/DictionaryAPI.java | 1-
Msrc/main/java/com/wimdupont/service/WordService.java | 13+++++++++----
2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/wimdupont/client/DictionaryAPI.java b/src/main/java/com/wimdupont/client/DictionaryAPI.java @@ -28,7 +28,6 @@ public class DictionaryAPI { } return Arrays.asList(OBJECT_MAPPER.readValue(sbuilder.toString(), DictionaryDto[].class)); } catch (Exception e) { - System.out.println(e.getMessage()); return new ArrayList<>(); } } diff --git a/src/main/java/com/wimdupont/service/WordService.java b/src/main/java/com/wimdupont/service/WordService.java @@ -25,7 +25,7 @@ public class WordService { private final EntityManager entityManager; private final WordFetcher wordFetcher; - public void saveNew(){ + public void saveNew() { List<String> words = wordFetcher.fetch(); List<Word> savedWordList = wordRepository.findAll(); System.out.printf("Words in database: %s%n", savedWordList.size()); @@ -35,9 +35,14 @@ public class WordService { .filter(csvWord -> !savedWords.contains(csvWord)) .forEach(newWord -> { List<DictionaryDto> response = DICTIONARY_API.getAffirmation(newWord); - Word word = wordRepository.save(wordConverter.convert(newWord, response)); - System.out.printf("Saved new word %s%n", word.getWord()); - count.getAndIncrement(); + if (response.isEmpty()) { + System.out.printf("No results found for '%s', no data saved%n", newWord); + count.get(); + } else { + Word word = wordRepository.save(wordConverter.convert(newWord, response)); + System.out.printf("Saved new word %s%n", word.getWord()); + count.getAndIncrement(); + } }); if (count.get() > 0)