use of io.apiman.manager.api.beans.members.MemberRoleBean 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());
});
}
use of io.apiman.manager.api.beans.members.MemberRoleBean 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();
}
}
Aggregations