import org.sakaiproject.site.api.Site; //导入方法依赖的package包/类
/**
* Get the members with the given role.
*
* Sorted by online status then display name. Maximum returned is 30 but can be overridden.
*
* @param siteId the site id to get the members for
* @param role the role we want to get the users for
* @return list of {@link GridPerson} or an empty list if none
*/
final List getMembersWithRole(final Site site, final SiteRole role,
final Set hiddenUserIds) {
List userList = new ArrayList<>();
Set userUuids = site.getUsersIsAllowed(role.getPermissionName());
userUuids.removeAll(hiddenUserIds);
final List users = this.userDirectoryService.getUsers(userUuids);
userList = this.connectionsLogic.getBasicConnections(users);
// sort
Collections.sort(userList, new Comparator() {
@Override
public int compare(final BasicConnection o1, final BasicConnection o2) {
// Here we sort the users by their online status. Annoyingly, the constants are
// 0: offline, 1: online, 2:away, so we can't just sort by that.
return new CompareToBuilder()
.append(o1.getOnlineStatus()==ProfileConstants.ONLINE_STATUS_OFFLINE?2:1,
o2.getOnlineStatus()==ProfileConstants.ONLINE_STATUS_OFFLINE?2:1)
.append(o1.getDisplayName(), o2.getDisplayName())
.toComparison();
}
});
// get slice
userList = userList
.stream()
.limit(this.maxUsers)
.collect(Collectors.toList());
List rval = new ArrayList<>();
for (BasicConnection person : userList) {
GridPerson gridPerson = new GridPerson();
gridPerson.uuid = person.getUuid();
gridPerson.displayName = person.getDisplayName();
gridPerson.role = role.toString();
gridPerson.onlineStatus = person.getOnlineStatus();
rval.add(gridPerson);
}
return rval;
}