Search in sources :

Example 11 with BusinessGroupShort

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

the class GroupMemberViewComparator method compare.

@Override
public int compare(MemberView m1, MemberView m2) {
    List<BusinessGroupShort> g1 = m1.getGroups();
    List<BusinessGroupShort> g2 = m2.getGroups();
    if (g1 == null || g1.isEmpty()) {
        if (g2 == null || g2.isEmpty())
            return 0;
        return -1;
    }
    if (g2 == null || g2.isEmpty())
        return 1;
    int maxLevel = Math.max(g1.size(), g2.size());
    int compare = 0;
    for (int i = 0; i < maxLevel && compare == 0; i++) {
        BusinessGroupShort gs1 = i < g1.size() ? g1.get(i) : null;
        BusinessGroupShort gs2 = i < g2.size() ? g2.get(i) : null;
        compare = compareLevel(gs1, gs2);
    }
    return compare;
}
Also used : BusinessGroupShort(org.olat.group.BusinessGroupShort)

Example 12 with BusinessGroupShort

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

the class BusinessGroupDAOTest method loadShortBusinessGroupsByKeys.

@Test
public void loadShortBusinessGroupsByKeys() {
    BusinessGroup group1 = businessGroupDao.createAndPersist(null, "shorty-1", "shorty-1-desc", 0, 10, true, true, false, false, false);
    BusinessGroup group2 = businessGroupDao.createAndPersist(null, "shorty-2", "shorty-2-desc", 0, 10, true, true, false, false, false);
    dbInstance.commitAndCloseSession();
    // check if the method is robust against empty list fo keys
    List<BusinessGroupShort> groups1 = businessGroupDao.loadShort(Collections.<Long>emptyList());
    Assert.assertNotNull(groups1);
    Assert.assertEquals(0, groups1.size());
    // check load 1 group
    List<BusinessGroupShort> groups2 = businessGroupDao.loadShort(Collections.singletonList(group1.getKey()));
    Assert.assertNotNull(groups2);
    Assert.assertEquals(1, groups2.size());
    Assert.assertEquals(group1.getKey(), groups2.get(0).getKey());
    Assert.assertEquals(group1.getName(), groups2.get(0).getName());
    // check load 2 groups
    List<Long> groupKeys = new ArrayList<Long>(2);
    groupKeys.add(group1.getKey());
    groupKeys.add(group2.getKey());
    List<BusinessGroupShort> groups3 = businessGroupDao.loadShort(groupKeys);
    Assert.assertNotNull(groups3);
    Assert.assertEquals(2, groups3.size());
    List<Long> groupShortKeys3 = new ArrayList<Long>(3);
    for (BusinessGroupShort group : groups3) {
        groupShortKeys3.add(group.getKey());
    }
    Assert.assertTrue(groupShortKeys3.contains(group1.getKey()));
    Assert.assertTrue(groupShortKeys3.contains(group2.getKey()));
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) BusinessGroupShort(org.olat.group.BusinessGroupShort) Test(org.junit.Test)

Example 13 with BusinessGroupShort

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

the class ENEditGroupAreaFormController method getGroupKeysAndNames.

private KeysAndNames getGroupKeysAndNames(List<Long> keys) {
    StringBuilder sb = new StringBuilder();
    KeysAndNames keysAndNames = new KeysAndNames();
    keysAndNames.getKeys().addAll(keys);
    List<BusinessGroupShort> groups = businessGroupService.loadShortBusinessGroups(keys);
    for (BusinessGroupShort group : groups) {
        if (sb.length() > 0)
            sb.append("&nbsp;&nbsp;");
        sb.append("<i class='o_icon o_icon-fw o_icon_group'>&nbsp;</i> ");
        sb.append(StringHelper.escapeHtml(group.getName()));
        keysAndNames.getNames().add(group.getName());
    }
    keysAndNames.setDecoratedNames(sb.toString());
    return keysAndNames;
}
Also used : BusinessGroupShort(org.olat.group.BusinessGroupShort)

Example 14 with BusinessGroupShort

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

the class BusinessGroupRelationDAO method findShortRepositoryEntries.

