Search in sources :

Example 11 with RepositoryEntryMembership

use of org.olat.repository.model.RepositoryEntryMembership 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;
}
Also used : Locale(java.util.Locale) BusinessGroupMembership(org.olat.group.BusinessGroupMembership) RepositoryEntryMembership(org.olat.repository.model.RepositoryEntryMembership) HashMap(java.util.HashMap) ResourceReservation(org.olat.resource.accesscontrol.ResourceReservation) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) BusinessGroupShort(org.olat.group.BusinessGroupShort) HashSet(java.util.HashSet) BusinessGroup(org.olat.group.BusinessGroup) OLATResource(org.olat.resource.OLATResource) Date(java.util.Date)

Example 12 with RepositoryEntryMembership

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

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

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

the class RepositoryManagerTest method getRepositoryentryMembership.

@Test
public void getRepositoryentryMembership() {
    // create a repository entry with an owner and a participant
    Identity admin = securityManager.findIdentityByName("administrator");
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser("re-m-is-" + UUID.randomUUID().toString());
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("re-m-is-" + UUID.randomUUID().toString());
    Identity id3 = JunitTestHelper.createAndPersistIdentityAsUser("re-m-is-" + UUID.randomUUID().toString());
    Identity id4 = JunitTestHelper.createAndPersistIdentityAsUser("re-m-is-" + UUID.randomUUID().toString());
    Identity id5 = JunitTestHelper.createAndPersistIdentityAsUser("re-m-is-" + UUID.randomUUID().toString());
    Identity id6 = JunitTestHelper.createAndPersistIdentityAsUser("re-m-is-" + UUID.randomUUID().toString());
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
    dbInstance.commitAndCloseSession();
    if (repositoryEntryRelationDao.hasRole(admin, re, GroupRoles.owner.name())) {
        repositoryEntryRelationDao.removeRole(admin, re, GroupRoles.owner.name());
    }
    repositoryEntryRelationDao.addRole(id1, re, GroupRoles.owner.name());
    repositoryEntryRelationDao.addRole(id2, re, GroupRoles.owner.name());
    repositoryEntryRelationDao.addRole(id3, re, GroupRoles.coach.name());
    repositoryEntryRelationDao.addRole(id4, re, GroupRoles.coach.name());
    repositoryEntryRelationDao.addRole(id5, re, GroupRoles.participant.name());
    repositoryEntryRelationDao.addRole(id6, re, GroupRoles.participant.name());
    repositoryEntryRelationDao.addRole(id1, re, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    Set<Long> identityKeys = new HashSet<Long>();
    identityKeys.add(id1.getKey());
    identityKeys.add(id2.getKey());
    identityKeys.add(id3.getKey());
    identityKeys.add(id4.getKey());
    identityKeys.add(id5.getKey());
    identityKeys.add(id6.getKey());
    // check with all identities
    List<RepositoryEntryMembership> memberships = repositoryManager.getRepositoryEntryMembership(re);
    Assert.assertNotNull(memberships);
    Assert.assertEquals(6, memberships.size());
    int countOwner = 0;
    int countTutor = 0;
    int countParticipant = 0;
    for (RepositoryEntryMembership membership : memberships) {
        if (membership.isOwner()) {
            countOwner++;
            Assert.assertEquals(re.getKey(), membership.getRepoKey());
        }
        if (membership.isCoach()) {
            countTutor++;
            Assert.assertEquals(re.getKey(), membership.getRepoKey());
        }
        if (membership.isParticipant()) {
            countParticipant++;
            Assert.assertEquals(re.getKey(), membership.getRepoKey());
        }
        Assert.assertTrue(identityKeys.contains(membership.getIdentityKey()));
    }
    Assert.assertEquals(2, countOwner);
    Assert.assertEquals(2, countTutor);
    Assert.assertEquals(3, countParticipant);
    // check with id1
    List<RepositoryEntryMembership> membership1s = repositoryManager.getRepositoryEntryMembership(re, id1);
    Assert.assertNotNull(membership1s);
    Assert.assertEquals(2, membership1s.size());
    for (RepositoryEntryMembership membership : membership1s) {
        if (membership.isOwner()) {
            Assert.assertEquals(re.getKey(), membership.getRepoKey());
        } else if (membership.isParticipant()) {
            Assert.assertEquals(re.getKey(), membership.getRepoKey());
        } else {
            Assert.assertTrue(false);
        }
        Assert.assertEquals(id1.getKey(), membership.getIdentityKey());
    }
}
Also used : RepositoryEntryMembership(org.olat.repository.model.RepositoryEntryMembership) Identity(org.olat.core.id.Identity) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 14 with RepositoryEntryMembership

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

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

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

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)

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