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;
}
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()));
}
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(" ");
sb.append("<i class='o_icon o_icon-fw o_icon_group'> </i> ");
sb.append(StringHelper.escapeHtml(group.getName()));
keysAndNames.getNames().add(group.getName());
}
keysAndNames.setDecoratedNames(sb.toString());
return keysAndNames;
}
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();
}
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();
}
Aggregations