use of org.apache.syncope.core.persistence.jpa.entity.JPAPlainSchema in project syncope by apache.
the class AbstractAnySearchDAO method check.
protected Triple<PlainSchema, PlainAttrValue, AnyCond> check(final AnyCond cond, final AnyTypeKind kind) {
AnyCond condClone = SerializationUtils.clone(cond);
AnyUtils attrUtils = anyUtilsFactory.getInstance(kind);
// Keeps track of difference between entity's getKey() and JPA @Id fields
if ("key".equals(condClone.getSchema())) {
condClone.setSchema("id");
}
Field anyField = ReflectionUtils.findField(attrUtils.anyClass(), condClone.getSchema());
if (anyField == null) {
LOG.warn("Ignoring invalid schema '{}'", condClone.getSchema());
throw new IllegalArgumentException();
}
PlainSchema schema = new JPAPlainSchema();
schema.setKey(anyField.getName());
for (AttrSchemaType attrSchemaType : AttrSchemaType.values()) {
if (anyField.getType().isAssignableFrom(attrSchemaType.getType())) {
schema.setType(attrSchemaType);
}
}
// Deal with any Integer fields logically mapping to boolean values
boolean foundBooleanMin = false;
boolean foundBooleanMax = false;
if (Integer.class.equals(anyField.getType())) {
for (Annotation annotation : anyField.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(AttrSchemaType.Boolean);
}
// Deal with any fields representing relationships to other entities
if (anyField.getType().getAnnotation(Entity.class) != null) {
Method relMethod = null;
try {
relMethod = ClassUtils.getPublicMethod(anyField.getType(), "getKey", new Class<?>[0]);
} catch (Exception e) {
LOG.error("Could not find {}#getKey", anyField.getType(), e);
}
if (relMethod != null && String.class.isAssignableFrom(relMethod.getReturnType())) {
condClone.setSchema(condClone.getSchema() + "_id");
schema.setType(AttrSchemaType.String);
}
}
PlainAttrValue attrValue = attrUtils.newPlainAttrValue();
if (condClone.getType() != AttributeCond.Type.LIKE && condClone.getType() != AttributeCond.Type.ILIKE && condClone.getType() != AttributeCond.Type.ISNULL && condClone.getType() != AttributeCond.Type.ISNOTNULL) {
try {
((JPAPlainSchema) schema).validator().validate(condClone.getExpression(), attrValue);
} catch (ValidationException e) {
LOG.error("Could not validate expression '" + condClone.getExpression() + "'", e);
throw new IllegalArgumentException();
}
}
return Triple.of(schema, attrValue, condClone);
}
use of org.apache.syncope.core.persistence.jpa.entity.JPAPlainSchema in project syncope by apache.
the class AbstractAnySearchDAO method check.
protected Pair<PlainSchema, PlainAttrValue> check(final AttributeCond cond, final AnyTypeKind kind) {
AnyUtils attrUtils = anyUtilsFactory.getInstance(kind);
PlainSchema schema = schemaDAO.find(cond.getSchema());
if (schema == null) {
LOG.warn("Ignoring invalid schema '{}'", cond.getSchema());
throw new IllegalArgumentException();
}
PlainAttrValue attrValue = attrUtils.newPlainAttrValue();
try {
if (cond.getType() != AttributeCond.Type.LIKE && cond.getType() != AttributeCond.Type.ILIKE && cond.getType() != AttributeCond.Type.ISNULL && cond.getType() != AttributeCond.Type.ISNOTNULL) {
((JPAPlainSchema) schema).validator().validate(cond.getExpression(), attrValue);
}
} catch (ValidationException e) {
LOG.error("Could not validate expression '" + cond.getExpression() + "'", e);
throw new IllegalArgumentException();
}
return Pair.of(schema, attrValue);
}
Aggregations