if (subjectField == null) {
LOG.warn("Ignoring invalid schema '{}'", cond.getSchema());
return EMPTY_ATTR_QUERY;
}
AbstractNormalSchema schema = attrUtil.newSchema();
schema.setName(subjectField.getName());
for (AttributeSchemaType attrSchemaType : AttributeSchemaType.values()) {
if (subjectField.getType().isAssignableFrom(attrSchemaType.getType())) {
schema.setType(attrSchemaType);
}
}
// Deal with subject Integer fields logically mapping to boolean values
// (SyncopeRole.inheritAttrs, for example)
boolean foundBooleanMin = false;
boolean foundBooleanMax = false;
if (Integer.class.equals(subjectField.getType())) {
for (Annotation annotation : subjectField.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) {
schema.setType(AttributeSchemaType.Boolean);
}
// Deal with subject fields representing relationships to other entities
// Only _id and _name are suppored
if (subjectField.getType().getAnnotation(Entity.class) != null) {
if (BeanUtils.findDeclaredMethodWithMinimalParameters(subjectField.getType(), "getId") != null) {
cond.setSchema(cond.getSchema() + "_id");
schema.setType(AttributeSchemaType.Long);
}
if (BeanUtils.findDeclaredMethodWithMinimalParameters(subjectField.getType(), "getName") != null) {
cond.setSchema(cond.getSchema() + "_name");
schema.setType(AttributeSchemaType.String);
}
}
AbstractAttrValue attrValue = attrUtil.newAttrValue();
if (cond.getType() != AttributeCond.Type.LIKE && cond.getType() != AttributeCond.Type.ISNULL
&& cond.getType() != AttributeCond.Type.ISNOTNULL) {
try {
schema.getValidator().validate(cond.getExpression(), attrValue);
} catch (ValidationException e) {
LOG.error("Could not validate expression '" + cond.getExpression() + "'", e);
return EMPTY_ATTR_QUERY;
}
}