Search in sources :

Example 1 with BusinessGroupMembershipViewImpl

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

the class BusinessGroupDAOTest method getMembershipInfoInBusinessGroupsWithoutIdentityParam.

@Test
public void getMembershipInfoInBusinessGroupsWithoutIdentityParam() {
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser("is-in-grp-" + UUID.randomUUID().toString());
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("is-in-grp-" + UUID.randomUUID().toString());
    Identity id3 = JunitTestHelper.createAndPersistIdentityAsUser("is-in-grp-" + UUID.randomUUID().toString());
    BusinessGroup group1 = businessGroupDao.createAndPersist(id1, "is-in-grp-1", "is-in-grp-1-desc", 0, 5, true, false, true, false, false);
    BusinessGroup group2 = businessGroupDao.createAndPersist(id2, "is-in-grp-2", "is-in-grp-2-desc", 0, 5, true, false, true, false, false);
    BusinessGroup group3 = businessGroupDao.createAndPersist(null, "is-in-grp-3", "is-in-grp-3-desc", 0, 5, true, false, true, false, false);
    dbInstance.commitAndCloseSession();
    businessGroupRelationDao.addRole(id1, group1, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(id1, group3, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(id2, group3, GroupRoles.coach.name());
    businessGroupRelationDao.addRole(id3, group2, GroupRoles.waiting.name());
    businessGroupRelationDao.addRole(id3, group3, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    List<Long> groupKeys = new ArrayList<Long>();
    groupKeys.add(group1.getKey());
    groupKeys.add(group2.getKey());
    groupKeys.add(group3.getKey());
    // check owner + attendee + waiting
    List<BusinessGroupMembershipViewImpl> memberships = businessGroupDao.getMembershipInfoInBusinessGroups(groupKeys);
    Assert.assertNotNull(memberships);
    Assert.assertEquals(7, memberships.size());
    for (BusinessGroupMembershipViewImpl membership : memberships) {
        Assert.assertNotNull(membership.getIdentityKey());
        Assert.assertNotNull(membership.getCreationDate());
        Assert.assertNotNull(membership.getLastModified());
    }
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) BusinessGroupMembershipViewImpl(org.olat.group.model.BusinessGroupMembershipViewImpl) Test(org.junit.Test)

Example 2 with BusinessGroupMembershipViewImpl

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

the class BusinessGroupServiceImpl method getBusinessGroupMembership.

@Override
public List<BusinessGroupMembership> getBusinessGroupMembership(Collection<Long> businessGroups, Identity... identity) {
    List<BusinessGroupMembershipViewImpl> views = businessGroupDAO.getMembershipInfoInBusinessGroups(businessGroups, identity);
    Map<IdentityGroupKey, BusinessGroupMembershipImpl> memberships = new HashMap<IdentityGroupKey, BusinessGroupMembershipImpl>();
    for (BusinessGroupMembershipViewImpl membership : views) {
        if (GroupRoles.coach.name().equals(membership.getRole())) {
            Long groupKey = membership.getGroupKey();
            IdentityGroupKey key = new IdentityGroupKey(membership.getIdentityKey(), groupKey);
            if (!memberships.containsKey(key)) {
                memberships.put(key, new BusinessGroupMembershipImpl(membership.getIdentityKey(), groupKey));
            }
            BusinessGroupMembershipImpl mb = memberships.get(key);
            mb.setOwner(true);
            mb.setCreationDate(membership.getCreationDate());
            mb.setLastModified(membership.getLastModified());
        }
        if (GroupRoles.participant.name().equals(membership.getRole())) {
            Long groupKey = membership.getGroupKey();
            IdentityGroupKey key = new IdentityGroupKey(membership.getIdentityKey(), groupKey);
            if (!memberships.containsKey(key)) {
                memberships.put(key, new BusinessGroupMembershipImpl(membership.getIdentityKey(), groupKey));
            }
            BusinessGroupMembershipImpl mb = memberships.get(key);
            mb.setParticipant(true);
            mb.setCreationDate(membership.getCreationDate());
            mb.setLastModified(membership.getLastModified());
        }
        if (GroupRoles.waiting.name().equals(membership.getRole())) {
            Long groupKey = membership.getGroupKey();
            IdentityGroupKey key = new IdentityGroupKey(membership.getIdentityKey(), groupKey);
            if (!memberships.containsKey(key)) {
                memberships.put(key, new BusinessGroupMembershipImpl(membership.getIdentityKey(), groupKey));
            }
            BusinessGroupMembershipImpl mb = memberships.get(key);
            mb.setWaiting(true);
            mb.setCreationDate(membership.getCreationDate());
            mb.setLastModified(membership.getLastModified());
        }
    }
    return new ArrayList<BusinessGroupMembership>(memberships.values());
}
Also used : IdentityGroupKey(org.olat.group.model.IdentityGroupKey) BusinessGroupMembershipImpl(org.olat.group.model.BusinessGroupMembershipImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BusinessGroupMembershipViewImpl(org.olat.group.model.BusinessGroupMembershipViewImpl)

Example 3 with BusinessGroupMembershipViewImpl

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

the class BusinessGroupServiceImpl method removeGroupMembers.

private final BusinessGroupMembershipViewImpl removeGroupMembers(Identity ureqIdentity, BusinessGroupMembershipViewImpl currentMembership, BusinessGroup currentGroup, Map<Long, Identity> keyToIdentityMap, Iterator<BusinessGroupMembershipViewImpl> itMembership, MailPackage mailing, List<BusinessGroupModifiedEvent.Deferred> events) {
    BusinessGroupMembershipViewImpl previsousComputedMembership = currentMembership;
    BusinessGroupMembershipViewImpl membership;
    do {
        if (previsousComputedMembership != null) {
            membership = previsousComputedMembership;
            previsousComputedMembership = null;
        } else if (itMembership.hasNext()) {
            membership = itMembership.next();
        } else {
            // security, nothing to do
            return null;
        }
        if (currentGroup.getKey().equals(membership.getGroupKey())) {
            Identity id = keyToIdentityMap.get(membership.getIdentityKey());
            if (GroupRoles.coach.name().equals(membership.getRole())) {
                removeOwner(ureqIdentity, id, currentGroup, events);
            }
            if (GroupRoles.participant.name().equals(membership.getRole())) {
                removeParticipant(ureqIdentity, id, currentGroup, mailing, events);
            }
            if (GroupRoles.waiting.name().equals(membership.getRole())) {
                removeFromWaitingList(ureqIdentity, id, currentGroup, mailing, events);
            }
        } else {
            return membership;
        }
    } while (itMembership.hasNext());
    return null;
}
Also used : Identity(org.olat.core.id.Identity) BusinessGroupMembershipViewImpl(org.olat.group.model.BusinessGroupMembershipViewImpl)

Example 4 with BusinessGroupMembershipViewImpl

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

the class BusinessGroupServiceImpl method getBusinessGroupMembership.

@Override
public List<BusinessGroupMembership> getBusinessGroupMembership(Collection<Long> businessGroups, Identity... identity) {
    List<BusinessGroupMembershipViewImpl> views = businessGroupDAO.getMembershipInfoInBusinessGroups(businessGroups, identity);
    Map<IdentityGroupKey, BusinessGroupMembershipImpl> memberships = new HashMap<IdentityGroupKey, BusinessGroupMembershipImpl>();
    for (BusinessGroupMembershipViewImpl membership : views) {
        if (GroupRoles.coach.name().equals(membership.getRole())) {
            Long groupKey = membership.getGroupKey();
            IdentityGroupKey key = new IdentityGroupKey(membership.getIdentityKey(), groupKey);
            if (!memberships.containsKey(key)) {
                memberships.put(key, new BusinessGroupMembershipImpl(membership.getIdentityKey(), groupKey));
            }
            BusinessGroupMembershipImpl mb = memberships.get(key);
            mb.setOwner(true);
            mb.setCreationDate(membership.getCreationDate());
            mb.setLastModified(membership.getLastModified());
        }
        if (GroupRoles.participant.name().equals(membership.getRole())) {
            Long groupKey = membership.getGroupKey();
            IdentityGroupKey key = new IdentityGroupKey(membership.getIdentityKey(), groupKey);
            if (!memberships.containsKey(key)) {
                memberships.put(key, new BusinessGroupMembershipImpl(membership.getIdentityKey(), groupKey));
            }
            BusinessGroupMembershipImpl mb = memberships.get(key);
            mb.setParticipant(true);
            mb.setCreationDate(membership.getCreationDate());
            mb.setLastModified(membership.getLastModified());
        }
        if (GroupRoles.waiting.name().equals(membership.getRole())) {
            Long groupKey = membership.getGroupKey();
            IdentityGroupKey key = new IdentityGroupKey(membership.getIdentityKey(), groupKey);
            if (!memberships.containsKey(key)) {
                memberships.put(key, new BusinessGroupMembershipImpl(membership.getIdentityKey(), groupKey));
            }
            BusinessGroupMembershipImpl mb = memberships.get(key);
            mb.setWaiting(true);
            mb.setCreationDate(membership.getCreationDate());
            mb.setLastModified(membership.getLastModified());
        }
    }
    return new ArrayList<BusinessGroupMembership>(memberships.values());
}
Also used : IdentityGroupKey(org.olat.group.model.IdentityGroupKey) BusinessGroupMembershipImpl(org.olat.group.model.BusinessGroupMembershipImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BusinessGroupMembershipViewImpl(org.olat.group.model.BusinessGroupMembershipViewImpl)

Example 5 with BusinessGroupMembershipViewImpl

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

the class BusinessGroupServiceImpl method removeMembers.

@Override
public void removeMembers(Identity ureqIdentity, List<Identity> identities, OLATResource resource, MailPackage mailing) {
    // nothing to do
    if (identities == null || identities.isEmpty() || resource == null)
        return;
    List<BusinessGroup> groups = null;
    if ("BusinessGroup".equals(resource.getResourceableTypeName())) {
        // it's a group resource
        BusinessGroup group = loadBusinessGroup(resource);
        if (group != null) {
            groups = Collections.singletonList(group);
        }
    } else {
        RepositoryEntryRef re = repositoryManager.lookupRepositoryEntry(resource, false);
        groups = findBusinessGroups(null, re, 0, -1);
    }
    if (groups == null || groups.isEmpty()) {
        // nothing to do
        return;
    }
    // remove managed groups
    for (Iterator<BusinessGroup> groupIt = groups.iterator(); groupIt.hasNext(); ) {
        boolean managed = BusinessGroupManagedFlag.isManaged(groupIt.next(), BusinessGroupManagedFlag.membersmanagement);
        if (managed) {
            groupIt.remove();
        }
    }
    if (groups.isEmpty()) {
        // nothing to do
        return;
    }
    List<OLATResource> groupResources = new ArrayList<OLATResource>();
    Map<Long, BusinessGroup> idToGroup = new HashMap<>();
    for (BusinessGroup group : groups) {
        groupResources.add(group.getResource());
        idToGroup.put(group.getKey(), group);
    }
    final Map<Long, Identity> keyToIdentityMap = new HashMap<Long, Identity>();
    for (Identity identity : identities) {
        keyToIdentityMap.put(identity.getKey(), identity);
    }
    List<BusinessGroupModifiedEvent.Deferred> events = new ArrayList<BusinessGroupModifiedEvent.Deferred>();
    List<BusinessGroupMembershipViewImpl> memberships = businessGroupDAO.getMembershipInfoInBusinessGroups(groups, identities);
    Collections.sort(memberships, new BusinessGroupMembershipViewComparator());
    BusinessGroupMembershipViewImpl nextGroupMembership = null;
    for (final Iterator<BusinessGroupMembershipViewImpl> itMembership = memberships.iterator(); nextGroupMembership != null || itMembership.hasNext(); ) {
        final BusinessGroupMembershipViewImpl currentMembership;
        if (nextGroupMembership == null) {
            currentMembership = itMembership.next();
        } else {
            currentMembership = nextGroupMembership;
            nextGroupMembership = null;
        }
        Long groupKey = currentMembership.getGroupKey();
        BusinessGroup nextGroup = businessGroupDAO.loadForUpdate(idToGroup.get(groupKey));
        nextGroupMembership = removeGroupMembers(ureqIdentity, currentMembership, nextGroup, keyToIdentityMap, itMembership, mailing, events);
        // release the lock
        dbInstance.commit();
    }
    List<ResourceReservation> reservations = reservationDao.loadReservations(groupResources);
    for (ResourceReservation reservation : reservations) {
        if (identities.contains(reservation.getIdentity())) {
            reservationDao.deleteReservation(reservation);
        }
    }
    dbInstance.commit();
    BusinessGroupModifiedEvent.fireDeferredEvents(events);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) HashMap(java.util.HashMap) ResourceReservation(org.olat.resource.accesscontrol.ResourceReservation) ArrayList(java.util.ArrayList) OLATResource(org.olat.resource.OLATResource) BusinessGroupModifiedEvent(org.olat.group.ui.edit.BusinessGroupModifiedEvent) RepositoryEntryRef(org.olat.repository.RepositoryEntryRef) Identity(org.olat.core.id.Identity) BusinessGroupMembershipViewImpl(org.olat.group.model.BusinessGroupMembershipViewImpl)

Aggregations

BusinessGroupMembershipViewImpl (org.olat.group.model.BusinessGroupMembershipViewImpl)12 ArrayList (java.util.ArrayList)10 Identity (org.olat.core.id.Identity)10 BusinessGroup (org.olat.group.BusinessGroup)6 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 BusinessGroupMembershipImpl (org.olat.group.model.BusinessGroupMembershipImpl)2 IdentityGroupKey (org.olat.group.model.IdentityGroupKey)2 BusinessGroupModifiedEvent (org.olat.group.ui.edit.BusinessGroupModifiedEvent)2 RepositoryEntryRef (org.olat.repository.RepositoryEntryRef)2 OLATResource (org.olat.resource.OLATResource)2 ResourceReservation (org.olat.resource.accesscontrol.ResourceReservation)2