use of org.olat.group.model.OpenBusinessGroupRow in project OpenOLAT by OpenOLAT.
the class OpenBusinessGroupListController method searchTableItems.
@Override
protected List<BGTableItem> searchTableItems(BusinessGroupQueryParams params) {
List<OpenBusinessGroupRow> rows = businessGroupService.findPublishedBusinessGroups(params, getIdentity());
List<BGTableItem> items = new ArrayList<>(rows.size());
for (OpenBusinessGroupRow row : rows) {
BusinessGroupMembership membership = row.getMember();
Boolean allowLeave = membership != null;
BGTableItem item = new BGTableItem(row, null, allowLeave, Boolean.FALSE);
addAccessLink(item);
items.add(item);
}
return items;
}
use of org.olat.group.model.OpenBusinessGroupRow in project OpenOLAT by OpenOLAT.
the class BusinessGroupDAOTest method findPublicGroups.
@Test
public void findPublicGroups() {
// create a group with an access control
Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("bg-search-11");
BusinessGroup group = businessGroupDao.createAndPersist(null, "access-grp-1", "access-grp-1-desc", 0, 5, true, false, true, false, false);
// create and save an offer
Offer offer = acService.createOffer(group.getResource(), "TestBGWorkflow");
assertNotNull(offer);
offer = acService.save(offer);
acMethodManager.enableMethod(TokenAccessMethod.class, true);
List<AccessMethod> methods = acMethodManager.getAvailableMethodsByType(TokenAccessMethod.class);
AccessMethod method = methods.get(0);
OfferAccess access = acMethodManager.createOfferAccess(offer, method);
acMethodManager.save(access);
dbInstance.commitAndCloseSession();
// retrieve the offer
// check the search with the views
BusinessGroupQueryParams queryAllParams = new BusinessGroupQueryParams();
queryAllParams.setPublicGroups(Boolean.TRUE);
List<OpenBusinessGroupRow> accessGroupViews = businessGroupDao.searchPublishedBusinessGroups(queryAllParams, identity);
Assert.assertNotNull(accessGroupViews);
Assert.assertTrue(accessGroupViews.size() >= 1);
Assert.assertTrue(contains(accessGroupViews, group));
for (OpenBusinessGroupRow accessGroup : accessGroupViews) {
OLATResource resource = resourceManager.findResourceById(accessGroup.getResourceKey());
List<Offer> offers = acService.findOfferByResource(resource, true, new Date());
Assert.assertNotNull(offers);
Assert.assertFalse(offers.isEmpty());
}
}
use of org.olat.group.model.OpenBusinessGroupRow 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.OpenBusinessGroupRow 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.OpenBusinessGroupRow in project openolat by klemens.
the class BusinessGroupDAO method searchPublishedBusinessGroups.
/**
* @return
*/
public List<OpenBusinessGroupRow> searchPublishedBusinessGroups(BusinessGroupQueryParams params, IdentityRef identity) {
// need resources, access type, membership, num of pending, num of participants
StringBuilder sb = new StringBuilder();
sb.append("select bgi, ").append(" (select count(nParticipants.key) from bgroupmember as nParticipants ").append(" where nParticipants.group.key=bgi.baseGroup and nParticipants.role='").append(GroupRoles.participant.name()).append("'").append(" ) as numOfParticipants,").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 fetch bgi.baseGroup as bGroup ");
filterBusinessGroupToSearch(sb, params, false);
TypedQuery<Object[]> queryObjects = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class);
filterBusinessGroupToSearchParameters(queryObjects, params, identity, false);
List<Object[]> objects = queryObjects.getResultList();
List<OpenBusinessGroupRow> groups = new ArrayList<>(objects.size());
Map<Long, OpenBusinessGroupRow> keyToGroup = new HashMap<>();
Map<Long, OpenBusinessGroupRow> resourceKeyToGroup = new HashMap<>();
for (Object[] object : objects) {
BusinessGroupToSearch businessGroup = (BusinessGroupToSearch) object[0];
if (!keyToGroup.containsKey(businessGroup.getKey())) {
Long numOfParticipants = (Long) object[1];
Long numOfReservations = (Long) object[2];
OpenBusinessGroupRow row = new OpenBusinessGroupRow(businessGroup, numOfParticipants, numOfReservations);
groups.add(row);
keyToGroup.put(businessGroup.getKey(), row);
resourceKeyToGroup.put(businessGroup.getResource().getKey(), row);
}
}
loadRelations(keyToGroup, params, identity);
loadOfferAccess(resourceKeyToGroup);
loadMemberships(identity, keyToGroup);
return groups;
}
Aggregations