in core/persistence-neo4j/src/main/java/org/apache/syncope/core/persistence/neo4j/dao/Neo4jAnySearchDAO.java [385:509]
protected void fillAttrQuery(
final TextStringBuilder query,
final PlainAttrValue attrValue,
final PlainSchema schema,
final AttrCond cond,
final boolean not,
final Map<String, Object> parameters) {
if (not && cond.getType() == AttrCond.Type.ISNULL) {
cond.setType(AttrCond.Type.ISNOTNULL);
fillAttrQuery(query, attrValue, schema, cond, true, parameters);
return;
}
if (not) {
if (schema.isUniqueConstraint()) {
fillAttrQuery(query, attrValue, schema, cond, false, parameters);
query.replaceFirst("WHERE", "WHERE NOT(");
query.append(')');
} else {
fillAttrQuery(query, attrValue, schema, cond, false, parameters);
query.replaceAll("any(", schema.getKey() + " IS NULL OR none(");
}
return;
}
String value = Optional.ofNullable(attrValue.getDateValue()).
map(DateTimeFormatter.ISO_OFFSET_DATE_TIME::format).
orElseGet(cond::getExpression);
boolean isStr = true;
boolean lower = false;
if (schema.getType().isStringClass()) {
lower = (cond.getType() == AttrCond.Type.IEQ || cond.getType() == AttrCond.Type.ILIKE);
} else if (schema.getType() != AttrSchemaType.Date) {
lower = false;
try {
switch (schema.getType()) {
case Long ->
Long.valueOf(value);
case Double ->
Double.valueOf(value);
case Boolean -> {
if (!("true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value))) {
throw new IllegalArgumentException();
}
}
default -> {
}
}
isStr = false;
} catch (Exception nfe) {
// ignore
}
}
query.append("WHERE ");
switch (cond.getType()) {
case ISNULL -> {
}
case ISNOTNULL ->
query.append(schema.getKey()).append(" IS NOT NULL");
case ILIKE, LIKE -> {
if (schema.getType().isStringClass()) {
appendPlainAttrCond(
query,
schema,
" =~ \"" + (lower ? "(?i)" : "")
+ AnyRepoExt.escapeForLikeRegex(value).replace("%", ".*") + '"');
} else {
query.append(ALWAYS_FALSE_CLAUSE);
LOG.error("LIKE is only compatible with string or enum schemas");
}
}
case IEQ, EQ -> {
if (StringUtils.containsAny(value, AnyRepoExt.REGEX_CHARS) || lower) {
appendPlainAttrCond(
query,
schema,
" =~ \"^" + (lower ? "(?i)" : "")
+ AnyRepoExt.escapeForLikeRegex(value).replace("%", ".*") + "$\"");
} else {
appendPlainAttrCond(
query,
schema,
" = " + escapeIfString(value, isStr));
}
}
case GE ->
appendPlainAttrCond(
query,
schema,
" >= " + escapeIfString(value, isStr));
case GT ->
appendPlainAttrCond(
query,
schema,
" > " + escapeIfString(value, isStr));
case LE ->
appendPlainAttrCond(
query,
schema,
" <= " + escapeIfString(value, isStr));
case LT ->
appendPlainAttrCond(
query,
schema,
" < " + escapeIfString(value, isStr));
default -> {
}
}
// shouldn't occour: processed before
}