Search in sources :

Example 1 with AbstractPlainAttrValue

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;
}
Also used : Query(javax.persistence.Query) ArrayList(java.util.ArrayList) AbstractPlainAttrValue(org.apache.syncope.core.persistence.jpa.entity.AbstractPlainAttrValue) PlainAttrValue(org.apache.syncope.core.persistence.api.entity.PlainAttrValue) AbstractPlainAttrValue(org.apache.syncope.core.persistence.jpa.entity.AbstractPlainAttrValue) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema)

Aggregations

ArrayList (java.util.ArrayList)1 Query (javax.persistence.Query)1 PlainAttrValue (org.apache.syncope.core.persistence.api.entity.PlainAttrValue)1 PlainSchema (org.apache.syncope.core.persistence.api.entity.PlainSchema)1 AbstractPlainAttrValue (org.apache.syncope.core.persistence.jpa.entity.AbstractPlainAttrValue)1