use of org.apache.syncope.core.persistence.jpa.entity.AbstractPlainAttrValue in project syncope by apache.
the class AbstractAnyDAO method findByPlainAttrValue.
@Override
@SuppressWarnings("unchecked")
public List<A> findByPlainAttrValue(final String schemaKey, final PlainAttrValue attrValue) {
PlainSchema schema = plainSchemaDAO().find(schemaKey);
if (schema == null) {
LOG.error("Invalid schema name '{}'", schemaKey);
return Collections.<A>emptyList();
}
String entityName = schema.isUniqueConstraint() ? anyUtils().plainAttrUniqueValueClass().getName() : anyUtils().plainAttrValueClass().getName();
Query query = findByPlainAttrValueQuery(entityName);
query.setParameter("schemaKey", schemaKey);
query.setParameter("stringValue", attrValue.getStringValue());
query.setParameter("booleanValue", attrValue.getBooleanValue() == null ? null : ((AbstractPlainAttrValue) attrValue).getBooleanAsInteger(attrValue.getBooleanValue()));
if (attrValue.getDateValue() == null) {
query.setParameter("dateValue", null);
} else {
query.setParameter("dateValue", attrValue.getDateValue(), TemporalType.TIMESTAMP);
}
query.setParameter("longValue", attrValue.getLongValue());
query.setParameter("doubleValue", attrValue.getDoubleValue());
List<A> result = new ArrayList<>();
((List<PlainAttrValue>) query.getResultList()).stream().forEach(value -> {
A any = (A) value.getAttr().getOwner();
if (!result.contains(any)) {
result.add(any);
}
});
return result;
}
Aggregations