From de47005ed39a95c43ea3fbe444dcb20372eb5b3f Mon Sep 17 00:00:00 2001 From: Stefan Viol Date: Tue, 16 Jul 2024 16:19:35 +0200 Subject: [PATCH] Use the default dict if available --- .../main/java/org/languagetool/server/ApiV2.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/languagetool-server/src/main/java/org/languagetool/server/ApiV2.java b/languagetool-server/src/main/java/org/languagetool/server/ApiV2.java index f31028e3a2ce..f120fda6a487 100644 --- a/languagetool-server/src/main/java/org/languagetool/server/ApiV2.java +++ b/languagetool-server/src/main/java/org/languagetool/server/ApiV2.java @@ -200,6 +200,10 @@ private void handleWordsRequest(HttpExchange httpExchange, Map p List groups = null; if (params.containsKey("dicts")) { groups = Arrays.asList(params.get("dicts").split(",")); + } else if (limits.getAccount() != null && + limits.getAccount().getDefaultDictionary() != null && + !limits.getAccount().getDefaultDictionary().isEmpty()) { + groups = Collections.singletonList(limits.getAccount().getDefaultDictionary()); } long start = System.nanoTime(); List words = db.getWords(limits, groups, offset, limit); @@ -214,16 +218,23 @@ private void handleWordAddRequest(HttpExchange httpExchange, Map ensurePostMethod(httpExchange, "/words/add"); UserLimits limits = getUserLimits(parameters, config); DatabaseAccess db = DatabaseAccess.getInstance(); + String dict = parameters.get("dict"); + if(dict == null && + limits.getAccount() != null && + limits.getAccount().getDefaultDictionary() != null && + !limits.getAccount().getDefaultDictionary().isEmpty()) { + dict = limits.getAccount().getDefaultDictionary(); + } /* * experimental batch mode for adding words, * use mode=batch, words="word1 word2 word3" (whitespace delimited list) instead of word parameter */ if ("batch".equals(parameters.get("mode"))) { List words = Arrays.asList(parameters.get("words").split("\\s+")); - db.addWordBatch(words, limits.getPremiumUid(), parameters.get("dict")); + db.addWordBatch(words, limits.getPremiumUid(), dict); writeResponse("added", true, httpExchange); } else { - boolean added = db.addWord(parameters.get("word"), limits.getPremiumUid(), parameters.get("dict")); + boolean added = db.addWord(parameters.get("word"), limits.getPremiumUid(), dict); writeResponse("added", added, httpExchange); } }