Search in sources :

Example 1 with BusinessGroupToSearch

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

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 2 with BusinessGroupToSearch

use of org.olat.group.model.BusinessGroupToSearch 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;
}
Also used : StatisticsBusinessGroupRow(org.olat.group.model.StatisticsBusinessGroupRow) 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 3 with BusinessGroupToSearch

use of org.olat.group.model.BusinessGroupToSearch 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 4 with BusinessGroupToSearch

use of org.olat.group.model.BusinessGroupToSearch 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 5 with BusinessGroupToSearch

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

Aggregations

ArrayList (java.util.ArrayList)10 BusinessGroupToSearch (org.olat.group.model.BusinessGroupToSearch)10 HashMap (java.util.HashMap)8 OpenBusinessGroupRow (org.olat.group.model.OpenBusinessGroupRow)8 StatisticsBusinessGroupRow (org.olat.group.model.StatisticsBusinessGroupRow)8 BusinessGroupRow (org.olat.group.model.BusinessGroupRow)6 MarkImpl (org.olat.core.commons.services.mark.impl.MarkImpl)2