Search in sources :

Example 1 with BusinessGroupRow

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

the class CourseBusinessGroupListController method doConfirmRemove.

private void doConfirmRemove(UserRequest ureq, List<BusinessGroupRow> selectedItems) {
    StringBuilder sb = new StringBuilder();
    StringBuilder managedSb = new StringBuilder();
    for (BusinessGroupRow item : selectedItems) {
        String gname = item.getName() == null ? "???" : StringHelper.escapeHtml(item.getName());
        if (BusinessGroupManagedFlag.isManaged(item.getManagedFlags(), BusinessGroupManagedFlag.resources)) {
            if (managedSb.length() > 0)
                managedSb.append(", ");
            managedSb.append(gname);
        } else {
            if (sb.length() > 0)
                sb.append(", ");
            sb.append(gname);
        }
    }
    if (managedSb.length() > 0) {
        showWarning("error.managed.group", managedSb.toString());
    } else {
        String text = getTranslator().translate("group.remove", new String[] { sb.toString(), StringHelper.escapeHtml(re.getDisplayname()) });
        confirmRemoveMultiResource = activateYesNoDialog(ureq, null, text, confirmRemoveResource);
        confirmRemoveMultiResource.setUserObject(selectedItems);
    }
}
Also used : StatisticsBusinessGroupRow(org.olat.group.model.StatisticsBusinessGroupRow) BusinessGroupRow(org.olat.group.model.BusinessGroupRow)

Example 2 with BusinessGroupRow

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

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 3 with BusinessGroupRow

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

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

the class BusinessGroupDAO method loadRelations.

private void loadRelations(Map<Long, ? extends BusinessGroupRow> keyToGroup, BusinessGroupQueryParams params, IdentityRef identity) {
    if (keyToGroup.isEmpty())
        return;
    // no resources, no relations
    if (params.getResources() != null && !params.getResources().booleanValue())
        return;
    // headless don't have relations
    if (params.isHeadless())
        return;
    final int RELATIONS_IN_LIMIT = 64;
    final boolean restrictToMembership = params != null && identity != null && (params.isAttendee() || params.isOwner() || params.isWaiting() || params.isMarked());
    // resources
    StringBuilder sr = new StringBuilder();
    sr.append("select entry.key, entry.displayname, bgi.key from repoentrytobusinessgroup as v").append(" inner join v.entry entry").append(" inner join v.businessGroup relationToGroup").append(" inner join relationToGroup.businessGroups bgi");
    if (restrictToMembership) {
        sr.append(" inner join bgi.baseGroup as bGroup ").append(" inner join bGroup.members as membership on membership.identity.key=:identityKey");
    } else if (keyToGroup.size() < RELATIONS_IN_LIMIT) {
        sr.append(" where bgi.key in (:businessGroupKeys)");
    } else if (params.getPublicGroups() != null && params.getPublicGroups().booleanValue()) {
        sr.append(" inner join acoffer as offer on (bgi.resource.key = offer.resource.key)");
    } else if (params.getRepositoryEntry() != null) {
        sr.append(" inner join repoentrytobusinessgroup as refBgiToGroup").append("   on (refBgiToGroup.entry.key=:repositoryEntryKey and bgi.baseGroup.key=refBgiToGroup.businessGroup.key)");
    } else {
        sr.append(" inner join bgi.resource as bgResource ").append(" inner join bgi.baseGroup as bGroup ");
        filterBusinessGroupToSearch(sr, params, false);
    }
    TypedQuery<Object[]> resourcesQuery = dbInstance.getCurrentEntityManager().createQuery(sr.toString(), Object[].class);
    if (restrictToMembership) {
        resourcesQuery.setParameter("identityKey", identity.getKey());
    } else if (keyToGroup.size() < RELATIONS_IN_LIMIT) {
        List<Long> businessGroupKeys = new ArrayList<>(keyToGroup.size());
        for (Long businessGroupKey : keyToGroup.keySet()) {
            businessGroupKeys.add(businessGroupKey);
        }
        resourcesQuery.setParameter("businessGroupKeys", businessGroupKeys);
    } else if (params.getPublicGroups() != null && params.getPublicGroups().booleanValue()) {
    // no parameters to add
    } else if (params.getRepositoryEntry() != null) {
        resourcesQuery.setParameter("repositoryEntryKey", params.getRepositoryEntry().getKey());
    } else {
        filterBusinessGroupToSearchParameters(resourcesQuery, params, identity, false);
    }
    List<Object[]> resources = resourcesQuery.getResultList();
    for (Object[] resource : resources) {
        Long groupKey = (Long) resource[2];
        BusinessGroupRow row = keyToGroup.get(groupKey);
        if (row != null) {
            Long entryKey = (Long) resource[0];
            String displayName = (String) resource[1];
            REShort entry = new REShort(entryKey, displayName);
            if (row.getResources() == null) {
                row.setResources(new ArrayList<>(4));
            }
            row.getResources().add(entry);
        }
    }
}
Also used : StatisticsBusinessGroupRow(org.olat.group.model.StatisticsBusinessGroupRow) BusinessGroupRow(org.olat.group.model.BusinessGroupRow) OpenBusinessGroupRow(org.olat.group.model.OpenBusinessGroupRow) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with BusinessGroupRow

use of org.olat.group.model.BusinessGroupRow 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)

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