use of io.gravitee.management.model.GroupMemberEntity in project gravitee-management-rest-api by gravitee-io.
the class GroupMembersResource method getMembers.
@GET
@Produces(io.gravitee.common.http.MediaType.APPLICATION_JSON)
@ApiOperation(value = "List Group members")
@ApiResponses({ @ApiResponse(code = 200, message = "List of Group's members", response = MemberEntity.class, responseContainer = "List"), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.MANAGEMENT_GROUP, acls = RolePermissionAction.READ) })
public List<GroupMemberEntity> getMembers(@PathParam("group") String group) {
// check that group exists
groupService.findById(group);
Map<String, List<MemberEntity>> membersWithApplicationRole = membershipService.getMembers(MembershipReferenceType.GROUP, group, RoleScope.APPLICATION).stream().filter(Objects::nonNull).collect(Collectors.groupingBy(MemberEntity::getId));
Map<String, List<MemberEntity>> membersWithApiRole = membershipService.getMembers(MembershipReferenceType.GROUP, group, RoleScope.API).stream().filter(Objects::nonNull).collect(Collectors.groupingBy(MemberEntity::getId));
Set<String> ids = new HashSet<>();
ids.addAll(membersWithApiRole.keySet());
ids.addAll(membersWithApplicationRole.keySet());
return ids.stream().map(id -> {
MemberEntity memberWithApiRole = Objects.isNull(membersWithApiRole.get(id)) ? null : membersWithApiRole.get(id).get(0);
MemberEntity memberWithApplicationRole = Objects.isNull(membersWithApplicationRole.get(id)) ? null : membersWithApplicationRole.get(id).get(0);
GroupMemberEntity groupMemberEntity = new GroupMemberEntity(Objects.nonNull(memberWithApiRole) ? memberWithApiRole : memberWithApplicationRole);
groupMemberEntity.setRoles(new HashMap<>());
if (Objects.nonNull(memberWithApiRole)) {
groupMemberEntity.getRoles().put(RoleScope.API.name(), memberWithApiRole.getRole());
}
if (Objects.nonNull(memberWithApplicationRole)) {
groupMemberEntity.getRoles().put(RoleScope.APPLICATION.name(), memberWithApplicationRole.getRole());
}
return groupMemberEntity;
}).sorted(Comparator.comparing(GroupMemberEntity::getId)).collect(Collectors.toList());
}
Aggregations