use of org.jooq.RecordHandler in project collect by openforis.
the class UserGroupDao method findUsersInGroup.
@SuppressWarnings({ "rawtypes", "unchecked" })
public List<UserInGroup> findUsersInGroup(final int userGroupId, final Integer userId) {
final List<UserInGroup> result = new ArrayList<UserInGroup>();
Condition conditions = OFC_USER_USERGROUP.GROUP_ID.eq(userGroupId);
if (userId != null) {
conditions = conditions.and(OFC_USER_USERGROUP.USER_ID.eq(userId));
}
dsl().select(OFC_USER_USERGROUP.USER_ID, OFC_USER_USERGROUP.ROLE_CODE, OFC_USER_USERGROUP.STATUS_CODE, OFC_USER_USERGROUP.REQUEST_DATE, OFC_USER_USERGROUP.MEMBER_SINCE, OFC_USER.USERNAME, OFC_USER.ENABLED).from(OFC_USER_USERGROUP).join(OFC_USER).on(OFC_USER.ID.eq(OFC_USER_USERGROUP.USER_ID)).where(conditions).orderBy(OFC_USER.USERNAME).fetchInto(new RecordHandler() {
public void next(Record record) {
UserInGroup userInGroup = new UserInGroup();
userInGroup.setGroupId(userGroupId);
userInGroup.setUserId(userId == null ? record.getValue(OFC_USER_USERGROUP.USER_ID) : userId);
userInGroup.setRole(UserGroupRole.fromCode(record.getValue(OFC_USER_USERGROUP.ROLE_CODE)));
userInGroup.setMemberSince(record.getValue(OFC_USER_USERGROUP.MEMBER_SINCE));
userInGroup.setRequestDate(record.getValue(OFC_USER_USERGROUP.REQUEST_DATE));
userInGroup.setJoinStatus(UserGroupJoinRequestStatus.fromCode(record.getValue(OFC_USER_USERGROUP.STATUS_CODE)));
result.add(userInGroup);
}
});
return result;
}
Aggregations