use of org.olat.group.BusinessGroupMembership in project OpenOLAT by OpenOLAT.
the class MembersExportManager method getGroupMembershipMap.
public Map<Long, BusinessGroupMembership> getGroupMembershipMap(List<BusinessGroup> groups) {
List<BusinessGroupMembership> groupMemberships = businessGroupService.getBusinessGroupsMembership(groups);
Map<Long, BusinessGroupMembership> map = new HashMap<>();
for (BusinessGroupMembership membership : groupMemberships) {
map.put(membership.getIdentityKey(), membership);
}
return map;
}
use of org.olat.group.BusinessGroupMembership in project OpenOLAT by OpenOLAT.
the class GroupOverviewController method updateModel.
/**
* @param ureq
* @param control
* @param identity
* @return
*/
private void updateModel() {
SearchBusinessGroupParams params = new SearchBusinessGroupParams();
params.setIdentity(identity);
params.setOwner(true);
params.setAttendee(true);
params.setWaiting(true);
List<BusinessGroup> groups = businessGroupService.findBusinessGroups(params, null, 0, -1);
List<Long> groupKeysWithMembers;
if (groups.size() > 50) {
groupKeysWithMembers = null;
} else {
groupKeysWithMembers = new ArrayList<Long>(groups.size());
for (BusinessGroup view : groups) {
groupKeysWithMembers.add(view.getKey());
}
}
// retrieve all user's membership if there are more than 50 groups
List<BusinessGroupMembership> groupsAsOwner = businessGroupService.getBusinessGroupMembership(groupKeysWithMembers, identity);
Map<Long, BusinessGroupMembership> memberships = new HashMap<Long, BusinessGroupMembership>();
for (BusinessGroupMembership membership : groupsAsOwner) {
memberships.put(membership.getGroupKey(), membership);
}
List<GroupOverviewRow> items = new ArrayList<GroupOverviewRow>();
for (BusinessGroup group : groups) {
BusinessGroupMembership membership = memberships.get(group.getKey());
GroupOverviewRow tableItem = new GroupOverviewRow(group, membership, Boolean.TRUE);
items.add(tableItem);
}
tableDataModel.setEntries(items);
groupListCtr.modelChanged();
}
use of org.olat.group.BusinessGroupMembership in project OpenOLAT by OpenOLAT.
the class CheckListAssessmentController method loadDatas.
private List<CheckListAssessmentRow> loadDatas() {
if (!(coachCourseEnv instanceof UserCourseEnvironmentImpl)) {
return Collections.emptyList();
}
UserCourseEnvironmentImpl env = (UserCourseEnvironmentImpl) coachCourseEnv;
List<Checkbox> checkboxColl = checkboxList.getList();
int numOfCheckbox = checkboxList.getNumOfCheckbox();
boolean courseAdmin = env.isAdmin();
RepositoryEntry re = env.getCourseRepositoryEntry();
boolean courseTutor = repositoryService.hasRole(getIdentity(), re, GroupRoles.coach.name());
Set<Long> missingIdentityKeys = new HashSet<>();
if (courseTutor || courseAdmin) {
List<RepositoryEntryMembership> repoMemberships = repositoryManager.getRepositoryEntryMembership(re);
for (RepositoryEntryMembership repoMembership : repoMemberships) {
if (repoMembership.isParticipant()) {
missingIdentityKeys.add(repoMembership.getIdentityKey());
}
}
}
List<BusinessGroup> coachedGroups = courseAdmin ? coachCourseEnv.getCourseEnvironment().getCourseGroupManager().getAllBusinessGroups() : env.getCoachedGroups();
List<AssessmentData> dataList = checkboxManager.getAssessmentDatas(courseOres, courseNode.getIdent(), courseTutor || courseAdmin ? re : null, coachedGroups);
List<CheckListAssessmentRow> boxList = getAssessmentDataViews(dataList, checkboxColl);
Map<Long, CheckListAssessmentRow> identityToView = new HashMap<>();
for (CheckListAssessmentRow box : boxList) {
identityToView.put(box.getIdentityKey(), box);
missingIdentityKeys.remove(box.getIdentityKey());
}
List<BusinessGroupMembership> memberships = businessGroupService.getBusinessGroupsMembership(coachedGroups);
for (BusinessGroupMembership membership : memberships) {
if (!membership.isParticipant())
continue;
Long identityKey = membership.getIdentityKey();
if (!identityToView.containsKey(identityKey)) {
missingIdentityKeys.add(identityKey);
}
}
List<Identity> missingIdentities = securityManager.loadIdentityByKeys(missingIdentityKeys);
for (Identity missingIdentity : missingIdentities) {
Boolean[] checked = new Boolean[numOfCheckbox];
Float[] scores = new Float[numOfCheckbox];
CheckListAssessmentRow view = new CheckListAssessmentRow(missingIdentity, checked, scores, null, userPropertyHandlers, getLocale());
identityToView.put(missingIdentity.getKey(), view);
}
for (BusinessGroupMembership membership : memberships) {
if (!membership.isParticipant())
continue;
CheckListAssessmentRow view = identityToView.get(membership.getIdentityKey());
if (view != null) {
view.addGroupKey(membership.getGroupKey());
}
}
List<CheckListAssessmentRow> views = new ArrayList<>();
views.addAll(identityToView.values());
return views;
}
use of org.olat.group.BusinessGroupMembership in project OpenOLAT by OpenOLAT.
the class AbstractMemberListController method updateTableModel.
protected List<MemberView> updateTableModel(SearchMembersParams params) {
// course membership
boolean managedMembersRepo = RepositoryEntryManagedFlag.isManaged(repoEntry, RepositoryEntryManagedFlag.membersmanagement);
List<RepositoryEntryMembership> repoMemberships = repoEntry == null ? Collections.<RepositoryEntryMembership>emptyList() : repositoryManager.getRepositoryEntryMembership(repoEntry);
// groups membership
List<BusinessGroup> groups = repoEntry == null ? Collections.singletonList(businessGroup) : businessGroupService.findBusinessGroups(null, repoEntry, 0, -1);
List<Long> groupKeys = new ArrayList<Long>();
Map<Long, BusinessGroupShort> keyToGroupMap = new HashMap<>();
for (BusinessGroup group : groups) {
groupKeys.add(group.getKey());
keyToGroupMap.put(group.getKey(), group);
}
List<BusinessGroupMembership> memberships = groups.isEmpty() ? Collections.<BusinessGroupMembership>emptyList() : businessGroupService.getBusinessGroupsMembership(groups);
// get identities
Set<Long> identityKeys = new HashSet<>();
for (RepositoryEntryMembership membership : repoMemberships) {
identityKeys.add(membership.getIdentityKey());
}
for (BusinessGroupMembership membership : memberships) {
identityKeys.add(membership.getIdentityKey());
}
List<Identity> identities;
if (identityKeys.isEmpty()) {
identities = new ArrayList<>(0);
} else {
identities = filterIdentities(params, identityKeys);
}
Map<Long, MemberView> keyToMemberMap = new HashMap<>();
List<MemberView> memberList = new ArrayList<>();
Locale locale = getLocale();
// reservations
if (params.isPending()) {
List<OLATResource> resourcesForReservations = new ArrayList<>();
if (repoEntry != null) {
resourcesForReservations.add(repoEntry.getOlatResource());
}
for (BusinessGroup group : groups) {
resourcesForReservations.add(group.getResource());
}
List<ResourceReservation> reservations = acService.getReservations(resourcesForReservations);
List<Long> pendingIdentityKeys = new ArrayList<>(reservations.size());
for (ResourceReservation reservation : reservations) {
pendingIdentityKeys.add(reservation.getIdentity().getKey());
}
if (StringHelper.containsNonWhitespace(params.getSearchString()) || StringHelper.containsNonWhitespace(params.getLogin()) || (params.getUserPropertiesSearch() != null && !params.getUserPropertiesSearch().isEmpty())) {
List<Identity> pendingIdentities = filterIdentities(params, pendingIdentityKeys);
pendingIdentityKeys.retainAll(PersistenceHelper.toKeys(pendingIdentities));
}
for (ResourceReservation reservation : reservations) {
Identity identity = reservation.getIdentity();
if (pendingIdentityKeys.contains(identity.getKey())) {
MemberView member = new MemberView(identity, userPropertyHandlers, locale);
member.getMembership().setPending(true);
memberList.add(member);
forgeLinks(member);
keyToMemberMap.put(identity.getKey(), member);
}
}
}
Long me = getIdentity().getKey();
Set<Long> loadStatus = new HashSet<>();
for (Identity identity : identities) {
MemberView member = new MemberView(identity, userPropertyHandlers, locale);
if (chatEnabled) {
if (identity.getKey().equals(me)) {
member.setOnlineStatus("me");
} else if (sessionManager.isOnline(identity.getKey())) {
loadStatus.add(identity.getKey());
} else {
member.setOnlineStatus(Presence.unavailable.name());
}
}
memberList.add(member);
forgeLinks(member);
keyToMemberMap.put(identity.getKey(), member);
}
if (loadStatus.size() > 0) {
List<Long> statusToLoadList = new ArrayList<>(loadStatus);
Map<Long, String> statusMap = imService.getBuddyStatus(statusToLoadList);
for (Long toLoad : statusToLoadList) {
String status = statusMap.get(toLoad);
MemberView member = keyToMemberMap.get(toLoad);
if (status == null) {
member.setOnlineStatus(Presence.available.name());
} else {
member.setOnlineStatus(status);
}
}
}
for (BusinessGroupMembership membership : memberships) {
Long identityKey = membership.getIdentityKey();
MemberView memberView = keyToMemberMap.get(identityKey);
if (memberView != null) {
memberView.setFirstTime(membership.getCreationDate());
memberView.setLastTime(membership.getLastModified());
if (membership.isOwner()) {
memberView.getMembership().setGroupTutor(true);
}
if (membership.isParticipant()) {
memberView.getMembership().setGroupParticipant(true);
}
if (membership.isWaiting()) {
memberView.getMembership().setGroupWaiting(true);
}
Long groupKey = membership.getGroupKey();
BusinessGroupShort group = keyToGroupMap.get(groupKey);
memberView.addGroup(group);
}
}
for (RepositoryEntryMembership membership : repoMemberships) {
Long identityKey = membership.getIdentityKey();
MemberView memberView = keyToMemberMap.get(identityKey);
if (memberView != null) {
memberView.setFirstTime(membership.getCreationDate());
memberView.setLastTime(membership.getLastModified());
memberView.getMembership().setManagedMembersRepo(managedMembersRepo);
if (membership.isOwner()) {
memberView.getMembership().setRepoOwner(true);
}
if (membership.isCoach()) {
memberView.getMembership().setRepoTutor(true);
}
if (membership.isParticipant()) {
memberView.getMembership().setRepoParticipant(true);
}
}
}
if (repoEntry != null) {
Map<Long, Date> lastLaunchDates = userInfosMgr.getRecentLaunchDates(repoEntry.getOlatResource());
for (MemberView memberView : keyToMemberMap.values()) {
Long identityKey = memberView.getIdentityKey();
Date date = lastLaunchDates.get(identityKey);
memberView.setLastTime(date);
}
}
// the order of the filter is important
filterByRoles(memberList, params);
filterByOrigin(memberList, params);
memberListModel.setObjects(memberList);
membersTable.reset(true, true, true);
return memberList;
}
use of org.olat.group.BusinessGroupMembership in project OpenOLAT by OpenOLAT.
the class BusinessGroupListController method searchTableItems.
@Override
protected List<BGTableItem> searchTableItems(BusinessGroupQueryParams params) {
List<BusinessGroupRow> rows = businessGroupService.findBusinessGroupsWithMemberships(params, getIdentity());
List<BGTableItem> items = new ArrayList<>(rows.size());
for (BusinessGroupRow row : rows) {
BusinessGroupMembership membership = row.getMember();
Boolean allowLeave = membership != null;
Boolean allowDelete = isAdmin() ? Boolean.TRUE : (membership == null ? null : new Boolean(membership.isOwner()));
FormLink markLink = uifactory.addFormLink("mark_" + row.getKey(), "mark", "", null, null, Link.NONTRANSLATED);
markLink.setIconLeftCSS(row.isMarked() ? Mark.MARK_CSS_LARGE : Mark.MARK_ADD_CSS_LARGE);
BGTableItem item = new BGTableItem(row, markLink, allowLeave, allowDelete);
items.add(item);
}
return items;
}
Aggregations