Search in sources :

Example 16 with BusinessGroup

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);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) BusinessGroupShort(org.olat.group.BusinessGroupShort)

Example 17 with BusinessGroup

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");
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity)

Example 18 with BusinessGroup

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;
}
Also used : HashMap(java.util.HashMap) BusinessGroup(org.olat.group.BusinessGroup) Property(org.olat.properties.Property)

Example 19 with BusinessGroup

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);
            }
        }
    }
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) HashSet(java.util.HashSet)

Example 20 with BusinessGroup

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());
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) BusinessGroup(org.olat.group.BusinessGroup)

Aggregations

BusinessGroup (org.olat.group.BusinessGroup)1034 Test (org.junit.Test)536 Identity (org.olat.core.id.Identity)536 RepositoryEntry (org.olat.repository.RepositoryEntry)324 ArrayList (java.util.ArrayList)224 BusinessGroupService (org.olat.group.BusinessGroupService)116 SearchBusinessGroupParams (org.olat.group.model.SearchBusinessGroupParams)84 BGArea (org.olat.group.area.BGArea)70 CollaborationTools (org.olat.collaboration.CollaborationTools)58 OLATResource (org.olat.resource.OLATResource)56 Date (java.util.Date)54 HashSet (java.util.HashSet)50 File (java.io.File)46 Path (javax.ws.rs.Path)42 Group (org.olat.basesecurity.Group)42 HashMap (java.util.HashMap)38 Roles (org.olat.core.id.Roles)38 BusinessGroupQueryParams (org.olat.group.model.BusinessGroupQueryParams)38 BusinessGroupRow (org.olat.group.model.BusinessGroupRow)38 StatisticsBusinessGroupRow (org.olat.group.model.StatisticsBusinessGroupRow)38