Search in sources :

Example 1 with RepositoryEntryMembership

use of org.olat.repository.model.RepositoryEntryMembership 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 2 with RepositoryEntryMembership

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

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

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

the class RepositoryManager method getRepositoryEntryMembership.

public List<RepositoryEntryMembership> getRepositoryEntryMembership(RepositoryEntryRef re) {
    if (re == null)
        return Collections.emptyList();
    StringBuilder sb = new StringBuilder();
    sb.append("select membership.identity.key, membership.creationDate, membership.lastModified, membership.role ").append(" from ").append(RepositoryEntry.class.getName()).append(" as v ").append(" inner join v.groups as relGroup on relGroup.defaultGroup=true").append(" inner join relGroup.group as baseGroup").append(" inner join baseGroup.members as membership").append(" where v.key=:repoKey");
    List<Object[]> members = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("repoKey", re.getKey()).getResultList();
    Map<Long, RepositoryEntryMembership> memberships = new HashMap<Long, RepositoryEntryMembership>();
    for (Object[] membership : members) {
        Long identityKey = (Long) membership[0];
        Date lastModified = (Date) membership[1];
        Date creationDate = (Date) membership[2];
        Object role = membership[3];
        RepositoryEntryMembership mb = memberships.get(identityKey);
        if (mb == null) {
            mb = new RepositoryEntryMembership();
            mb.setIdentityKey(identityKey);
            mb.setRepoKey(re.getKey());
            memberships.put(identityKey, mb);
        }
        mb.setCreationDate(creationDate);
        mb.setLastModified(lastModified);
        if (GroupRoles.participant.name().equals(role)) {
            mb.setParticipant(true);
        } else if (GroupRoles.coach.name().equals(role)) {
            mb.setCoach(true);
        } else if (GroupRoles.owner.name().equals(role)) {
            mb.setOwner(true);
        }
    }
    return new ArrayList<RepositoryEntryMembership>(memberships.values());
}
Also used : RepositoryEntryMembership(org.olat.repository.model.RepositoryEntryMembership) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 4 with RepositoryEntryMembership

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

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)

Example 5 with RepositoryEntryMembership

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

the class RepositoryManager method getRepositoryEntryMembership.

public List<RepositoryEntryMembership> getRepositoryEntryMembership(RepositoryEntryRef re) {
    if (re == null)
        return Collections.emptyList();
    StringBuilder sb = new StringBuilder();
    sb.append("select membership.identity.key, membership.creationDate, membership.lastModified, membership.role ").append(" from ").append(RepositoryEntry.class.getName()).append(" as v ").append(" inner join v.groups as relGroup on relGroup.defaultGroup=true").append(" inner join relGroup.group as baseGroup").append(" inner join baseGroup.members as membership").append(" where v.key=:repoKey");
    List<Object[]> members = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("repoKey", re.getKey()).getResultList();
    Map<Long, RepositoryEntryMembership> memberships = new HashMap<Long, RepositoryEntryMembership>();
    for (Object[] membership : members) {
        Long identityKey = (Long) membership[0];
        Date lastModified = (Date) membership[1];
        Date creationDate = (Date) membership[2];
        Object role = membership[3];
        RepositoryEntryMembership mb = memberships.get(identityKey);
        if (mb == null) {
            mb = new RepositoryEntryMembership();
            mb.setIdentityKey(identityKey);
            mb.setRepoKey(re.getKey());
            memberships.put(identityKey, mb);
        }
        mb.setCreationDate(creationDate);
        mb.setLastModified(lastModified);
        if (GroupRoles.participant.name().equals(role)) {
            mb.setParticipant(true);
        } else if (GroupRoles.coach.name().equals(role)) {
            mb.setCoach(true);
        } else if (GroupRoles.owner.name().equals(role)) {
            mb.setOwner(true);
        }
    }
    return new ArrayList<RepositoryEntryMembership>(memberships.values());
}
Also used : RepositoryEntryMembership(org.olat.repository.model.RepositoryEntryMembership) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Date(java.util.Date)

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