use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.
the class CourseOverviewController method doLeave.
/**
* The method check the managed flags
* @param ureq
* @param views
*/
private void doLeave(UserRequest ureq, Collection<CourseMemberView> views) {
List<Long> groupKeys = new ArrayList<Long>();
List<RepositoryEntry> repoEntryToLeave = new ArrayList<RepositoryEntry>();
for (CourseMemberView view : views) {
for (BusinessGroupShort group : view.getGroups()) {
if (!BusinessGroupManagedFlag.isManaged(group.getManagedFlags(), BusinessGroupManagedFlag.membersmanagement)) {
groupKeys.add(group.getKey());
}
}
RepositoryEntry re = repositoryManager.lookupRepositoryEntry(view.getRepoKey());
if (!RepositoryEntryManagedFlag.isManaged(re, RepositoryEntryManagedFlag.membersmanagement)) {
repoEntryToLeave.add(re);
if (view.getMembership().isRepoOwner()) {
int numOfOwners = repositoryService.countMembers(re, GroupRoles.owner.name());
if (numOfOwners == 1) {
showError("error.atleastone", view.getDisplayName());
// break the process
return;
}
}
}
}
List<BusinessGroup> groupsToLeave = businessGroupService.loadBusinessGroups(groupKeys);
List<BusinessGroup> groupsToDelete = new ArrayList<BusinessGroup>(1);
for (BusinessGroup group : groupsToLeave) {
int numOfOwners = businessGroupService.countMembers(group, GroupRoles.coach.name());
int numOfParticipants = businessGroupService.countMembers(group, GroupRoles.participant.name());
if ((numOfOwners == 1 && numOfParticipants == 0) || (numOfOwners == 0 && numOfParticipants == 1)) {
groupsToDelete.add(group);
}
}
removeFromCourseDlg = new CourseLeaveDialogBoxController(ureq, getWindowControl(), editedIdentity, repoEntryToLeave, groupsToLeave, groupsToDelete);
listenTo(removeFromCourseDlg);
cmc = new CloseableModalController(getWindowControl(), translate("close"), removeFromCourseDlg.getInitialComponent(), true, translate("unsubscribe.title"));
cmc.activate();
listenTo(cmc);
}
use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.
the class CourseOverviewController method removeUserFromCourse.
private void removeUserFromCourse(UserRequest ureq, List<RepositoryEntry> repoEntriesToLeave, List<BusinessGroup> groupsToLeave, List<BusinessGroup> groupsToDelete, boolean doSendMail) {
List<Identity> membersToRemove = Collections.singletonList(editedIdentity);
for (BusinessGroup group : groupsToLeave) {
if (groupsToDelete.contains(group)) {
// really delete the group as it has no more owners/participants
if (doSendMail) {
String businessPath = getWindowControl().getBusinessControl().getAsString();
businessGroupService.deleteBusinessGroupWithMail(group, businessPath, getIdentity(), getLocale());
} else {
businessGroupService.deleteBusinessGroup(group);
}
} else {
// 1) remove as owner
if (businessGroupService.hasRoles(editedIdentity, group, GroupRoles.coach.name())) {
businessGroupService.removeOwners(ureq.getIdentity(), membersToRemove, group);
}
MailPackage mailing = new MailPackage(doSendMail);
// 2) remove as participant
businessGroupService.removeParticipants(getIdentity(), membersToRemove, group, mailing);
MailHelper.printErrorsAndWarnings(mailing.getResult(), getWindowControl(), ureq.getUserSession().getRoles().isOLATAdmin(), getLocale());
}
}
for (RepositoryEntry repoEntry : repoEntriesToLeave) {
if (isRepoMember(repoEntry)) {
MailPackage mailing = new MailPackage(doSendMail);
repositoryManager.removeMembers(getIdentity(), membersToRemove, repoEntry, mailing);
}
}
updateModel();
StringBuilder groupNames = new StringBuilder();
for (BusinessGroup group : groupsToLeave) {
if (groupNames.length() > 0)
groupNames.append(", ");
groupNames.append(group.getName());
}
showInfo("unsubscribe.successful");
}
use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.
the class CollaborationManagerImpl method lookupCalendarAccess.
@Override
public Map<Long, Long> lookupCalendarAccess(List<BusinessGroup> groups) {
if (groups == null || groups.isEmpty()) {
return new HashMap<Long, Long>();
}
StringBuilder query = new StringBuilder();
query.append("select prop from ").append(Property.class.getName()).append(" as prop where ").append(" prop.category='").append(PROP_CAT_BG_COLLABTOOLS).append("'").append(" and prop.resourceTypeName='BusinessGroup'").append(" and prop.resourceTypeId in (:groupKeys)").append(" and prop.name='").append(KEY_CALENDAR_ACCESS).append("'").append(" and prop.identity is null and prop.grp is null");
TypedQuery<Property> dbquery = dbInstance.getCurrentEntityManager().createQuery(query.toString(), Property.class);
Map<Long, Long> groupKeyToAccess = new HashMap<Long, Long>();
int count = 0;
int batch = 200;
do {
int toIndex = Math.min(count + batch, groups.size());
List<BusinessGroup> toLoad = groups.subList(count, toIndex);
List<Long> groupKeys = PersistenceHelper.toKeys(toLoad);
List<Property> props = dbquery.setFirstResult(count).setMaxResults(batch).setParameter("groupKeys", groupKeys).getResultList();
for (Property prop : props) {
groupKeyToAccess.put(prop.getResourceTypeId(), prop.getLongValue());
}
count += batch;
} while (count < groups.size());
return groupKeyToAccess;
}
use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.
the class GTACoachedParticipantListController method collectIdentities.
private void collectIdentities(Consumer<Identity> participantCollector) {
Set<Identity> duplicateKiller = new HashSet<>();
CourseGroupManager cgm = coachCourseEnv.getCourseEnvironment().getCourseGroupManager();
boolean admin = coachCourseEnv.isAdmin();
List<BusinessGroup> coachedGroups = admin ? cgm.getAllBusinessGroups() : coachCourseEnv.getCoachedGroups();
List<Identity> participants = businessGroupService.getMembers(coachedGroups, GroupRoles.participant.name());
for (Identity participant : participants) {
if (!duplicateKiller.contains(participant)) {
participantCollector.accept(participant);
duplicateKiller.add(participant);
}
}
RepositoryEntry re = coachCourseEnv.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
boolean repoTutor = admin || (coachedGroups.isEmpty() && repositoryService.hasRole(getIdentity(), re, GroupRoles.coach.name()));
if (repoTutor) {
List<Identity> courseParticipants = repositoryService.getMembers(re, GroupRoles.participant.name());
for (Identity participant : courseParticipants) {
if (!duplicateKiller.contains(participant)) {
participantCollector.accept(participant);
duplicateKiller.add(participant);
}
}
}
}
use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.
the class RunMainController method loadUserCourseEnvironment.
private UserCourseEnvironmentImpl loadUserCourseEnvironment(UserRequest ureq, RepositoryEntrySecurity reSecurity) {
CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager();
List<BusinessGroup> coachedGroups;
if (reSecurity.isGroupCoach()) {
coachedGroups = cgm.getOwnedBusinessGroups(ureq.getIdentity());
} else {
coachedGroups = Collections.emptyList();
}
List<BusinessGroup> participatedGroups;
if (reSecurity.isGroupParticipant()) {
participatedGroups = cgm.getParticipatingBusinessGroups(ureq.getIdentity());
} else {
participatedGroups = Collections.emptyList();
}
List<BusinessGroup> waitingLists;
if (reSecurity.isGroupWaiting()) {
waitingLists = cgm.getWaitingListGroups(ureq.getIdentity());
} else {
waitingLists = Collections.emptyList();
}
return new UserCourseEnvironmentImpl(ureq.getUserSession().getIdentityEnvironment(), course.getCourseEnvironment(), getWindowControl(), coachedGroups, participatedGroups, waitingLists, reSecurity.isCourseCoach() || reSecurity.isGroupCoach(), reSecurity.isEntryAdmin(), reSecurity.isCourseParticipant() || reSecurity.isGroupParticipant(), reSecurity.isReadOnly());
}
Aggregations