use of org.olat.group.model.StatisticsBusinessGroupRow in project openolat by klemens.
the class BusinessGroupDAOTest method findBusinessGroupWithAuthorConnection.
@Test
public void findBusinessGroupWithAuthorConnection() {
Identity author = JunitTestHelper.createAndPersistIdentityAsUser("bdao-5-" + UUID.randomUUID().toString());
RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
repositoryEntryRelationDao.addRole(author, re, GroupRoles.owner.name());
BusinessGroup group1 = businessGroupDao.createAndPersist(null, "gdlo", "gdlo-desc", 0, 5, true, false, false, false, false);
BusinessGroup group2 = businessGroupDao.createAndPersist(author, "gdmo", "gdmo-desc", 0, 5, true, false, false, false, false);
BusinessGroup group3 = businessGroupDao.createAndPersist(author, "gdmo", "gdmo-desc", 0, 5, true, false, false, false, false);
businessGroupRelationDao.addRelationToResource(group1, re);
businessGroupRelationDao.addRelationToResource(group3, re);
dbInstance.commitAndCloseSession();
// check
BusinessGroupQueryParams params = new BusinessGroupQueryParams();
params.setAuthorConnection(true);
List<StatisticsBusinessGroupRow> groups = businessGroupDao.searchBusinessGroupsForSelection(params, author);
Assert.assertNotNull(groups);
Assert.assertEquals(2, groups.size());
Set<Long> retrievedGroupkey = new HashSet<Long>();
for (StatisticsBusinessGroupRow group : groups) {
retrievedGroupkey.add(group.getKey());
}
Assert.assertTrue(retrievedGroupkey.contains(group1.getKey()));
Assert.assertTrue(retrievedGroupkey.contains(group3.getKey()));
Assert.assertFalse(retrievedGroupkey.contains(group2.getKey()));
}
use of org.olat.group.model.StatisticsBusinessGroupRow in project OpenOLAT by OpenOLAT.
the class BusinessGroupDAOTest method findBusinessGroupWithAuthorConnection.
@Test
public void findBusinessGroupWithAuthorConnection() {
Identity author = JunitTestHelper.createAndPersistIdentityAsUser("bdao-5-" + UUID.randomUUID().toString());
RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
repositoryEntryRelationDao.addRole(author, re, GroupRoles.owner.name());
BusinessGroup group1 = businessGroupDao.createAndPersist(null, "gdlo", "gdlo-desc", 0, 5, true, false, false, false, false);
BusinessGroup group2 = businessGroupDao.createAndPersist(author, "gdmo", "gdmo-desc", 0, 5, true, false, false, false, false);
BusinessGroup group3 = businessGroupDao.createAndPersist(author, "gdmo", "gdmo-desc", 0, 5, true, false, false, false, false);
businessGroupRelationDao.addRelationToResource(group1, re);
businessGroupRelationDao.addRelationToResource(group3, re);
dbInstance.commitAndCloseSession();
// check
BusinessGroupQueryParams params = new BusinessGroupQueryParams();
params.setAuthorConnection(true);
List<StatisticsBusinessGroupRow> groups = businessGroupDao.searchBusinessGroupsForSelection(params, author);
Assert.assertNotNull(groups);
Assert.assertEquals(2, groups.size());
Set<Long> retrievedGroupkey = new HashSet<Long>();
for (StatisticsBusinessGroupRow group : groups) {
retrievedGroupkey.add(group.getKey());
}
Assert.assertTrue(retrievedGroupkey.contains(group1.getKey()));
Assert.assertTrue(retrievedGroupkey.contains(group3.getKey()));
Assert.assertFalse(retrievedGroupkey.contains(group2.getKey()));
}
use of org.olat.group.model.StatisticsBusinessGroupRow in project OpenOLAT by OpenOLAT.
the class EditMembershipController method loadModel.
private void loadModel(Identity memberToLoad) {
BusinessGroupQueryParams params = new BusinessGroupQueryParams();
if (repoEntry == null) {
params.setBusinessGroupKey(businessGroup.getKey());
} else {
params.setRepositoryEntry(repoEntry);
}
List<StatisticsBusinessGroupRow> groups = businessGroupService.findBusinessGroupsStatistics(params);
if (groups.size() > 1) {
Collections.sort(groups, new BusinessGroupRowComparator(getLocale()));
}
boolean defaultMembership = false;
if (memberToLoad == null) {
if (repoEntry != null && groups.isEmpty()) {
boolean managed = RepositoryEntryManagedFlag.isManaged(repoEntry, RepositoryEntryManagedFlag.membersmanagement) && !overrideManaged;
if (!managed) {
repoRightsEl.select("participant", true);
}
} else if (repoEntry == null && groups.size() == 1) {
boolean managed = BusinessGroupManagedFlag.isManaged(groups.get(0).getManagedFlags(), BusinessGroupManagedFlag.membersmanagement) && !overrideManaged;
if (!managed) {
defaultMembership = true;
}
}
}
List<Long> businessGroupKeys = new ArrayList<>(groups.size());
groups.forEach(group -> businessGroupKeys.add(group.getKey()));
groupMemberships = memberToLoad == null ? Collections.<BusinessGroupMembership>emptyList() : businessGroupService.getBusinessGroupMembership(businessGroupKeys, memberToLoad);
List<MemberOption> options = new ArrayList<MemberOption>();
for (StatisticsBusinessGroupRow group : groups) {
boolean managed = BusinessGroupManagedFlag.isManaged(group.getManagedFlags(), BusinessGroupManagedFlag.membersmanagement) && !overrideManaged;
MemberOption option = new MemberOption(group);
BGPermission bgPermission = PermissionHelper.getPermission(group.getKey(), memberToLoad, groupMemberships);
option.setTutor(createSelection(bgPermission.isTutor(), !managed, GroupRoles.coach.name()));
option.setParticipant(createSelection(bgPermission.isParticipant() || defaultMembership, !managed, GroupRoles.participant.name()));
boolean waitingListEnable = !managed && group.isWaitingListEnabled();
option.setWaiting(createSelection(bgPermission.isWaitingList(), waitingListEnable, GroupRoles.waiting.name()));
options.add(option);
}
tableDataModel.setObjects(options);
}
use of org.olat.group.model.StatisticsBusinessGroupRow in project OpenOLAT by OpenOLAT.
the class CourseBusinessGroupListController method searchTableItems.
@Override
protected List<BGTableItem> searchTableItems(BusinessGroupQueryParams params) {
List<StatisticsBusinessGroupRow> rows = businessGroupService.findBusinessGroupsFromRepositoryEntry(params, getIdentity(), getResource());
List<BGTableItem> items = new ArrayList<>(rows.size());
for (StatisticsBusinessGroupRow 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);
item.setNumOfOwners(row.getNumOfCoaches());
item.setNumOfParticipants(row.getNumOfParticipants());
item.setNumWaiting(row.getNumWaiting());
item.setNumOfPendings(row.getNumPending());
items.add(item);
}
return items;
}
use of org.olat.group.model.StatisticsBusinessGroupRow in project OpenOLAT by OpenOLAT.
the class BusinessGroupDAO method searchBusinessGroupsStatistics.
public List<StatisticsBusinessGroupRow> searchBusinessGroupsStatistics(BusinessGroupQueryParams params) {
StringBuilder sb = new StringBuilder();
sb.append("select bgi, ").append(" (select count(nCoaches.key) from bgroupmember as nCoaches ").append(" where nCoaches.group.key=bgi.baseGroup.key and nCoaches.role='").append(GroupRoles.coach.name()).append("'").append(" ) as numOfCoaches,").append(" (select count(nParticipants.key) from bgroupmember as nParticipants ").append(" where nParticipants.group.key=bgi.baseGroup.key and nParticipants.role='").append(GroupRoles.participant.name()).append("'").append(" ) as numOfParticipants,").append(" (select count(nWaiting.key) from bgroupmember as nWaiting ").append(" where bgi.waitingListEnabled=true and nWaiting.group.key=bgi.baseGroup.key and nWaiting.role='").append(GroupRoles.waiting.name()).append("'").append(" ) as numWaiting,").append(" (select count(reservation.key) from resourcereservation as reservation ").append(" where reservation.resource.key=bgi.resource.key").append(" ) as numOfReservations").append(" from businessgrouptosearch as bgi").append(" inner join fetch bgi.resource as bgResource ").append(" inner join bgi.baseGroup as bGroup ");
filterBusinessGroupToSearch(sb, params, false);
sb.append(" order by bgi.name");
TypedQuery<Object[]> objectsQuery = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class);
filterBusinessGroupToSearchParameters(objectsQuery, params, null, false);
List<Object[]> objects = objectsQuery.getResultList();
List<StatisticsBusinessGroupRow> groups = new ArrayList<>(objects.size());
for (Object[] object : objects) {
BusinessGroupToSearch businessGroup = (BusinessGroupToSearch) object[0];
Number numOfCoaches = (Number) object[1];
Number numOfParticipants = (Number) object[2];
Number numWaiting = (Number) object[3];
Number numPending = (Number) object[4];
StatisticsBusinessGroupRow row = new StatisticsBusinessGroupRow(businessGroup, numOfCoaches, numOfParticipants, numWaiting, numPending);
groups.add(row);
}
return groups;
}
Aggregations