Search in sources :

Example 6 with RepositoryEntryMembership

use of org.olat.repository.model.RepositoryEntryMembership in project openolat by klemens.

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 7 with RepositoryEntryMembership

use of org.olat.repository.model.RepositoryEntryMembership in project OpenOLAT by OpenOLAT.

the class RepositoryManager method getRepositoryEntryMembership.

/**
 * Need a repository entry or identites to return a list.
 * @param re
 * @param identity
 * @return
 */
public List<RepositoryEntryMembership> getRepositoryEntryMembership(RepositoryEntryRef re, Identity... identity) {
    if (re == null && (identity == null || identity.length == 0))
        return Collections.emptyList();
    StringBuilder sb = new StringBuilder(400);
    sb.append("select distinct membership from repoentrymembership as membership ");
    boolean and = false;
    if (re != null) {
        and = and(sb, and);
        sb.append("membership.repoKey=:repoKey");
    }
    if (identity != null && identity.length > 0) {
        and = and(sb, and);
        sb.append("membership.identityKey=:identityKeys");
    }
    TypedQuery<RepositoryEntryMembership> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), RepositoryEntryMembership.class);
    if (re != null) {
        query.setParameter("repoKey", re.getKey());
    }
    if (identity != null && identity.length > 0) {
        List<Long> ids = new ArrayList<Long>(identity.length);
        for (Identity id : identity) {
            ids.add(id.getKey());
        }
        query.setParameter("identityKeys", ids);
    }
    List<RepositoryEntryMembership> entries = query.getResultList();
    return entries;
}
Also used : RepositoryEntryMembership(org.olat.repository.model.RepositoryEntryMembership) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity)

Example 8 with RepositoryEntryMembership

use of org.olat.repository.model.RepositoryEntryMembership in project OpenOLAT by OpenOLAT.

the class MembersExportManager method getXlsMediaResource.

public MediaResource getXlsMediaResource(boolean showOwners, boolean showCoaches, boolean showParticipants, boolean showWaiting, List<Identity> owners, List<Identity> coaches, List<Identity> participants, List<Identity> waiting, Translator translator, List<UserPropertyHandler> userPropertyHandlers, RepositoryEntry repoEntry, BusinessGroup businessGroup) {
    // TODO
    Map<Long, BusinessGroupMembership> groupmemberships;
    Map<Long, RepositoryEntryMembership> repomemberships;
    if (repoEntry == null) {
        List<BusinessGroup> groups = new ArrayList<>();
        groups.add(businessGroup);
        groupmemberships = getGroupMembershipMap(groups);
        repomemberships = new HashMap<>();
    } else {
        repomemberships = getRepoMembershipMap(repoEntry);
        List<BusinessGroup> groups = businessGroupService.findBusinessGroups(null, repoEntry, 0, -1);
        groupmemberships = getGroupMembershipMap(groups);
    }
    List<List<Identity>> roleMembers = new ArrayList<>();
    if (showOwners) {
        roleMembers.add(owners);
    }
    if (showCoaches) {
        roleMembers.add(coaches);
    }
    if (showParticipants) {
        roleMembers.add(participants);
    }
    if (showWaiting) {
        roleMembers.add(waiting);
    }
    Translator repoTranslator = Util.createPackageTranslator(Member.class, translator.getLocale());
    Translator groupTranslator = Util.createPackageTranslator(GroupMembersRunController.class, translator.getLocale());
    Map<Identity, StringBuilder> membersMap = new HashMap<>();
    List<Identity> rows = new ArrayList<>();
    for (List<Identity> membersList : roleMembers) {
        for (Identity member : membersList) {
            Long memberKey = member.getKey();
            if (repomemberships != null && !repomemberships.isEmpty() && repomemberships.containsKey(memberKey)) {
                RepositoryEntryMembership repomembership = repomemberships.get(memberKey);
                if (repomembership.isOwner()) {
                    putRoleToMember(rows, membersMap, member, "owners", repoTranslator);
                }
                if (repomembership.isCoach()) {
                    putRoleToMember(rows, membersMap, member, "coaches", repoTranslator);
                }
                if (repomembership.isParticipant()) {
                    putRoleToMember(rows, membersMap, member, "participants", repoTranslator);
                }
            }
            if (groupmemberships != null && !groupmemberships.isEmpty() && groupmemberships.containsKey(memberKey)) {
                BusinessGroupMembership groupmembership = groupmemberships.get(memberKey);
                if (groupmembership.isOwner()) {
                    putRoleToMember(rows, membersMap, member, "coaches", groupTranslator);
                }
                if (groupmembership.isParticipant()) {
                    putRoleToMember(rows, membersMap, member, "participants", groupTranslator);
                }
                if (groupmembership.isWaiting()) {
                    putRoleToMember(rows, membersMap, member, "waiting", groupTranslator);
                }
            }
        }
    }
    Translator handlerTranslator = userManager.getPropertyHandlerTranslator(translator);
    XlsMembersExport exporter = new XlsMembersExport();
    MediaResource resource = exporter.export(rows, membersMap, handlerTranslator, userPropertyHandlers);
    return resource;
}
Also used : BusinessGroupMembership(org.olat.group.BusinessGroupMembership) RepositoryEntryMembership(org.olat.repository.model.RepositoryEntryMembership) BusinessGroup(org.olat.group.BusinessGroup) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Translator(org.olat.core.gui.translator.Translator) ArrayList(java.util.ArrayList) List(java.util.List) MediaResource(org.olat.core.gui.media.MediaResource) Identity(org.olat.core.id.Identity)

