Search in sources :

Example 16 with BusinessGroupRow

use of org.olat.group.model.BusinessGroupRow 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);
}
Also used : BusinessGroupQueryParams(org.olat.group.model.BusinessGroupQueryParams) StatisticsBusinessGroupRow(org.olat.group.model.StatisticsBusinessGroupRow) BusinessGroup(org.olat.group.BusinessGroup) OpenBusinessGroupRow(org.olat.group.model.OpenBusinessGroupRow) Identity(org.olat.core.id.Identity) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) StatisticsBusinessGroupRow(org.olat.group.model.StatisticsBusinessGroupRow) BusinessGroupRow(org.olat.group.model.BusinessGroupRow) OpenBusinessGroupRow(org.olat.group.model.OpenBusinessGroupRow) Test(org.junit.Test)

Example 17 with BusinessGroupRow

use of org.olat.group.model.BusinessGroupRow 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;
}
Also used : StatisticsBusinessGroupRow(org.olat.group.model.StatisticsBusinessGroupRow) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MarkImpl(org.olat.core.commons.services.mark.impl.MarkImpl) StatisticsBusinessGroupRow(org.olat.group.model.StatisticsBusinessGroupRow) BusinessGroupRow(org.olat.group.model.BusinessGroupRow) OpenBusinessGroupRow(org.olat.group.model.OpenBusinessGroupRow) BusinessGroupToSearch(org.olat.group.model.BusinessGroupToSearch)

Example 18 with BusinessGroupRow

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

the class BusinessGroupDAO method searchBusinessGroupsWithMemberships.

/**
 * @param params
 * @param identity
 * @return
 */
public List<BusinessGroupRow> searchBusinessGroupsWithMemberships(BusinessGroupQueryParams params, IdentityRef identity) {
    StringBuilder sm = new StringBuilder();
    sm.append("select memberships, bgi");
    appendMarkedSubQuery(sm, params);
    sm.append(" from businessgrouptosearch as bgi ").append(" inner join fetch bgi.resource as bgResource ").append(" inner join bgi.baseGroup as bGroup ");
    filterBusinessGroupToSearch(sm, params, true);
    TypedQuery<Object[]> objectsQuery = dbInstance.getCurrentEntityManager().createQuery(sm.toString(), Object[].class);
    filterBusinessGroupToSearchParameters(objectsQuery, params, identity, true);
    List<Object[]> objects = objectsQuery.getResultList();
    List<BusinessGroupRow> 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[1];
        BusinessGroupRow row;
        if (keyToGroup.containsKey(businessGroup.getKey())) {
            row = keyToGroup.get(businessGroup.getKey());
        } else {
            row = new BusinessGroupRow(businessGroup);
            groups.add(row);
            keyToGroup.put(businessGroup.getKey(), row);
            resourceKeyToGroup.put(businessGroup.getResource().getKey(), row);
        }
        Number numOfMarks = (Number) object[2];
        row.setMarked(numOfMarks == null ? false : numOfMarks.intValue() > 0);
        addMembershipToRow(row, (GroupMembershipImpl) object[0]);
    }
    loadRelations(keyToGroup, params, identity);
    loadOfferAccess(resourceKeyToGroup);
    return groups;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StatisticsBusinessGroupRow(org.olat.group.model.StatisticsBusinessGroupRow) BusinessGroupRow(org.olat.group.model.BusinessGroupRow) OpenBusinessGroupRow(org.olat.group.model.OpenBusinessGroupRow) BusinessGroupToSearch(org.olat.group.model.BusinessGroupToSearch)

Example 19 with BusinessGroupRow

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

the class BusinessGroupDAO method loadOfferAccess.

