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;
}
Aggregations