EDQS SQL like query updates to be in sync with legacy
This commit is contained in:
parent
e752902cfc
commit
3288ec257f
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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,35 +322,24 @@ 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, "", ".*");
|
||||
}
|
||||
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) {
|
||||
if (value.contains("%") || value.contains("_")) {
|
||||
String 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);
|
||||
return Pattern.compile(regexValue);
|
||||
} else {
|
||||
return Pattern.compile(prefix + Pattern.quote(value) + suffix);
|
||||
}
|
||||
|
||||
@ -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),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user