if (attributableField == null) {
LOG.warn("Ignoring invalid schema '{}'", cond.getSchema());
return EMPTY_ATTR_QUERY;
}
AbstractSchema schema = attrUtil.newSchema();
schema.setName(attributableField.getName());
for (AttributeSchemaType type : AttributeSchemaType.values()) {
if (attributableField.getType().isAssignableFrom(type.getType())) {
schema.setType(type);
}
}
// Deal with Attributable Integer fields logically mapping to boolean values
// (SyncopeRole.inheritAttributes, for example)
boolean foundBooleanMin = false;
boolean foundBooleanMax = false;
if (Integer.class.equals(attributableField.getType())) {
for (Annotation annotation : attributableField.getAnnotations()) {
if (Min.class.equals(annotation.annotationType())) {
foundBooleanMin = ((Min) annotation).value() == 0;
} else if (Max.class.equals(annotation.annotationType())) {
foundBooleanMax = ((Max) annotation).value() == 1;
}
}
}
if (foundBooleanMin && foundBooleanMax) {
if ("true".equalsIgnoreCase(cond.getExpression())) {
cond.setExpression("1");
schema.setType(AttributeSchemaType.Long);
} else if ("false".equalsIgnoreCase(cond.getExpression())) {
cond.setExpression("0");
schema.setType(AttributeSchemaType.Long);
}
}
// Deal with Attributable fields representing relationships to other entities
// Only _id and _name are suppored
if (attributableField.getType().getAnnotation(Entity.class) != null) {
if (BeanUtils.findDeclaredMethodWithMinimalParameters(attributableField.getType(), "getId") != null) {
cond.setSchema(cond.getSchema() + "_id");
schema.setType(AttributeSchemaType.Long);
}
if (BeanUtils.findDeclaredMethodWithMinimalParameters(attributableField.getType(), "getName") != null) {
cond.setSchema(cond.getSchema() + "_name");
schema.setType(AttributeSchemaType.String);
}
}
AbstractAttrValue attrValue = attrUtil.newAttrValue();
try {
if (cond.getType() != AttributeCond.Type.LIKE && cond.getType() != AttributeCond.Type.ISNULL
&& cond.getType() != AttributeCond.Type.ISNOTNULL) {
schema.getValidator().validate(cond.getExpression(), attrValue);
}
} catch (ValidationException e) {
LOG.error("Could not validate expression '" + cond.getExpression() + "'", e);
return EMPTY_ATTR_QUERY;
}