in core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/search/FilterVisitor.java [52:142]
private Filter visitPrimitive(final SearchCondition<SearchBean> sc) {
String name = getRealPropertyName(sc.getStatement().getProperty());
Optional<SpecialAttr> specialAttrName = SpecialAttr.fromString(name);
String value = SearchUtils.toSqlWildcardString(
URLDecoder.decode(sc.getStatement().getValue().toString(), StandardCharsets.UTF_8), false).
replaceAll("\\\\_", "_");
Optional<SpecialAttr> specialAttrValue = SpecialAttr.fromString(value);
ConditionType ct = sc.getConditionType();
if (sc instanceof final SyncopeFiqlSearchCondition<SearchBean> sfsc
&& sc.getConditionType() == ConditionType.CUSTOM) {
switch (sfsc.getOperator()) {
case SyncopeFiqlParser.IEQ:
ct = ConditionType.EQUALS;
break;
case SyncopeFiqlParser.NIEQ:
ct = ConditionType.NOT_EQUALS;
break;
default:
throw new IllegalArgumentException(
String.format("Condition type %s is not supported", sfsc.getOperator()));
}
}
Attribute attr = AttributeBuilder.build(name, value);
attrs.add(name);
Filter leaf;
switch (ct) {
case EQUALS:
case NOT_EQUALS:
if (specialAttrName.isEmpty()) {
if (specialAttrValue.isPresent() && specialAttrValue.get() == SpecialAttr.NULL) {
Filter empty = FilterBuilder.startsWith(AttributeBuilder.build(name, StringUtils.EMPTY));
if (ct == ConditionType.NOT_EQUALS) {
leaf = empty;
} else {
leaf = FilterBuilder.not(empty);
attrs.remove(name);
}
} else {
if (value.indexOf('%') == -1) {
leaf = sc.getConditionType() == ConditionType.CUSTOM
? FilterBuilder.equalsIgnoreCase(attr)
: FilterBuilder.equalTo(attr);
} else if (sc.getConditionType() != ConditionType.CUSTOM && value.startsWith("%")) {
leaf = FilterBuilder.endsWith(
AttributeBuilder.build(name, value.substring(1)));
} else if (sc.getConditionType() != ConditionType.CUSTOM && value.endsWith("%")) {
leaf = FilterBuilder.startsWith(
AttributeBuilder.build(name, value.substring(0, value.length() - 1)));
} else {
throw new IllegalArgumentException(
String.format("Unsupported search value %s", value));
}
if (ct == ConditionType.NOT_EQUALS) {
leaf = FilterBuilder.not(leaf);
}
}
} else {
throw new IllegalArgumentException(
String.format("Special attr name %s is not supported", specialAttrName));
}
break;
case GREATER_OR_EQUALS:
leaf = FilterBuilder.greaterThanOrEqualTo(attr);
break;
case GREATER_THAN:
leaf = FilterBuilder.greaterThan(attr);
break;
case LESS_OR_EQUALS:
leaf = FilterBuilder.lessThanOrEqualTo(attr);
break;
case LESS_THAN:
leaf = FilterBuilder.lessThan(attr);
break;
default:
throw new IllegalArgumentException(String.format("Condition type %s is not supported", ct.name()));
}
return leaf;
}