Skip to content

Commit

Permalink
adding localization for erro message 'unsupported matching role'
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Mar 5, 2024
1 parent 391cf3a commit 2f2712c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.List;
import java.util.Locale;

import com.evolveum.midpoint.gui.api.util.LocalizationUtil;
import com.evolveum.midpoint.gui.impl.util.DetailsPageUtil;

import com.evolveum.midpoint.xml.ns._public.common.common_3.FeedbackMessagesHookType;
Expand Down Expand Up @@ -248,11 +249,7 @@ private WebMarkupContainer createMessage() {

String msg = null;
if (result.getUserFriendlyMessage() != null) {
//TODO: unify with WebModelServiceUtil.translateMessage()
LocalizationService service = page.getLocalizationService();
Locale locale = page.getSession().getLocale();

msg = service.translate(result.getUserFriendlyMessage(), locale);
msg = LocalizationUtil.translateMessage(result.getUserFriendlyMessage());
}

if (StringUtils.isNotBlank(msg)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import static com.evolveum.midpoint.prism.PrismConstants.STRING_IGNORE_CASE_MATCHING_RULE_NAME;

import com.evolveum.midpoint.util.SingleLocalizableMessage;

import com.querydsl.core.types.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -23,6 +25,8 @@
import com.evolveum.midpoint.repo.sqlbase.filtering.ValueFilterValues;
import com.evolveum.midpoint.repo.sqlbase.mapping.QueryTableMapping;

import java.util.ArrayList;

/**
* Type of {@link FilterProcessor} for a single Prism item (not necessarily one SQL column).
* These are executed as "leaves" of filter processing tree returning terminal predicates.
Expand Down Expand Up @@ -170,15 +174,34 @@ protected final QueryException createUnsupportedMatchingRuleException(O filter)
}

protected final QueryException createUnsupportedMatchingRuleException(O filter, boolean addFilter) {

StringBuilder technicalMessage = new StringBuilder();
String key;
ArrayList<Object> objects = new ArrayList<>();

if (filter.getMatchingRule() != null) {
key = "ItemValueFilterProcessor.message.error.unsupportedMatchingRule";
objects.add(filter.getMatchingRule().getLocalPart());
technicalMessage.append("Unsupported matching rule '").append(filter.getMatchingRule().getLocalPart()).append("'");
} else {
key = "ItemValueFilterProcessor.message.error.unsupportedEmptyMatchingRule";
technicalMessage.append("Unsupported empty matching rule");
}

var definition = filter.getDefinition();
String suffix = ".";
if (definition != null) {
suffix = " for value type '" + definition.getTypeName().getLocalPart() +"'.";
key += ".withType";
objects.add(definition.getTypeName().getLocalPart());
technicalMessage.append(" for value type '").append(definition.getTypeName().getLocalPart()).append("'.");
} else {
technicalMessage.append(".");
}

if (addFilter) {
technicalMessage.append(" Filter: ").append(filter);
}

return new QueryException("Unsupported matching rule '" +
(filter.getMatchingRule() != null ? filter.getMatchingRule().getLocalPart() : "empty_value")
+ "'" + suffix
+ (addFilter ? (" Filter: " + filter) : ""));
SingleLocalizableMessage message = new SingleLocalizableMessage(key, objects.toArray(), technicalMessage.toString());
return new QueryException(message);
}
}

0 comments on commit 2f2712c

Please sign in to comment.