Search in sources :

Example 1 with BusinessGroupShort

use of org.olat.group.BusinessGroupShort in project OpenOLAT by OpenOLAT.

the class MailBoxExtension method getName.

@Override
public String getName(String businessPath, Locale locale) {
    if (!StringHelper.containsNonWhitespace(businessPath))
        return null;
    try {
        List<ContextEntry> entries = BusinessControlFactory.getInstance().createCEListFromString(businessPath);
        Collections.reverse(entries);
        for (ContextEntry entry : entries) {
            String resourceTypeName = entry.getOLATResourceable().getResourceableTypeName();
            Long resourceId = entry.getOLATResourceable().getResourceableId();
            if ("BusinessGroup".equals(resourceTypeName)) {
                List<Long> ids = Collections.singletonList(resourceId);
                List<BusinessGroupShort> groups = businessGroupService.loadShortBusinessGroups(ids);
                if (groups == null || groups.isEmpty()) {
                    return null;
                }
                return groups.get(0).getName();
            } else if ("RepositoryEntry".equals(resourceTypeName)) {
                return repositoryManager.lookupDisplayName(resourceId);
            }
        }
    } catch (Exception e) {
        log.error("", e);
    }
    return null;
}
Also used : BusinessGroupShort(org.olat.group.BusinessGroupShort) ContextEntry(org.olat.core.id.context.ContextEntry)

Example 2 with BusinessGroupShort

use of org.olat.group.BusinessGroupShort in project OpenOLAT by OpenOLAT.

the class BusinessGroupNameColumnDescriptor method compareTo.

@Override
public int compareTo(int rowa, int rowb) {
    Object a = table.getTableDataModel().getValueAt(rowa, dataColumn);
    Object b = table.getTableDataModel().getValueAt(rowb, dataColumn);
    if (a instanceof BusinessGroupShort && b instanceof BusinessGroupShort) {
        BusinessGroupShort g1 = (BusinessGroupShort) a;
        BusinessGroupShort g2 = (BusinessGroupShort) b;
        return super.compareString(g1.getName(), g2.getName());
    }
    return super.compareTo(rowa, rowb);
}
Also used : BusinessGroupShort(org.olat.group.BusinessGroupShort)

Example 3 with BusinessGroupShort

use of org.olat.group.BusinessGroupShort 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 4 with BusinessGroupShort

use of org.olat.group.BusinessGroupShort in project OpenOLAT by OpenOLAT.

the class CourseOverviewController method updateModel.

