Search in sources :

Example 1 with RecordHandler

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;
}
Also used : Condition(org.jooq.Condition) UserInGroup(org.openforis.collect.model.UserInGroup) RecordHandler(org.jooq.RecordHandler) ArrayList(java.util.ArrayList) Record(org.jooq.Record) OfcUsergroupRecord(org.openforis.collect.persistence.jooq.tables.records.OfcUsergroupRecord)

Aggregations

ArrayList (java.util.ArrayList)1 Condition (org.jooq.Condition)1 Record (org.jooq.Record)1 RecordHandler (org.jooq.RecordHandler)1 UserInGroup (org.openforis.collect.model.UserInGroup)1 OfcUsergroupRecord (org.openforis.collect.persistence.jooq.tables.records.OfcUsergroupRecord)1