Example 9 with RepositoryEntryMembership

use of org.olat.repository.model.RepositoryEntryMembership in project OpenOLAT by OpenOLAT.

the class MembersExportManager method getRepoMembershipMap.

public Map<Long, RepositoryEntryMembership> getRepoMembershipMap(RepositoryEntry repoEntry) {
    List<RepositoryEntryMembership> repoMemberships = repositoryManager.getRepositoryEntryMembership(repoEntry);
    Map<Long, RepositoryEntryMembership> map = new HashMap<>();
    for (RepositoryEntryMembership membership : repoMemberships) {
        map.put(membership.getIdentityKey(), membership);
    }
    return map;
}
Also used : RepositoryEntryMembership(org.olat.repository.model.RepositoryEntryMembership) HashMap(java.util.HashMap)

Example 10 with RepositoryEntryMembership

use of org.olat.repository.model.RepositoryEntryMembership 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;
}
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) Checkbox(org.olat.course.nodes.cl.model.Checkbox) Identity(org.olat.core.id.Identity) HashSet(java.util.HashSet) BusinessGroup(org.olat.group.BusinessGroup) AssessmentData(org.olat.course.nodes.cl.model.AssessmentData) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl)

Aggregations

RepositoryEntryMembership (org.olat.repository.model.RepositoryEntryMembership)16 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)12 Identity (org.olat.core.id.Identity)10 BusinessGroupMembership (org.olat.group.BusinessGroupMembership)8 HashSet (java.util.HashSet)6 BusinessGroup (org.olat.group.BusinessGroup)6 Date (java.util.Date)4 List (java.util.List)4 BusinessGroupShort (org.olat.group.BusinessGroupShort)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 Locale (java.util.Locale)2 Test (org.junit.Test)2 MediaResource (org.olat.core.gui.media.MediaResource)2 Translator (org.olat.core.gui.translator.Translator)2 AssessmentData (org.olat.course.nodes.cl.model.AssessmentData)2 Checkbox (org.olat.course.nodes.cl.model.Checkbox)2 UserCourseEnvironmentImpl (org.olat.course.run.userview.UserCourseEnvironmentImpl)2 BGRepositoryEntryRelation (org.olat.group.model.BGRepositoryEntryRelation)2 OLATResource (org.olat.resource.OLATResource)2