RED-7757: added check for case sensitivity when adding local dictionary entries
This commit is contained in:
parent
775f43ce03
commit
3c99e015aa
@ -7,6 +7,7 @@ import java.util.Collection;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -106,12 +107,18 @@ public class Dictionary {
|
|||||||
if (StringUtils.isEmpty(value)) {
|
if (StringUtils.isEmpty(value)) {
|
||||||
throw new IllegalArgumentException(format("%s is not a valid dictionary entry", value));
|
throw new IllegalArgumentException(format("%s is not a valid dictionary entry", value));
|
||||||
}
|
}
|
||||||
|
boolean isCaseInsensitive = localAccessMap.get(type).isCaseInsensitive();
|
||||||
Set<MatchedRule> matchedRulesSet = new HashSet<>(matchedRules);
|
Set<MatchedRule> matchedRulesSet = new HashSet<>(matchedRules);
|
||||||
|
|
||||||
|
String cleanedValue = value;
|
||||||
|
if (isCaseInsensitive) {
|
||||||
|
cleanedValue = cleanedValue.toLowerCase(Locale.US);
|
||||||
|
}
|
||||||
localAccessMap.get(type)
|
localAccessMap.get(type)
|
||||||
.getLocalEntriesWithMatchedRules()
|
.getLocalEntriesWithMatchedRules()
|
||||||
.merge(value.trim(), matchedRulesSet, (set1, set2) -> Stream.concat(set1.stream(), set2.stream()).collect(Collectors.toSet()));
|
.merge(cleanedValue.trim(), matchedRulesSet, (set1, set2) -> Stream.concat(set1.stream(), set2.stream()).collect(Collectors.toSet()));
|
||||||
if (alsoAddLastname) {
|
if (alsoAddLastname) {
|
||||||
String lastname = value.split(" ")[0];
|
String lastname = cleanedValue.split(" ")[0];
|
||||||
localAccessMap.get(type)
|
localAccessMap.get(type)
|
||||||
.getLocalEntriesWithMatchedRules()
|
.getLocalEntriesWithMatchedRules()
|
||||||
.merge(lastname, matchedRulesSet, (set1, set2) -> Stream.concat(set1.stream(), set2.stream()).collect(Collectors.toSet()));
|
.merge(lastname, matchedRulesSet, (set1, set2) -> Stream.concat(set1.stream(), set2.stream()).collect(Collectors.toSet()));
|
||||||
|
|||||||
@ -2,6 +2,8 @@ package com.iqser.red.service.redaction.v1.server.model.dictionary;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -109,4 +111,11 @@ public class DictionaryModel implements Serializable {
|
|||||||
return falseRecommendationsSearch;
|
return falseRecommendationsSearch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<MatchedRule> getMatchedRulesForLocalDictionaryEntry(String value) {
|
||||||
|
var cleanedValue = isCaseInsensitive() ? value.toLowerCase(Locale.US) : value;
|
||||||
|
|
||||||
|
return localEntriesWithMatchedRules.get(cleanedValue);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -746,7 +746,7 @@ rule "LDS.0.0: Run local dictionary search"
|
|||||||
then
|
then
|
||||||
entityCreationService.bySearchImplementation($dictionaryModel.getLocalSearch(), $dictionaryModel.getType(), EntityType.RECOMMENDATION, document)
|
entityCreationService.bySearchImplementation($dictionaryModel.getLocalSearch(), $dictionaryModel.getType(), EntityType.RECOMMENDATION, document)
|
||||||
.forEach(entity -> {
|
.forEach(entity -> {
|
||||||
Collection<MatchedRule> matchedRules = $dictionaryModel.getLocalEntriesWithMatchedRules().get(entity.getValue());
|
Collection<MatchedRule> matchedRules = $dictionaryModel.getMatchedRulesForLocalDictionaryEntry(entity.getValue());
|
||||||
matchedRules.forEach(matchedRule -> entity.addMatchedRule(matchedRule.asSkippedIfApplied()));
|
matchedRules.forEach(matchedRule -> entity.addMatchedRule(matchedRule.asSkippedIfApplied()));
|
||||||
});
|
});
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1563,7 +1563,7 @@ rule "LDS.0.0: Run local dictionary search"
|
|||||||
then
|
then
|
||||||
entityCreationService.bySearchImplementation($dictionaryModel.getLocalSearch(), $dictionaryModel.getType(), EntityType.RECOMMENDATION, document)
|
entityCreationService.bySearchImplementation($dictionaryModel.getLocalSearch(), $dictionaryModel.getType(), EntityType.RECOMMENDATION, document)
|
||||||
.forEach(entity -> {
|
.forEach(entity -> {
|
||||||
Collection<MatchedRule> matchedRules = $dictionaryModel.getLocalEntriesWithMatchedRules().get(entity.getValue());
|
Collection<MatchedRule> matchedRules = $dictionaryModel.getMatchedRulesForLocalDictionaryEntry(entity.getValue());
|
||||||
matchedRules.forEach(matchedRule -> entity.addMatchedRule(matchedRule.asSkippedIfApplied()));
|
matchedRules.forEach(matchedRule -> entity.addMatchedRule(matchedRule.asSkippedIfApplied()));
|
||||||
});
|
});
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1393,7 +1393,7 @@ rule "LDS.0.0: Run local dictionary search"
|
|||||||
then
|
then
|
||||||
entityCreationService.bySearchImplementation($dictionaryModel.getLocalSearch(), $dictionaryModel.getType(), EntityType.RECOMMENDATION, document)
|
entityCreationService.bySearchImplementation($dictionaryModel.getLocalSearch(), $dictionaryModel.getType(), EntityType.RECOMMENDATION, document)
|
||||||
.forEach(entity -> {
|
.forEach(entity -> {
|
||||||
Collection<MatchedRule> matchedRules = $dictionaryModel.getLocalEntriesWithMatchedRules().get(entity.getValue());
|
Collection<MatchedRule> matchedRules = $dictionaryModel.getMatchedRulesForLocalDictionaryEntry(entity.getValue());
|
||||||
matchedRules.forEach(matchedRule -> entity.addMatchedRule(matchedRule.asSkippedIfApplied()));
|
matchedRules.forEach(matchedRule -> entity.addMatchedRule(matchedRule.asSkippedIfApplied()));
|
||||||
});
|
});
|
||||||
end
|
end
|
||||||
|
|||||||
@ -219,7 +219,7 @@ rule "LDS.0.0: Run local dictionary search"
|
|||||||
then
|
then
|
||||||
entityCreationService.bySearchImplementation($dictionaryModel.getLocalSearch(), $dictionaryModel.getType(), EntityType.RECOMMENDATION, document)
|
entityCreationService.bySearchImplementation($dictionaryModel.getLocalSearch(), $dictionaryModel.getType(), EntityType.RECOMMENDATION, document)
|
||||||
.forEach(entity -> {
|
.forEach(entity -> {
|
||||||
Collection<MatchedRule> matchedRules = $dictionaryModel.getLocalEntriesWithMatchedRules().get(entity.getValue());
|
Collection<MatchedRule> matchedRules = $dictionaryModel.getMatchedRulesForLocalDictionaryEntry(entity.getValue());
|
||||||
matchedRules.forEach(matchedRule -> entity.addMatchedRule(matchedRule.asSkippedIfApplied()));
|
matchedRules.forEach(matchedRule -> entity.addMatchedRule(matchedRule.asSkippedIfApplied()));
|
||||||
});
|
});
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1144,7 +1144,7 @@ rule "LDS.0.0: Run local dictionary search"
|
|||||||
then
|
then
|
||||||
entityCreationService.bySearchImplementation($dictionaryModel.getLocalSearch(), $dictionaryModel.getType(), EntityType.RECOMMENDATION, document)
|
entityCreationService.bySearchImplementation($dictionaryModel.getLocalSearch(), $dictionaryModel.getType(), EntityType.RECOMMENDATION, document)
|
||||||
.forEach(entity -> {
|
.forEach(entity -> {
|
||||||
Collection<MatchedRule> matchedRules = $dictionaryModel.getLocalEntriesWithMatchedRules().get(entity.getValue());
|
Collection<MatchedRule> matchedRules = $dictionaryModel.getMatchedRulesForLocalDictionaryEntry(entity.getValue());
|
||||||
matchedRules.forEach(matchedRule -> entity.addMatchedRule(matchedRule.asSkippedIfApplied()));
|
matchedRules.forEach(matchedRule -> entity.addMatchedRule(matchedRule.asSkippedIfApplied()));
|
||||||
});
|
});
|
||||||
end
|
end
|
||||||
|
|||||||
@ -360,7 +360,7 @@ rule "LDS.0.0: Run local dictionary search"
|
|||||||
then
|
then
|
||||||
entityCreationService.bySearchImplementation($dictionaryModel.getLocalSearch(), $dictionaryModel.getType(), EntityType.RECOMMENDATION, document)
|
entityCreationService.bySearchImplementation($dictionaryModel.getLocalSearch(), $dictionaryModel.getType(), EntityType.RECOMMENDATION, document)
|
||||||
.forEach(entity -> {
|
.forEach(entity -> {
|
||||||
Collection<MatchedRule> matchedRules = $dictionaryModel.getLocalEntriesWithMatchedRules().get(entity.getValue());
|
Collection<MatchedRule> matchedRules = $dictionaryModel.getMatchedRulesForLocalDictionaryEntry(entity.getValue());
|
||||||
matchedRules.forEach(matchedRule -> entity.addMatchedRule(matchedRule.asSkippedIfApplied()));
|
matchedRules.forEach(matchedRule -> entity.addMatchedRule(matchedRule.asSkippedIfApplied()));
|
||||||
});
|
});
|
||||||
end
|
end
|
||||||
|
|||||||
@ -481,7 +481,7 @@ rule "LDS.0.0: Run local dictionary search"
|
|||||||
then
|
then
|
||||||
entityCreationService.bySearchImplementation($dictionaryModel.getLocalSearch(), $dictionaryModel.getType(), EntityType.RECOMMENDATION, document)
|
entityCreationService.bySearchImplementation($dictionaryModel.getLocalSearch(), $dictionaryModel.getType(), EntityType.RECOMMENDATION, document)
|
||||||
.forEach(entity -> {
|
.forEach(entity -> {
|
||||||
Collection<MatchedRule> matchedRules = $dictionaryModel.getLocalEntriesWithMatchedRules().get(entity.getValue());
|
Collection<MatchedRule> matchedRules = $dictionaryModel.getMatchedRulesForLocalDictionaryEntry(entity.getValue());
|
||||||
matchedRules.forEach(matchedRule -> entity.addMatchedRule(matchedRule.asSkippedIfApplied()));
|
matchedRules.forEach(matchedRule -> entity.addMatchedRule(matchedRule.asSkippedIfApplied()));
|
||||||
});
|
});
|
||||||
end
|
end
|
||||||
|
|||||||
@ -397,7 +397,7 @@ rule "LDS.0.0: Run local dictionary search"
|
|||||||
then
|
then
|
||||||
entityCreationService.bySearchImplementation($dictionaryModel.getLocalSearch(), $dictionaryModel.getType(), EntityType.RECOMMENDATION, document)
|
entityCreationService.bySearchImplementation($dictionaryModel.getLocalSearch(), $dictionaryModel.getType(), EntityType.RECOMMENDATION, document)
|
||||||
.forEach(entity -> {
|
.forEach(entity -> {
|
||||||
Collection<MatchedRule> matchedRules = $dictionaryModel.getLocalEntriesWithMatchedRules().get(entity.getValue());
|
Collection<MatchedRule> matchedRules = $dictionaryModel.getMatchedRulesForLocalDictionaryEntry(entity.getValue());
|
||||||
matchedRules.forEach(matchedRule -> entity.addMatchedRule(matchedRule.asSkippedIfApplied()));
|
matchedRules.forEach(matchedRule -> entity.addMatchedRule(matchedRule.asSkippedIfApplied()));
|
||||||
});
|
});
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1556,7 +1556,7 @@ rule "LDS.0.0: Run local dictionary search"
|
|||||||
then
|
then
|
||||||
entityCreationService.bySearchImplementation($dictionaryModel.getLocalSearch(), $dictionaryModel.getType(), EntityType.RECOMMENDATION, document)
|
entityCreationService.bySearchImplementation($dictionaryModel.getLocalSearch(), $dictionaryModel.getType(), EntityType.RECOMMENDATION, document)
|
||||||
.forEach(entity -> {
|
.forEach(entity -> {
|
||||||
Collection<MatchedRule> matchedRules = $dictionaryModel.getLocalEntriesWithMatchedRules().get(entity.getValue());
|
Collection<MatchedRule> matchedRules = $dictionaryModel.getMatchedRulesForLocalDictionaryEntry(entity.getValue());
|
||||||
matchedRules.forEach(matchedRule -> entity.addMatchedRule(matchedRule.asSkippedIfApplied()));
|
matchedRules.forEach(matchedRule -> entity.addMatchedRule(matchedRule.asSkippedIfApplied()));
|
||||||
});
|
});
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1540,7 +1540,7 @@ rule "LDS.0.0: Run local dictionary search"
|
|||||||
then
|
then
|
||||||
entityCreationService.bySearchImplementation($dictionaryModel.getLocalSearch(), $dictionaryModel.getType(), EntityType.RECOMMENDATION, document)
|
entityCreationService.bySearchImplementation($dictionaryModel.getLocalSearch(), $dictionaryModel.getType(), EntityType.RECOMMENDATION, document)
|
||||||
.forEach(entity -> {
|
.forEach(entity -> {
|
||||||
Collection<MatchedRule> matchedRules = $dictionaryModel.getLocalEntriesWithMatchedRules().get(entity.getValue());
|
Collection<MatchedRule> matchedRules = $dictionaryModel.getMatchedRulesForLocalDictionaryEntry(entity.getValue());
|
||||||
matchedRules.forEach(matchedRule -> entity.addMatchedRule(matchedRule.asSkippedIfApplied()));
|
matchedRules.forEach(matchedRule -> entity.addMatchedRule(matchedRule.asSkippedIfApplied()));
|
||||||
});
|
});
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user