Search in sources :

Example 11 with BusinessGroupMembership

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

the class GroupOverviewController method updateModel.

/**
 * @param ureq
 * @param control
 * @param identity
 * @return
 */
private void updateModel() {
    SearchBusinessGroupParams params = new SearchBusinessGroupParams();
    params.setIdentity(identity);
    params.setOwner(true);
    params.setAttendee(true);
    params.setWaiting(true);
    List<BusinessGroup> groups = businessGroupService.findBusinessGroups(params, null, 0, -1);
    List<Long> groupKeysWithMembers;
    if (groups.size() > 50) {
        groupKeysWithMembers = null;
    } else {
        groupKeysWithMembers = new ArrayList<Long>(groups.size());
        for (BusinessGroup view : groups) {
            groupKeysWithMembers.add(view.getKey());
        }
    }
    // retrieve all user's membership if there are more than 50 groups
    List<BusinessGroupMembership> groupsAsOwner = businessGroupService.getBusinessGroupMembership(groupKeysWithMembers, identity);
    Map<Long, BusinessGroupMembership> memberships = new HashMap<Long, BusinessGroupMembership>();
    for (BusinessGroupMembership membership : groupsAsOwner) {
        memberships.put(membership.getGroupKey(), membership);
    }
    List<GroupOverviewRow> items = new ArrayList<GroupOverviewRow>();
    for (BusinessGroup group : groups) {
        BusinessGroupMembership membership = memberships.get(group.getKey());
        GroupOverviewRow tableItem = new GroupOverviewRow(group, membership, Boolean.TRUE);
        items.add(tableItem);
    }
    tableDataModel.setEntries(items);
    groupListCtr.modelChanged();
}
Also used : BusinessGroupMembership(org.olat.group.BusinessGroupMembership) BusinessGroup(org.olat.group.BusinessGroup) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams)

Example 12 with BusinessGroupMembership

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

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

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

the class OpenBusinessGroupListController method addAccessLink.

protected void addAccessLink(BGTableItem item) {
    String action;
    BusinessGroupMembership membership = item.getMembership();
    if (membership != null && membership.isOwner()) {
        return;
    } else if (membership != null && (membership.isParticipant() || membership.isWaiting())) {
        action = TABLE_ACTION_LEAVE;
    } else if (item.isFull() && !item.isWaitingListEnabled()) {
        action = null;
    } else {
        action = TABLE_ACTION_ACCESS;
    }
    String i18nKey;
    if (membership != null && membership.isParticipant()) {
        i18nKey = "table.header.leave";
    } else if (membership != null && membership.isWaiting()) {
        i18nKey = "table.header.leave.waiting";
    } else if (item.isFull()) {
        if (item.isWaitingListEnabled()) {
            i18nKey = "table.access.waitingList";
        } else {
            i18nKey = "table.header.group.full";
        }
    } else if (item.isWaitingListEnabled()) {
        if (item.isFull()) {
            i18nKey = "table.access.waitingList";
        } else {
            i18nKey = "table.access";
        }
    } else {
        i18nKey = "table.access";
    }
    FormLink accessLink = uifactory.addFormLink("open_" + item.getBusinessGroupKey(), action, i18nKey, null, null, Link.LINK);
    if (action == null) {
        accessLink.setEnabled(false);
    }
    accessLink.setUserObject(item);
    item.setAccessLink(accessLink);
}
Also used : BusinessGroupMembership(org.olat.group.BusinessGroupMembership) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink)

Example 14 with BusinessGroupMembership

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

the class SearchBusinessGroupListController method searchTableItems.

@Override
protected List<BGTableItem> searchTableItems(BusinessGroupQueryParams params) {
    List<BusinessGroupRow> rows = businessGroupService.findBusinessGroupsWithMemberships(params, getIdentity());
    List<BGTableItem> items = new ArrayList<>(rows.size());
    for (BusinessGroupRow row : rows) {
        BusinessGroupMembership membership = row.getMember();
        Boolean allowLeave = membership != null;
        Boolean allowDelete = isAdmin() ? Boolean.TRUE : (membership == null ? null : new Boolean(membership.isOwner()));
        FormLink markLink = uifactory.addFormLink("mark_" + row.getKey(), "mark", "", null, null, Link.NONTRANSLATED);
        markLink.setIconLeftCSS(row.isMarked() ? Mark.MARK_CSS_LARGE : Mark.MARK_ADD_CSS_LARGE);
        BGTableItem item = new BGTableItem(row, markLink, allowLeave, allowDelete);
        items.add(item);
    }
    return items;
}
Also used : BusinessGroupMembership(org.olat.group.BusinessGroupMembership) ArrayList(java.util.ArrayList) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) BusinessGroupRow(org.olat.group.model.BusinessGroupRow)

Example 15 with BusinessGroupMembership

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

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