Search in sources :

Example 1 with CurrentUserGroupInfo

use of org.hisp.dhis.user.CurrentUserGroupInfo in project dhis2-core by dhis2.

the class HibernateUserStore method getCurrentUserGroupInfo.

@Override
public CurrentUserGroupInfo getCurrentUserGroupInfo(long userId) {
    CriteriaBuilder builder = getCriteriaBuilder();
    CriteriaQuery<Object[]> query = builder.createQuery(Object[].class);
    Root<User> root = query.from(User.class);
    query.where(builder.equal(root.get("id"), userId));
    query.select(builder.array(root.get("uid"), root.join("groups", JoinType.LEFT).get("uid")));
    List<Object[]> results = getSession().createQuery(query).getResultList();
    CurrentUserGroupInfo currentUserGroupInfo = new CurrentUserGroupInfo();
    if (CollectionUtils.isEmpty(results)) {
        return currentUserGroupInfo;
    }
    for (Object[] result : results) {
        if (currentUserGroupInfo.getUserUID() == null) {
            currentUserGroupInfo.setUserUID(result[0].toString());
        }
        if (result[1] != null) {
            currentUserGroupInfo.getUserGroupUIDs().add(result[1].toString());
        }
    }
    return currentUserGroupInfo;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) User(org.hisp.dhis.user.User) CurrentUserGroupInfo(org.hisp.dhis.user.CurrentUserGroupInfo)

Aggregations

CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 CurrentUserGroupInfo (org.hisp.dhis.user.CurrentUserGroupInfo)1 User (org.hisp.dhis.user.User)1