Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getDisabledRuleIdsFromDB #10447

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.languagetool.server;

import com.google.common.cache.Cache;
import org.apache.ibatis.jdbc.SQL;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
Expand Down Expand Up @@ -228,4 +227,11 @@ void execute(SQL sql) throws SQLException {
* @return a list of user rules (complete, or from the given range)
*/
public abstract List<Rule> getRules(UserLimits limits, Language lang, @Nullable List<String> groups);

/**
*
* @param limits user account and settings for e.g. caching
* @return a list of ignored ruleIDs
*/
public abstract List<String> getIgnoredRuleIds(UserLimits limits, @Nullable List<String> groups);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.jetbrains.annotations.Nullable;
import org.languagetool.Language;
import org.languagetool.Premium;
import org.languagetool.rules.Rule;
Expand Down Expand Up @@ -365,4 +366,10 @@ public List<Rule> getRules(UserLimits limits, Language lang, List<String> groups
return Collections.emptyList();
}

@Override
public List<String> getIgnoredRuleIds(UserLimits limits, @Nullable List<String> groups) {
// not implemented in open source
return Collections.emptyList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
import org.languagetool.rules.spelling.morfologik.suggestions_ordering.SuggestionsOrdererConfig;
import org.languagetool.server.tools.AbTestService;
import org.languagetool.server.tools.LocalAbTestService;
import org.languagetool.tools.TelemetryProvider;
import org.languagetool.tools.LtThreadPoolFactory;
import org.languagetool.tools.TelemetryProvider;
import org.languagetool.tools.Tools;
import org.slf4j.MDC;

Expand Down Expand Up @@ -436,6 +436,7 @@ void checkText(AnnotatedText aText, HttpExchange httpExchange, Map<String, Strin
List<String> enabledRules = getEnabledRuleIds(params);

List<String> disabledRules = getDisabledRuleIds(params);
disabledRules.addAll(getDisabledRuleIdsFromDB(limits, finalDictGroups));
List<CategoryId> enabledCategories = getCategoryIds("enabledCategories", params);
List<CategoryId> disabledCategories = getCategoryIds("disabledCategories", params);

Expand Down Expand Up @@ -760,6 +761,16 @@ private List<Rule> getUserRules(UserLimits limits, Language lang, List<String> g
}
}

@NotNull
private List<String> getDisabledRuleIdsFromDB(UserLimits limits, List<String> groups ) {
if (limits.getPremiumUid() != null && DatabaseAccess.isReady()) {
DatabaseAccess db = DatabaseAccess.getInstance();
return db.getIgnoredRuleIds(limits, groups);
} else {
return Collections.emptyList();
}
}

protected void checkParams(Map<String, String> parameters) {
if (parameters.get("text") == null && parameters.get("data") == null) {
throw new BadRequestException("Missing 'text' or 'data' parameter");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
/**
* @since 4.0
*/
class UserLimits {
public class UserLimits {

private static final Logger logger = LoggerFactory.getLogger(UserLimits.class);

Expand Down