Merge pull request #13604 from volodymyr-babak/merge

Rc-4.0.2 into rc
This commit is contained in:
Viacheslav Klimov 2025-06-18 10:02:57 +03:00 committed by GitHub
commit af88f7bfca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 20 additions and 26 deletions

View File

@ -36,7 +36,7 @@ public abstract class AbstractEntityProfileNameQueryProcessor<T extends EntityFi
public AbstractEntityProfileNameQueryProcessor(TenantRepo repo, QueryContext ctx, EdqsQuery query, T filter, EntityType entityType) {
super(repo, ctx, query, filter, entityType);
entityProfileNames = new HashSet<>(getProfileNames(this.filter));
pattern = RepositoryUtils.toContainsSqlLikePattern(getEntityNameFilter(filter));
pattern = RepositoryUtils.toEntityNameSqlLikePattern(getEntityNameFilter(filter));
}
protected abstract String getEntityNameFilter(T filter);

View File

@ -43,7 +43,7 @@ public abstract class AbstractEntityProfileQueryProcessor<T extends EntityFilter
entityProfileIds.add(dp.getId());
}
}
pattern = RepositoryUtils.toContainsSqlLikePattern(getEntityNameFilter(filter));
pattern = RepositoryUtils.toEntityNameSqlLikePattern(getEntityNameFilter(filter));
}
protected abstract String getEntityNameFilter(T filter);

View File

@ -30,7 +30,7 @@ public class EntityNameQueryProcessor extends AbstractSimpleQueryProcessor<Entit
public EntityNameQueryProcessor(TenantRepo repo, QueryContext ctx, EdqsQuery query) {
super(repo, ctx, query, (EntityNameFilter) query.getEntityFilter(), ((EntityNameFilter) query.getEntityFilter()).getEntityType());
pattern = RepositoryUtils.toContainsSqlLikePattern(filter.getEntityNameFilter());
pattern = RepositoryUtils.toEntityNameSqlLikePattern(filter.getEntityNameFilter());
}
@Override

View File

@ -248,11 +248,11 @@ public class RepositoryUtils {
}
return switch (predicate.getOperation()) {
case EQUAL -> value.equals(predicateValue);
case STARTS_WITH -> toStartsWithSqlLikePattern(predicateValue).matcher(value).matches();
case ENDS_WITH -> toEndsWithSqlLikePattern(predicateValue).matcher(value).matches();
case STARTS_WITH -> toSqlLikePattern(predicateValue, "^", ".*").matcher(value).matches();
case ENDS_WITH -> toSqlLikePattern(predicateValue, ".*", "$").matcher(value).matches();
case NOT_EQUAL -> !value.equals(predicateValue);
case CONTAINS -> toContainsSqlLikePattern(predicateValue).matcher(value).matches();
case NOT_CONTAINS -> !toContainsSqlLikePattern(predicateValue).matcher(value).matches();
case CONTAINS -> toSqlLikePattern(predicateValue, ".*", ".*").matcher(value).matches();
case NOT_CONTAINS -> !toSqlLikePattern(predicateValue, ".*", ".*").matcher(value).matches();
case IN -> equalsAny(value, splitByCommaWithoutQuotes(predicateValue));
case NOT_IN -> !equalsAny(value, splitByCommaWithoutQuotes(predicateValue));
};
@ -322,38 +322,32 @@ public class RepositoryUtils {
}
}
public static Pattern toContainsSqlLikePattern(String filter) {
public static Pattern toEntityNameSqlLikePattern(String filter) {
if (StringUtils.isNotBlank(filter)) {
return toSqlLikePattern(filter, ".*", ".*");
return toSqlLikePattern(filter, "", ".*", true);
}
return null;
}
private static Pattern toStartsWithSqlLikePattern(String filter) {
return toSqlLikePattern(filter, "^", ".*");
}
private static Pattern toEndsWithSqlLikePattern(String filter) {
return toSqlLikePattern(filter, ".*", "$");
}
private static Pattern toSqlLikePattern(String value, String prefix, String suffix) {
return toSqlLikePattern(value, prefix, suffix, false);
}
private static Pattern toSqlLikePattern(String value, String prefix, String suffix, boolean ignoreCase) {
String regexValue;
if (value.contains("%") || value.contains("_")) {
String regexValue = value
regexValue = value
.replace("_", ".")
.replace("%", ".*");
String regex;
if ("^".equals(prefix)) {
regex = "^" + regexValue + (regexValue.endsWith(".*") ? "" : ".*");
regexValue = "^" + regexValue + (regexValue.endsWith(".*") ? "" : ".*");
} else if ("$".equals(suffix)) {
regex = (regexValue.startsWith(".*") ? "" : ".*") + regexValue + "$";
} else {
regex = (regexValue.startsWith(".*") ? "" : ".*") + regexValue + (regexValue.endsWith(".*") ? "" : ".*");
regexValue = (regexValue.startsWith(".*") ? "" : ".*") + regexValue + "$";
}
return Pattern.compile(regex);
} else {
return Pattern.compile(prefix + Pattern.quote(value) + suffix);
regexValue = prefix + Pattern.quote(value) + suffix;
}
return ignoreCase ? Pattern.compile(regexValue, Pattern.CASE_INSENSITIVE) : Pattern.compile(regexValue);
}
@FunctionalInterface

View File

@ -73,7 +73,7 @@ public class RepositoryUtilsTest {
Arguments.of("loranet 123", getNameFilter(StringOperation.NOT_IN, "loranet 123, loranet 126"), false),
// Basic CONTAINS
Arguments.of("loranet 123", getNameFilter(StringOperation.CONTAINS, "%loranet"), true),
Arguments.of("loranet 123", getNameFilter(StringOperation.CONTAINS, "%loranet"), false),
Arguments.of("loranet 123", getNameFilter(StringOperation.CONTAINS, "loranet%"), true),
Arguments.of("loranet 123", getNameFilter(StringOperation.CONTAINS, "%ranet%"), true),
Arguments.of("loranet 123", getNameFilter(StringOperation.CONTAINS, "%123"), true),