if (searchClauses.isEmpty() || searchClauses.get(0).getType() == null) {
return StringUtils.EMPTY;
}
SyncopeFiqlSearchConditionBuilder builder = getSearchConditionBuilder();
CompleteCondition prevCondition;
CompleteCondition condition = null;
for (int i = 0; i < searchClauses.size(); i++) {
prevCondition = condition;
switch (searchClauses.get(i).getType()) {
case ENTITLEMENT:
condition = searchClauses.get(i).getComparator() == SearchClause.Comparator.EQUALS
? ((RoleFiqlSearchConditionBuilder) builder).
hasEntitlements(searchClauses.get(i).getProperty())
: ((RoleFiqlSearchConditionBuilder) builder).
hasNotEntitlements(searchClauses.get(i).getProperty());
break;
case MEMBERSHIP:
Long roleId = NumberUtils.toLong(searchClauses.get(i).getProperty().split(" ")[0]);
condition = searchClauses.get(i).getComparator() == SearchClause.Comparator.EQUALS
? ((UserFiqlSearchConditionBuilder) builder).hasRoles(roleId)
: ((UserFiqlSearchConditionBuilder) builder).hasNotRoles(roleId);
break;
case RESOURCE:
condition = searchClauses.get(i).getComparator() == SearchClause.Comparator.EQUALS
? builder.hasResources(searchClauses.get(i).getProperty())
: builder.hasNotResources(searchClauses.get(i).getProperty());
break;
case ATTRIBUTE:
SyncopeProperty property = builder.is(searchClauses.get(i).getProperty());
switch (searchClauses.get(i).getComparator()) {
case IS_NULL:
condition = builder.isNull(searchClauses.get(i).getProperty());
break;
case IS_NOT_NULL:
condition = builder.isNotNull(searchClauses.get(i).getProperty());
break;
case LESS_THAN:
condition = StringUtils.isNumeric(searchClauses.get(i).getProperty())
? property.lessThan(NumberUtils.toDouble(searchClauses.get(i).getValue()))
: property.lexicalBefore(searchClauses.get(i).getValue());
break;
case LESS_OR_EQUALS:
condition = StringUtils.isNumeric(searchClauses.get(i).getProperty())
? property.lessOrEqualTo(NumberUtils.toDouble(searchClauses.get(i).getValue()))
: property.lexicalNotAfter(searchClauses.get(i).getValue());
break;
case GREATER_THAN:
condition = StringUtils.isNumeric(searchClauses.get(i).getProperty())
? property.greaterThan(NumberUtils.toDouble(searchClauses.get(i).getValue()))
: property.lexicalAfter(searchClauses.get(i).getValue());
break;
case GREATER_OR_EQUALS:
condition = StringUtils.isNumeric(searchClauses.get(i).getProperty())
? property.greaterOrEqualTo(NumberUtils.toDouble(searchClauses.get(i).getValue()))
: property.lexicalNotBefore(searchClauses.get(i).getValue());
break;
case NOT_EQUALS:
condition = property.notEqualTo(searchClauses.get(i).getValue());
break;
case EQUALS:
default:
condition = property.equalTo(searchClauses.get(i).getValue());
break;
}
default:
break;
}
if (i > 0) {
if (searchClauses.get(i).getOperator() == SearchClause.Operator.AND) {
condition = builder.and(prevCondition, condition);
}
if (searchClauses.get(i).getOperator() == SearchClause.Operator.OR) {
condition = builder.or(prevCondition, condition);
}
}
}
String fiql = condition == null ? StringUtils.EMPTY : condition.query();