use of org.olat.group.model.StatisticsBusinessGroupRow in project OpenOLAT by OpenOLAT.
the class BusinessGroupDAO method searchBusinessGroupsForRepositoryEntry.
/**
* @param entry
* @return
*/
public List<StatisticsBusinessGroupRow> searchBusinessGroupsForRepositoryEntry(BusinessGroupQueryParams params, IdentityRef identity, RepositoryEntryRef entry) {
// name, externalId, description, resources, tutors, participants, free places, waiting, access
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 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 ");
if (params.getRepositoryEntry() == null) {
// make sur the restricition is applied
params.setRepositoryEntry(entry);
}
filterBusinessGroupToSearch(sb, params, false);
TypedQuery<Object[]> objectsQuery = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class);
filterBusinessGroupToSearchParameters(objectsQuery, params, identity, false);
List<Object[]> objects = objectsQuery.getResultList();
List<StatisticsBusinessGroupRow> groups = new ArrayList<>(objects.size());
Map<Long, BusinessGroupRow> keyToGroup = new HashMap<>();
Map<Long, BusinessGroupRow> resourceKeyToGroup = new HashMap<>();
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);
keyToGroup.put(businessGroup.getKey(), row);
resourceKeyToGroup.put(businessGroup.getResource().getKey(), row);
}
loadOfferAccess(resourceKeyToGroup);
loadRelations(keyToGroup, params, identity);
return groups;
}
use of org.olat.group.model.StatisticsBusinessGroupRow in project OpenOLAT by OpenOLAT.
the class BusinessGroupDAOTest method findBusinessGroups.
@Test
public void findBusinessGroups() {
Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("bg-search");
BusinessGroup group1 = businessGroupDao.createAndPersist(null, "gduo", "gduo-desc", 0, 5, true, false, true, false, false);
BusinessGroup group2 = businessGroupDao.createAndPersist(null, "gdvo", "gdvo-desc", 0, 5, true, false, true, false, false);
dbInstance.commitAndCloseSession();
SearchBusinessGroupParams params = new SearchBusinessGroupParams();
List<BusinessGroup> groups = businessGroupDao.findBusinessGroups(params, null, 0, -1);
Assert.assertNotNull(groups);
Assert.assertTrue(groups.size() >= 2);
Assert.assertTrue(groups.contains(group1));
Assert.assertTrue(groups.contains(group2));
BusinessGroupQueryParams searchParams = new BusinessGroupQueryParams();
List<BusinessGroupRow> groupViews = businessGroupDao.searchBusinessGroupsWithMemberships(searchParams, identity);
Assert.assertNotNull(groupViews);
Assert.assertTrue(groupViews.size() >= 2);
Assert.assertTrue(contains(groupViews, group1));
Assert.assertTrue(contains(groupViews, group2));
List<StatisticsBusinessGroupRow> groupToSelect = businessGroupDao.searchBusinessGroupsForSelection(searchParams, identity);
Assert.assertNotNull(groupToSelect);
Assert.assertTrue(groupToSelect.size() >= 2);
List<OpenBusinessGroupRow> openGroups = businessGroupDao.searchPublishedBusinessGroups(searchParams, identity);
Assert.assertNotNull(openGroups);
}
use of org.olat.group.model.StatisticsBusinessGroupRow in project OpenOLAT by OpenOLAT.
the class AbstractSelectBusinessGroupListController method searchTableItems.
@Override
protected List<BGTableItem> searchTableItems(BusinessGroupQueryParams params) {
List<StatisticsBusinessGroupRow> rows = businessGroupService.findBusinessGroupsForSelection(params, getIdentity());
List<BGTableItem> items = new ArrayList<>(rows.size());
for (StatisticsBusinessGroupRow row : rows) {
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, Boolean.FALSE, Boolean.FALSE);
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 klemens.
the class BusinessGroupDAOTest method findBusinessGroups.
@Test
public void findBusinessGroups() {
Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("bg-search");
BusinessGroup group1 = businessGroupDao.createAndPersist(null, "gduo", "gduo-desc", 0, 5, true, false, true, false, false);
BusinessGroup group2 = businessGroupDao.createAndPersist(null, "gdvo", "gdvo-desc", 0, 5, true, false, true, false, false);
dbInstance.commitAndCloseSession();
SearchBusinessGroupParams params = new SearchBusinessGroupParams();
List<BusinessGroup> groups = businessGroupDao.findBusinessGroups(params, null, 0, -1);
Assert.assertNotNull(groups);
Assert.assertTrue(groups.size() >= 2);
Assert.assertTrue(groups.contains(group1));
Assert.assertTrue(groups.contains(group2));
BusinessGroupQueryParams searchParams = new BusinessGroupQueryParams();
List<BusinessGroupRow> groupViews = businessGroupDao.searchBusinessGroupsWithMemberships(searchParams, identity);
Assert.assertNotNull(groupViews);
Assert.assertTrue(groupViews.size() >= 2);
Assert.assertTrue(contains(groupViews, group1));
Assert.assertTrue(contains(groupViews, group2));
List<StatisticsBusinessGroupRow> groupToSelect = businessGroupDao.searchBusinessGroupsForSelection(searchParams, identity);
Assert.assertNotNull(groupToSelect);
Assert.assertTrue(groupToSelect.size() >= 2);
List<OpenBusinessGroupRow> openGroups = businessGroupDao.searchPublishedBusinessGroups(searchParams, identity);
Assert.assertNotNull(openGroups);
}
use of org.olat.group.model.StatisticsBusinessGroupRow in project openolat by klemens.
the class BusinessGroupDAO method searchBusinessGroupsForSelection.
public List<StatisticsBusinessGroupRow> searchBusinessGroupsForSelection(BusinessGroupQueryParams params, IdentityRef identity) {
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(" (select count(mark.key) from ").append(MarkImpl.class.getName()).append(" as mark ").append(" where mark.creator.key=:identityKey and mark.resId=bgi.key and mark.resName='BusinessGroup'").append(" ) as marks").append(" from businessgrouptosearch as bgi").append(" inner join fetch bgi.resource as bgResource ").append(" inner join bgi.baseGroup as bGroup ");
filterBusinessGroupToSearch(sb, params, false);
TypedQuery<Object[]> objectsQuery = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class);
filterBusinessGroupToSearchParameters(objectsQuery, params, identity, true);
List<Object[]> objects = objectsQuery.getResultList();
List<StatisticsBusinessGroupRow> groups = new ArrayList<>(objects.size());
Map<Long, BusinessGroupRow> keyToGroup = new HashMap<>();
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];
Number marked = (Number) object[5];
StatisticsBusinessGroupRow row = new StatisticsBusinessGroupRow(businessGroup, numOfCoaches, numOfParticipants, numWaiting, numPending);
groups.add(row);
row.setMarked(marked == null ? false : marked.longValue() > 0);
keyToGroup.put(businessGroup.getKey(), row);
}
loadRelations(keyToGroup, params, identity);
return groups;
}
Aggregations