Search in sources :

Example 1 with MemberBean

use of io.apiman.manager.api.beans.members.MemberBean in project apiman by apiman.

the class OrganizationService method listMembers.

public List<MemberBean> listMembers(String organizationId) throws OrganizationNotFoundException, NotAuthorizedException {
    getOrg(organizationId);
    return tryAction(() -> {
        Set<RoleMembershipBean> memberships = query.getOrgMemberships(organizationId);
        TreeMap<String, MemberBean> members = new TreeMap<>();
        for (RoleMembershipBean membershipBean : memberships) {
            String userId = membershipBean.getUserId();
            String roleId = membershipBean.getRoleId();
            RoleBean role = storage.getRole(roleId);
            // Role does not exist!
            if (role == null) {
                continue;
            }
            MemberBean member = members.get(userId);
            if (member == null) {
                UserBean user = storage.getUser(userId);
                member = new MemberBean();
                member.setEmail(user.getEmail());
                member.setUserId(userId);
                member.setUserName(user.getFullName());
                member.setRoles(new ArrayList<>());
                members.put(userId, member);
            }
            MemberRoleBean mrb = new MemberRoleBean();
            mrb.setRoleId(roleId);
            mrb.setRoleName(role.getName());
            member.getRoles().add(mrb);
            if (member.getJoinedOn() == null || membershipBean.getCreatedOn().compareTo(member.getJoinedOn()) < 0) {
                member.setJoinedOn(membershipBean.getCreatedOn());
            }
        }
        return new ArrayList<>(members.values());
    });
}
Also used : RoleMembershipBean(io.apiman.manager.api.beans.idm.RoleMembershipBean) MemberBean(io.apiman.manager.api.beans.members.MemberBean) UserBean(io.apiman.manager.api.beans.idm.UserBean) RoleBean(io.apiman.manager.api.beans.idm.RoleBean) MemberRoleBean(io.apiman.manager.api.beans.members.MemberRoleBean) MemberRoleBean(io.apiman.manager.api.beans.members.MemberRoleBean) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap)

Example 2 with MemberBean

use of io.apiman.manager.api.beans.members.MemberBean in project apiman by apiman.

the class OrganizationResourceImpl method listMembers.

/**
 * @see IOrganizationResource#listMembers(java.lang.String)
 */
@Override
public List<MemberBean> listMembers(String organizationId) throws OrganizationNotFoundException, NotAuthorizedException {
    // Only members are allowed to see other members
    if (!securityContext.isMemberOf(organizationId)) {
        throw ExceptionFactory.notAuthorizedException();
    }
    get(organizationId);
    try {
        Set<RoleMembershipBean> memberships = query.getOrgMemberships(organizationId);
        TreeMap<String, MemberBean> members = new TreeMap<>();
        storage.beginTx();
        for (RoleMembershipBean membershipBean : memberships) {
            String userId = membershipBean.getUserId();
            String roleId = membershipBean.getRoleId();
            RoleBean role = storage.getRole(roleId);
            // Role does not exist!
            if (role == null) {
                continue;
            }
            MemberBean member = members.get(userId);
            if (member == null) {
                UserBean user = storage.getUser(userId);
                member = new MemberBean();
                member.setEmail(user.getEmail());
                member.setUserId(userId);
                member.setUserName(user.getFullName());
                member.setRoles(new ArrayList<>());
                members.put(userId, member);
            }
            MemberRoleBean mrb = new MemberRoleBean();
            mrb.setRoleId(roleId);
            mrb.setRoleName(role.getName());
            member.getRoles().add(mrb);
            if (member.getJoinedOn() == null || membershipBean.getCreatedOn().compareTo(member.getJoinedOn()) < 0) {
                member.setJoinedOn(membershipBean.getCreatedOn());
            }
        }
        return new ArrayList<>(members.values());
    } catch (StorageException e) {
        throw new SystemErrorException(e);
    } finally {
        storage.rollbackTx();
    }
}
Also used : SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) MemberRoleBean(io.apiman.manager.api.beans.members.MemberRoleBean) RoleBean(io.apiman.manager.api.beans.idm.RoleBean) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) RoleMembershipBean(io.apiman.manager.api.beans.idm.RoleMembershipBean) MemberBean(io.apiman.manager.api.beans.members.MemberBean) UserBean(io.apiman.manager.api.beans.idm.UserBean) MemberRoleBean(io.apiman.manager.api.beans.members.MemberRoleBean) StorageException(io.apiman.manager.api.core.exceptions.StorageException)

Aggregations

RoleBean (io.apiman.manager.api.beans.idm.RoleBean)2 RoleMembershipBean (io.apiman.manager.api.beans.idm.RoleMembershipBean)2 UserBean (io.apiman.manager.api.beans.idm.UserBean)2 MemberBean (io.apiman.manager.api.beans.members.MemberBean)2 MemberRoleBean (io.apiman.manager.api.beans.members.MemberRoleBean)2 ArrayList (java.util.ArrayList)2 TreeMap (java.util.TreeMap)2 StorageException (io.apiman.manager.api.core.exceptions.StorageException)1 SystemErrorException (io.apiman.manager.api.rest.exceptions.SystemErrorException)1