use of org.apache.cxf.jaxrs.ext.search.client.CompleteCondition in project cxf by apache.
the class SearchContextImpl method convertPlainQueriesToFiqlExp.
private String convertPlainQueriesToFiqlExp(MultivaluedMap<String, String> params) {
SearchConditionBuilder builder = SearchConditionBuilder.instance();
List<CompleteCondition> list = new ArrayList<>(params.size());
for (Map.Entry<String, List<String>> entry : params.entrySet()) {
list.add(getOrCondition(builder, entry));
}
return builder.and(list).query();
}
use of org.apache.cxf.jaxrs.ext.search.client.CompleteCondition in project syncope by apache.
the class SearchUtils method buildFIQL.
public static String buildFIQL(final List<SearchClause> clauses, final AbstractFiqlSearchConditionBuilder builder, final Map<String, PlainSchemaTO> availableSchemaTypes) {
LOG.debug("Generating FIQL from List<SearchClause>: {}", clauses);
CompleteCondition prevCondition;
CompleteCondition condition = null;
boolean notTheFirst = false;
for (SearchClause clause : clauses) {
prevCondition = condition;
if (clause.getType() != null) {
String value = clause.getValue() == null ? null : clause.getValue().replace(",", "%252C").replace(";", "%253B");
switch(clause.getType()) {
case GROUP_MEMBER:
switch(clause.getComparator()) {
case EQUALS:
condition = ((GroupFiqlSearchConditionBuilder) builder).withMembers(value);
break;
case NOT_EQUALS:
condition = ((GroupFiqlSearchConditionBuilder) builder).withoutMembers(value);
break;
default:
}
break;
case GROUP_MEMBERSHIP:
if (StringUtils.isNotBlank(clause.getProperty())) {
String groupKey = clause.getProperty();
if (builder instanceof UserFiqlSearchConditionBuilder) {
condition = clause.getComparator() == SearchClause.Comparator.EQUALS ? ((UserFiqlSearchConditionBuilder) builder).inGroups(groupKey) : ((UserFiqlSearchConditionBuilder) builder).notInGroups(groupKey);
} else {
condition = clause.getComparator() == SearchClause.Comparator.EQUALS ? ((AnyObjectFiqlSearchConditionBuilder) builder).inGroups(groupKey) : ((AnyObjectFiqlSearchConditionBuilder) builder).notInGroups(groupKey);
}
}
break;
case RESOURCE:
if (StringUtils.isNotBlank(clause.getProperty())) {
condition = clause.getComparator() == SearchClause.Comparator.EQUALS ? builder.hasResources(clause.getProperty()) : builder.hasNotResources(clause.getProperty());
}
break;
case ATTRIBUTE:
if (StringUtils.isNotBlank(clause.getProperty())) {
boolean isLong = false;
boolean isDouble = false;
if (availableSchemaTypes.get(clause.getProperty()) != null) {
isLong = availableSchemaTypes.get(clause.getProperty()).getType() == AttrSchemaType.Long;
isDouble = availableSchemaTypes.get(clause.getProperty()).getType() == AttrSchemaType.Double;
}
SyncopeProperty property = builder.is(clause.getProperty());
switch(clause.getComparator()) {
case IS_NULL:
condition = builder.isNull(clause.getProperty());
break;
case IS_NOT_NULL:
condition = builder.isNotNull(clause.getProperty());
break;
case LESS_THAN:
condition = isLong ? property.lessThan(NumberUtils.toLong(value)) : isDouble ? property.lessThan(NumberUtils.toDouble(value)) : property.lexicalBefore(value);
break;
case LESS_OR_EQUALS:
condition = isLong ? property.lessOrEqualTo(NumberUtils.toLong(value)) : isDouble ? property.lessOrEqualTo(NumberUtils.toDouble(value)) : property.lexicalNotAfter(value);
break;
case GREATER_THAN:
condition = isLong ? property.greaterThan(NumberUtils.toLong(value)) : isDouble ? property.greaterThan(NumberUtils.toDouble(value)) : property.lexicalAfter(value);
break;
case GREATER_OR_EQUALS:
condition = isLong ? property.greaterOrEqualTo(NumberUtils.toLong(value)) : isDouble ? property.greaterOrEqualTo(NumberUtils.toDouble(value)) : property.lexicalNotBefore(value);
break;
case NOT_EQUALS:
condition = property.notEqualTolIgnoreCase(value);
break;
case EQUALS:
condition = isLong ? property.equalTo(NumberUtils.toLong(value)) : isDouble ? property.equalTo(NumberUtils.toDouble(value)) : property.equalToIgnoreCase(value);
break;
default:
condition = property.equalToIgnoreCase(value);
break;
}
}
break;
case ROLE_MEMBERSHIP:
if (StringUtils.isNotBlank(clause.getProperty())) {
switch(clause.getComparator()) {
case EQUALS:
condition = ((UserFiqlSearchConditionBuilder) builder).inRoles(clause.getProperty());
break;
case NOT_EQUALS:
condition = ((UserFiqlSearchConditionBuilder) builder).notInRoles(clause.getProperty());
break;
default:
break;
}
}
break;
case PRIVILEGE:
if (StringUtils.isNotBlank(clause.getProperty())) {
switch(clause.getComparator()) {
case EQUALS:
condition = ((UserFiqlSearchConditionBuilder) builder).withPrivileges(clause.getProperty());
break;
case NOT_EQUALS:
condition = ((UserFiqlSearchConditionBuilder) builder).withoutPrivileges(clause.getProperty());
break;
default:
break;
}
}
break;
case RELATIONSHIP:
if (StringUtils.isNotBlank(clause.getProperty())) {
if (builder instanceof UserFiqlSearchConditionBuilder) {
switch(clause.getComparator()) {
case IS_NOT_NULL:
condition = ((UserFiqlSearchConditionBuilder) builder).inRelationshipTypes(clause.getProperty());
break;
case IS_NULL:
condition = ((UserFiqlSearchConditionBuilder) builder).notInRelationshipTypes(clause.getProperty());
break;
case EQUALS:
condition = ((UserFiqlSearchConditionBuilder) builder).inRelationships(value);
break;
case NOT_EQUALS:
condition = ((UserFiqlSearchConditionBuilder) builder).notInRelationships(value);
break;
default:
break;
}
} else {
switch(clause.getComparator()) {
case IS_NOT_NULL:
condition = ((AnyObjectFiqlSearchConditionBuilder) builder).inRelationshipTypes(clause.getProperty());
break;
case IS_NULL:
condition = ((AnyObjectFiqlSearchConditionBuilder) builder).notInRelationshipTypes(clause.getProperty());
break;
case EQUALS:
condition = ((AnyObjectFiqlSearchConditionBuilder) builder).inRelationships(value);
break;
case NOT_EQUALS:
condition = ((AnyObjectFiqlSearchConditionBuilder) builder).notInRelationships(value);
break;
default:
break;
}
}
}
break;
default:
break;
}
}
if (notTheFirst) {
if (clause.getOperator() == SearchClause.Operator.AND) {
condition = builder.and(prevCondition, condition);
}
if (clause.getOperator() == SearchClause.Operator.OR) {
condition = builder.or(prevCondition, condition);
}
}
notTheFirst = true;
}
String fiql = condition == null ? null : condition.query();
LOG.debug("Generated FIQL: {}", fiql);
return fiql;
}
Aggregations