public List<RepositoryEntryShort> findShortRepositoryEntries(Collection<BusinessGroupShort> groups, int firstResult, int maxResults) {
    if (groups == null || groups.isEmpty()) {
        return Collections.emptyList();
    }
    StringBuilder sb = new StringBuilder();
    sb.append("select new org.olat.group.model.BGRepositoryEntryShortImpl(v.key, v.displayname) from ").append(RepositoryEntry.class.getName()).append(" as v ").append(" inner join v.olatResource as ores ").append(" inner join v.groups as relGroup").append(" where exists (").append("   select bgi from businessgroup as bgi where bgi.baseGroup=relGroup.group and bgi.key in (:groupKeys)").append(" )");
    TypedQuery<RepositoryEntryShort> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), RepositoryEntryShort.class);
    query.setFirstResult(firstResult);
    if (maxResults > 0) {
        query.setMaxResults(maxResults);
    }
    List<Long> groupKeys = new ArrayList<Long>();
    for (BusinessGroupShort group : groups) {
        groupKeys.add(group.getKey());
    }
    query.setParameter("groupKeys", groupKeys);
    query.setHint("org.hibernate.cacheable", Boolean.TRUE);
    return query.getResultList();
}
Also used : RepositoryEntryShort(org.olat.repository.RepositoryEntryShort) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) BusinessGroupShort(org.olat.group.BusinessGroupShort)

Example 15 with BusinessGroupShort

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

the class AbstractMemberListController method doGraduate.

protected void doGraduate(List<MemberView> members) {
    if (businessGroup != null) {
        List<Long> identityKeys = getMemberKeys(members);
        List<Identity> identitiesToGraduate = securityManager.loadIdentityByKeys(identityKeys);
        businessGroupService.moveIdentityFromWaitingListToParticipant(getIdentity(), identitiesToGraduate, businessGroup, null);
    } else {
        Map<Long, BusinessGroup> groupsMap = new HashMap<>();
        Map<BusinessGroup, List<Identity>> graduatesMap = new HashMap<>();
        for (MemberView member : members) {
            List<BusinessGroupShort> groups = member.getGroups();
            if (groups != null && groups.size() > 0) {
                Identity memberIdentity = securityManager.loadIdentityByKey(member.getIdentityKey());
                for (BusinessGroupShort group : groups) {
                    if (businessGroupService.hasRoles(memberIdentity, group, GroupRoles.waiting.name())) {
                        BusinessGroup fullGroup = groupsMap.get(group.getKey());
                        if (fullGroup == null) {
                            fullGroup = businessGroupService.loadBusinessGroup(group.getKey());
                            groupsMap.put(group.getKey(), fullGroup);
                        }
                        List<Identity> identitiesToGraduate = graduatesMap.get(fullGroup);
                        if (identitiesToGraduate == null) {
                            identitiesToGraduate = new ArrayList<>();
                            graduatesMap.put(fullGroup, identitiesToGraduate);
                        }
                        identitiesToGraduate.add(memberIdentity);
                    }
                }
            }
        }
        for (Map.Entry<BusinessGroup, List<Identity>> entry : graduatesMap.entrySet()) {
            BusinessGroup fullGroup = entry.getKey();
            List<Identity> identitiesToGraduate = entry.getValue();
            businessGroupService.moveIdentityFromWaitingListToParticipant(getIdentity(), identitiesToGraduate, fullGroup, null);
        }
    }
    reloadModel();
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) HashMap(java.util.HashMap) ContactList(org.olat.core.util.mail.ContactList) List(java.util.List) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) BusinessGroupShort(org.olat.group.BusinessGroupShort) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

BusinessGroupShort (org.olat.group.BusinessGroupShort)34 ArrayList (java.util.ArrayList)18 BusinessGroup (org.olat.group.BusinessGroup)10 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 List (java.util.List)6 BGArea (org.olat.group.area.BGArea)6 RepositoryEntry (org.olat.repository.RepositoryEntry)6 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)4 FormLinkImpl (org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl)4 Identity (org.olat.core.id.Identity)4 BusinessGroupMembership (org.olat.group.BusinessGroupMembership)4 RepositoryEntryShort (org.olat.repository.RepositoryEntryShort)4 RepositoryEntryMembership (org.olat.repository.model.RepositoryEntryMembership)4 Date (java.util.Date)2 Locale (java.util.Locale)2 Map (java.util.Map)2 Test (org.junit.Test)2 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)2 FlexiTableSearchEvent (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableSearchEvent)2