Search in sources :

Example 6 with BusinessGroupMembership

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

the class BGRoleCellRenderer method render.

private void render(StringOutput sb, Object val) {
    if (val instanceof BusinessGroupMembership) {
        BusinessGroupMembership membership = (BusinessGroupMembership) val;
        boolean and = false;
        if (membership.isOwner()) {
            and = and(sb, and);
            sb.append(trans.translate("owned.groups"));
        }
        if (membership.isParticipant()) {
            and = and(sb, and);
            sb.append(trans.translate("search.attendee"));
        }
        if (membership.isWaiting()) {
            and = and(sb, and);
            sb.append(trans.translate("search.waiting"));
        }
    } else if (val instanceof BGMembership) {
        BGMembership membership = (BGMembership) val;
        switch(membership) {
            case owner:
                sb.append(trans.translate("owned.groups"));
                break;
            case participant:
                sb.append(trans.translate("search.attendee"));
                break;
            case waiting:
                sb.append(trans.translate("search.waiting"));
                break;
        }
    }
}
Also used : BusinessGroupMembership(org.olat.group.BusinessGroupMembership) BGMembership(org.olat.group.model.BGMembership)

Example 7 with BusinessGroupMembership

use of org.olat.group.BusinessGroupMembership 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 8 with BusinessGroupMembership

use of org.olat.group.BusinessGroupMembership in project openolat by klemens.

the class BusinessGroupDAOTest method getBusinessGroupsMembership.

@Test
public void getBusinessGroupsMembership() {
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser("is-in-grp-rev-1" + UUID.randomUUID().toString());
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("is-in-grp-rev-2" + UUID.randomUUID().toString());
    BusinessGroup group1 = businessGroupDao.createAndPersist(id1, "is-in-grp-rev-1", "is-in-grp-rev-1-desc", 0, 5, true, false, true, false, false);
    BusinessGroup group2 = businessGroupDao.createAndPersist(id2, "is-in-grp-rev-2", "is-in-grp-rev-2-desc", 0, 5, true, false, true, false, false);
    BusinessGroup group3 = businessGroupDao.createAndPersist(null, "is-in-grp-rev-3", "is-in-grp-rev-3-desc", 0, 5, true, false, true, false, false);
    dbInstance.commitAndCloseSession();
    businessGroupRelationDao.addRole(id1, group2, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(id1, group3, GroupRoles.waiting.name());
    businessGroupRelationDao.addRole(id2, group2, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(id2, group3, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    List<BusinessGroup> groups = new ArrayList<BusinessGroup>();
    groups.add(group1);
    groups.add(group2);
    groups.add(group3);
    List<Long> groupKeys = new ArrayList<Long>();
    groupKeys.add(group1.getKey());
    groupKeys.add(group2.getKey());
    groupKeys.add(group3.getKey());
    // check owner + attendee
    int countMembership1 = businessGroupDao.countMembershipInfoInBusinessGroups(id1, groupKeys);
    int countMembership2 = businessGroupDao.countMembershipInfoInBusinessGroups(id2, groupKeys);
    Assert.assertEquals(3, countMembership1);
    Assert.assertEquals(3, countMembership2);
    List<BusinessGroupMembership> memberships = businessGroupDao.getBusinessGroupsMembership(groups);
    Assert.assertNotNull(memberships);
    // 5: id1 3 membership in group1, group2, group3 and id2 2 memberships in group2 and group3
    Assert.assertEquals(5, memberships.size());
    int foundOwn = 0;
    int foundPart = 0;
    int foundWait = 0;
    for (BusinessGroupMembership membership : memberships) {
        Assert.assertNotNull(membership.getIdentityKey());
        Assert.assertNotNull(membership.getCreationDate());
        Assert.assertNotNull(membership.getLastModified());
        Assert.assertNotNull(membership.getGroupKey());
        Assert.assertTrue(groupKeys.contains(membership.getGroupKey()));
        if (membership.isOwner()) {
            foundOwn++;
        }
        if (membership.isParticipant()) {
            foundPart++;
        }
        if (membership.isWaiting()) {
            foundWait++;
        }
    }
    Assert.assertEquals("Owners", 2, foundOwn);
    Assert.assertEquals("Participants", 3, foundPart);
    Assert.assertEquals("Waiting", 1, foundWait);
}
Also used : BusinessGroupMembership(org.olat.group.BusinessGroupMembership) BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 9 with BusinessGroupMembership

use of org.olat.group.BusinessGroupMembership in project openolat by klemens.

the class BGRoleCellRenderer method render.

private void render(StringOutput sb, Object val) {
    if (val instanceof BusinessGroupMembership) {
        BusinessGroupMembership membership = (BusinessGroupMembership) val;
        boolean and = false;
        if (membership.isOwner()) {
            and = and(sb, and);
            sb.append(trans.translate("owned.groups"));
        }
        if (membership.isParticipant()) {
            and = and(sb, and);
            sb.append(trans.translate("search.attendee"));
        }
        if (membership.isWaiting()) {
            and = and(sb, and);
            sb.append(trans.translate("search.waiting"));
        }
    } else if (val instanceof BGMembership) {
        BGMembership membership = (BGMembership) val;
        switch(membership) {
            case owner:
                sb.append(trans.translate("owned.groups"));
                break;
            case participant:
                sb.append(trans.translate("search.attendee"));
                break;
            case waiting:
                sb.append(trans.translate("search.waiting"));
                break;
        }
    }
}
Also used : BusinessGroupMembership(org.olat.group.BusinessGroupMembership) BGMembership(org.olat.group.model.BGMembership)

Example 10 with BusinessGroupMembership

use of org.olat.group.BusinessGroupMembership 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)

Aggregations

BusinessGroupMembership (org.olat.group.BusinessGroupMembership)34 ArrayList (java.util.ArrayList)26 HashMap (java.util.HashMap)12 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)10 Identity (org.olat.core.id.Identity)10 BusinessGroup (org.olat.group.BusinessGroup)10 RepositoryEntryMembership (org.olat.repository.model.RepositoryEntryMembership)8 BusinessGroupRow (org.olat.group.model.BusinessGroupRow)6 RepositoryEntry (org.olat.repository.RepositoryEntry)6 HashSet (java.util.HashSet)4 List (java.util.List)4 BusinessGroupShort (org.olat.group.BusinessGroupShort)4 StatisticsBusinessGroupRow (org.olat.group.model.StatisticsBusinessGroupRow)4 OLATResource (org.olat.resource.OLATResource)4 Date (java.util.Date)2 Locale (java.util.Locale)2 Test (org.junit.Test)2 Component (org.olat.core.gui.components.Component)2 TableEvent (org.olat.core.gui.components.table.TableEvent)2 GenericTreeModel (org.olat.core.gui.components.tree.GenericTreeModel)2