public void loadOfferAccess(Map<Long, ? extends BusinessGroupRow> resourceKeyToGroup) {
    if (resourceKeyToGroup.isEmpty())
        return;
    final int OFFERS_IN_LIMIT = 255;
    // offers
    StringBuilder so = new StringBuilder();
    so.append("select access.method, resource.key, offer.price from acofferaccess access ").append(" inner join access.offer offer").append(" inner join offer.resource resource");
    if (resourceKeyToGroup.size() < OFFERS_IN_LIMIT) {
        so.append(" where resource.key in (:resourceKeys)");
    } else {
        so.append(" where exists (select bgi.key from businessgroup bgi where bgi.resource=resource)");
    }
    TypedQuery<Object[]> offersQuery = dbInstance.getCurrentEntityManager().createQuery(so.toString(), Object[].class);
    if (resourceKeyToGroup.size() < OFFERS_IN_LIMIT) {
        List<Long> resourceKeys = new ArrayList<>(resourceKeyToGroup.size());
        for (Long resourceKey : resourceKeyToGroup.keySet()) {
            resourceKeys.add(resourceKey);
        }
        offersQuery.setParameter("resourceKeys", resourceKeys);
    }
    List<Object[]> offers = offersQuery.getResultList();
    for (Object[] offer : offers) {
        Long resourceKey = (Long) offer[1];
        BusinessGroupRow row = resourceKeyToGroup.get(resourceKey);
        if (row != null) {
            AccessMethod method = (AccessMethod) offer[0];
            Price price = (Price) offer[2];
            if (row.getBundles() == null) {
                row.setBundles(new ArrayList<>(3));
            }
            row.getBundles().add(new PriceMethodBundle(price, method));
        }
    }
}
Also used : ArrayList(java.util.ArrayList) StatisticsBusinessGroupRow(org.olat.group.model.StatisticsBusinessGroupRow) BusinessGroupRow(org.olat.group.model.BusinessGroupRow) OpenBusinessGroupRow(org.olat.group.model.OpenBusinessGroupRow) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) Price(org.olat.resource.accesscontrol.Price) PriceMethodBundle(org.olat.resource.accesscontrol.model.PriceMethodBundle)

Example 20 with BusinessGroupRow

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

the class BusinessGroupDAO method loadMemberships.

private void loadMemberships(IdentityRef identity, Map<Long, ? extends BusinessGroupRow> keyToGroup) {
    // memberships
    StringBuilder sm = new StringBuilder();
    sm.append("select membership, bgi.key").append(" from businessgroup as bgi ").append(" inner join bgi.baseGroup as bGroup ").append(" inner join bGroup.members as membership").append(" where membership.identity.key=:identityKey");
    List<Object[]> memberships = dbInstance.getCurrentEntityManager().createQuery(sm.toString(), Object[].class).setParameter("identityKey", identity.getKey()).getResultList();
    for (Object[] membership : memberships) {
        Long groupkey = (Long) membership[1];
        BusinessGroupRow row = keyToGroup.get(groupkey);
        addMembershipToRow(row, (GroupMembershipImpl) membership[0]);
    }
}
Also used : StatisticsBusinessGroupRow(org.olat.group.model.StatisticsBusinessGroupRow) BusinessGroupRow(org.olat.group.model.BusinessGroupRow) OpenBusinessGroupRow(org.olat.group.model.OpenBusinessGroupRow)

Aggregations

BusinessGroupRow (org.olat.group.model.BusinessGroupRow)60 StatisticsBusinessGroupRow (org.olat.group.model.StatisticsBusinessGroupRow)50 OpenBusinessGroupRow (org.olat.group.model.OpenBusinessGroupRow)46 BusinessGroup (org.olat.group.BusinessGroup)38 Test (org.junit.Test)34 Identity (org.olat.core.id.Identity)34 BusinessGroupQueryParams (org.olat.group.model.BusinessGroupQueryParams)34 ArrayList (java.util.ArrayList)20 SearchBusinessGroupParams (org.olat.group.model.SearchBusinessGroupParams)16 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)8 HashMap (java.util.HashMap)6 BusinessGroupMembership (org.olat.group.BusinessGroupMembership)6 BusinessGroupToSearch (org.olat.group.model.BusinessGroupToSearch)6 RepositoryEntry (org.olat.repository.RepositoryEntry)6 List (java.util.List)4 BusinessGroupSelectionEvent (org.olat.group.model.BusinessGroupSelectionEvent)4 AccessMethod (org.olat.resource.accesscontrol.model.AccessMethod)4 Calendar (java.util.Calendar)2 MarkImpl (org.olat.core.commons.services.mark.impl.MarkImpl)2 FlexiTableSearchEvent (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableSearchEvent)2