private void updateModel() {
    // course membership
    List<RepositoryEntryMembership> memberships = repositoryManager.getRepositoryEntryMembership(null, editedIdentity);
    // group membership
    List<BusinessGroupMembership> groupMemberships = businessGroupService.getBusinessGroupMembership(Collections.<Long>emptyList(), editedIdentity);
    Collection<Long> groupKeys = new ArrayList<Long>(groupMemberships.size());
    for (BusinessGroupMembership membership : groupMemberships) {
        groupKeys.add(membership.getGroupKey());
    }
    // relation to course
    List<BGRepositoryEntryRelation> relations = businessGroupService.findRelationToRepositoryEntries(groupKeys, 0, -1);
    Map<Long, List<Long>> groupKeyToRepoKeyMap = new HashMap<>();
    for (BGRepositoryEntryRelation relation : relations) {
        if (groupKeyToRepoKeyMap.containsKey(relation.getGroupKey())) {
            groupKeyToRepoKeyMap.get(relation.getGroupKey()).add(relation.getRepositoryEntryKey());
        } else {
            List<Long> repoEntryKeys = new ArrayList<>(2);
            repoEntryKeys.add(relation.getRepositoryEntryKey());
            groupKeyToRepoKeyMap.put(relation.getGroupKey(), repoEntryKeys);
        }
    }
    Map<Long, CourseMemberView> repoKeyToViewMap = new HashMap<Long, CourseMemberView>();
    for (RepositoryEntryMembership membership : memberships) {
        Long repoKey = membership.getRepoKey();
        CourseMemberView memberView;
        if (repoKeyToViewMap.containsKey(repoKey)) {
            memberView = repoKeyToViewMap.get(repoKey);
        } else {
            memberView = new CourseMemberView(repoKey);
            repoKeyToViewMap.put(repoKey, memberView);
        }
        memberView.setFirstTime(membership.getCreationDate());
        if (memberView.getLastTime() == null || (memberView.getLastTime() != null && membership.getLastModified() != null && membership.getLastModified().after(memberView.getLastTime()))) {
            memberView.setLastTime(membership.getLastModified());
        }
        // add the roles
        if (!memberView.getMembership().isRepoOwner()) {
            memberView.getMembership().setRepoOwner(membership.isOwner());
        }
        if (!memberView.getMembership().isRepoTutor()) {
            memberView.getMembership().setRepoTutor(membership.isCoach());
        }
        if (!memberView.getMembership().isRepoParticipant()) {
            memberView.getMembership().setRepoParticipant(membership.isParticipant());
        }
    }
    List<BusinessGroupShort> groups = businessGroupService.loadShortBusinessGroups(groupKeys);
    Map<Long, BusinessGroupShort> groupKeyToGroupMap = new HashMap<Long, BusinessGroupShort>();
    for (BusinessGroupShort group : groups) {
        groupKeyToGroupMap.put(group.getKey(), group);
    }
    for (BusinessGroupMembership membership : groupMemberships) {
        List<Long> repoKeys;
        if (groupKeyToRepoKeyMap.containsKey(membership.getGroupKey())) {
            repoKeys = groupKeyToRepoKeyMap.get(membership.getGroupKey());
        } else {
            continue;
        }
        BusinessGroupShort group = groupKeyToGroupMap.get(membership.getGroupKey());
        if (group == null) {
            continue;
        }
        for (Long repoKey : repoKeys) {
            CourseMemberView memberView;
            if (repoKeyToViewMap.containsKey(repoKey)) {
                memberView = repoKeyToViewMap.get(repoKey);
            } else {
                memberView = new CourseMemberView(repoKey);
                repoKeyToViewMap.put(repoKey, memberView);
            }
            memberView.addGroup(group);
            memberView.setFirstTime(membership.getCreationDate());
            if (memberView.getLastTime() == null || (memberView.getLastTime() != null && membership.getLastModified() != null && membership.getLastModified().after(memberView.getLastTime()))) {
                memberView.setLastTime(membership.getLastModified());
            }
            switch(membership.getMembership()) {
                case owner:
                    memberView.getMembership().setGroupTutor(true);
                    break;
                case participant:
                    memberView.getMembership().setGroupParticipant(true);
                    break;
                case waiting:
                    memberView.getMembership().setGroupWaiting(true);
                    break;
            }
        }
    }
    List<RepositoryEntry> entries = repositoryManager.lookupRepositoryEntries(repoKeyToViewMap.keySet());
    Map<Long, RepositoryEntry> entryKeyToRepoEntryMap = new HashMap<Long, RepositoryEntry>();
    for (RepositoryEntry entry : entries) {
        entryKeyToRepoEntryMap.put(entry.getKey(), entry);
    }
    for (CourseMemberView memberView : repoKeyToViewMap.values()) {
        RepositoryEntry entry = entryKeyToRepoEntryMap.get(memberView.getRepoKey());
        if (entry != null) {
            memberView.setEntry(entry);
            boolean managedMembersRepo = RepositoryEntryManagedFlag.isManaged(entry, RepositoryEntryManagedFlag.membersmanagement);
            memberView.getMembership().setManagedMembersRepo(managedMembersRepo);
        }
    }
    List<CourseMemberView> views = new ArrayList<CourseMemberView>(repoKeyToViewMap.values());
    tableDataModel.setObjects(views);
    courseListCtr.modelChanged();
}
Also used : BusinessGroupMembership(org.olat.group.BusinessGroupMembership) RepositoryEntryMembership(org.olat.repository.model.RepositoryEntryMembership) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) List(java.util.List) ArrayList(java.util.ArrayList) BGRepositoryEntryRelation(org.olat.group.model.BGRepositoryEntryRelation) BusinessGroupShort(org.olat.group.BusinessGroupShort)

Example 5 with BusinessGroupShort

use of org.olat.group.BusinessGroupShort in project OpenOLAT by OpenOLAT.

the class ConditionConfigEasyController method getGroupNames.

private String getGroupNames(List<Long> keys) {
    StringBuilder sb = new StringBuilder();
    List<BusinessGroupShort> groups = businessGroupService.loadShortBusinessGroups(keys);
    for (BusinessGroupShort group : groups) {
        if (sb.length() > 0)
            sb.append(", ");
        sb.append(StringHelper.escapeHtml(group.getName()));
    }
    return sb.toString();
}
Also used : BusinessGroupShort(org.olat.group.BusinessGroupShort)

Aggregations

BusinessGroupShort (org.olat.group.BusinessGroupShort)34 ArrayList (java.util.ArrayList)18 BusinessGroup (org.olat.group.BusinessGroup)10 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 List (java.util.List)6 BGArea (org.olat.group.area.BGArea)6 RepositoryEntry (org.olat.repository.RepositoryEntry)6 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)4 FormLinkImpl (org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl)4 Identity (org.olat.core.id.Identity)4 BusinessGroupMembership (org.olat.group.BusinessGroupMembership)4 RepositoryEntryShort (org.olat.repository.RepositoryEntryShort)4 RepositoryEntryMembership (org.olat.repository.model.RepositoryEntryMembership)4 Date (java.util.Date)2 Locale (java.util.Locale)2 Map (java.util.Map)2 Test (org.junit.Test)2 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)2 FlexiTableSearchEvent (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableSearchEvent)2