String value = SearchUtils.toSqlWildcardString(sc.getStatement().getValue().toString(), false).
replaceAll("\\\\_", "_");
SpecialAttr specialAttrValue = SpecialAttr.fromString(value);
AttributeCond attributeCond = createAttributeCond(name);
attributeCond.setExpression(value);
SearchCond leaf;
switch (sc.getConditionType()) {
case EQUALS:
case NOT_EQUALS:
if (specialAttrName == null) {
if (specialAttrValue != null && specialAttrValue == SpecialAttr.NULL) {
attributeCond.setType(AttributeCond.Type.ISNULL);
attributeCond.setExpression(null);
} else if (value.indexOf('%') == -1) {
attributeCond.setType(AttributeCond.Type.EQ);
} else {
attributeCond.setType(AttributeCond.Type.LIKE);
}
leaf = SearchCond.getLeafCond(attributeCond);
} else {
switch (specialAttrName) {
case ROLES:
MembershipCond membershipCond = new MembershipCond();
membershipCond.setRoleId(Long.valueOf(value));
leaf = SearchCond.getLeafCond(membershipCond);
break;
case RESOURCES:
ResourceCond resourceCond = new ResourceCond();
resourceCond.setResourceName(value);
leaf = SearchCond.getLeafCond(resourceCond);
break;
case ENTITLEMENTS:
EntitlementCond entitlementCond = new EntitlementCond();
entitlementCond.setExpression(value);
leaf = SearchCond.getLeafCond(entitlementCond);
break;
default:
throw new IllegalArgumentException(
String.format("Special attr name %s is not supported", specialAttrName));
}
}
if (sc.getConditionType() == ConditionType.NOT_EQUALS) {
if (leaf.getAttributeCond() != null
&& leaf.getAttributeCond().getType() == AttributeCond.Type.ISNULL) {
leaf.getAttributeCond().setType(AttributeCond.Type.ISNOTNULL);
} else if (leaf.getSubjectCond() != null
&& leaf.getSubjectCond().getType() == SubjectCond.Type.ISNULL) {
leaf.getSubjectCond().setType(AttributeCond.Type.ISNOTNULL);
} else {
leaf = SearchCond.getNotLeafCond(leaf);
}
}
break;
case GREATER_OR_EQUALS:
attributeCond.setType(AttributeCond.Type.GE);
leaf = SearchCond.getLeafCond(attributeCond);
break;
case GREATER_THAN:
attributeCond.setType(AttributeCond.Type.GT);
leaf = SearchCond.getLeafCond(attributeCond);
break;
case LESS_OR_EQUALS:
attributeCond.setType(AttributeCond.Type.LE);
leaf = SearchCond.getLeafCond(attributeCond);
break;
case LESS_THAN:
attributeCond.setType(AttributeCond.Type.LT);
leaf = SearchCond.getLeafCond(attributeCond);
break;
default:
throw new IllegalArgumentException(