Search in sources :

Example 6 with OpenBusinessGroupRow

use of org.olat.group.model.OpenBusinessGroupRow in project OpenOLAT by OpenOLAT.

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;
}
Also used : HashMap(java.util.HashMap) BusinessGroupToSearch(org.olat.group.model.BusinessGroupToSearch) OpenBusinessGroupRow(org.olat.group.model.OpenBusinessGroupRow) ArrayList(java.util.ArrayList)

Example 7 with OpenBusinessGroupRow

use of org.olat.group.model.OpenBusinessGroupRow in project openolat by klemens.

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());
    }
}
Also used : BusinessGroupQueryParams(org.olat.group.model.BusinessGroupQueryParams) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) OfferAccess(org.olat.resource.accesscontrol.OfferAccess) BusinessGroup(org.olat.group.BusinessGroup) Offer(org.olat.resource.accesscontrol.Offer) OpenBusinessGroupRow(org.olat.group.model.OpenBusinessGroupRow) OLATResource(org.olat.resource.OLATResource) Identity(org.olat.core.id.Identity) Date(java.util.Date) Test(org.junit.Test)

Example 8 with OpenBusinessGroupRow

use of org.olat.group.model.OpenBusinessGroupRow in project openolat by klemens.

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;
}
Also used : BusinessGroupMembership(org.olat.group.BusinessGroupMembership) OpenBusinessGroupRow(org.olat.group.model.OpenBusinessGroupRow) ArrayList(java.util.ArrayList)

Aggregations

OpenBusinessGroupRow (org.olat.group.model.OpenBusinessGroupRow)8 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 Identity (org.olat.core.id.Identity)4 BusinessGroup (org.olat.group.BusinessGroup)4 BusinessGroupQueryParams (org.olat.group.model.BusinessGroupQueryParams)4 Date (java.util.Date)2 HashMap (java.util.HashMap)2 BusinessGroupMembership (org.olat.group.BusinessGroupMembership)2 BusinessGroupRow (org.olat.group.model.BusinessGroupRow)2 BusinessGroupToSearch (org.olat.group.model.BusinessGroupToSearch)2 SearchBusinessGroupParams (org.olat.group.model.SearchBusinessGroupParams)2 StatisticsBusinessGroupRow (org.olat.group.model.StatisticsBusinessGroupRow)2 OLATResource (org.olat.resource.OLATResource)2 Offer (org.olat.resource.accesscontrol.Offer)2 OfferAccess (org.olat.resource.accesscontrol.OfferAccess)2 AccessMethod (org.olat.resource.accesscontrol.model.AccessMethod)2 TokenAccessMethod (org.olat.resource.accesscontrol.model.TokenAccessMethod)2