use of org.olat.group.model.BusinessGroupMembershipViewImpl in project openolat by klemens.
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;
}
use of org.olat.group.model.BusinessGroupMembershipViewImpl in project openolat by klemens.
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());
}
}
use of org.olat.group.model.BusinessGroupMembershipViewImpl in project OpenOLAT by OpenOLAT.
the class BusinessGroupDAOTest method getMembershipInfoInBusinessGroups.
@Test
public void getMembershipInfoInBusinessGroups() {
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("is-in-grp-" + UUID.randomUUID().toString());
BusinessGroup group1 = businessGroupDao.createAndPersist(id, "is-in-grp-1", "is-in-grp-1-desc", 0, 5, true, false, true, false, false);
BusinessGroup group2 = businessGroupDao.createAndPersist(null, "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(id, group2, GroupRoles.participant.name());
businessGroupRelationDao.addRole(id, group3, GroupRoles.waiting.name());
dbInstance.commitAndCloseSession();
List<Long> groupKeys = new ArrayList<Long>();
groupKeys.add(group1.getKey());
groupKeys.add(group2.getKey());
groupKeys.add(group3.getKey());
// check owner + attendee
int countMembershipA = businessGroupDao.countMembershipInfoInBusinessGroups(id, groupKeys);
Assert.assertEquals(3, countMembershipA);
List<BusinessGroupMembershipViewImpl> memberships = businessGroupDao.getMembershipInfoInBusinessGroups(groupKeys, id);
Assert.assertNotNull(memberships);
Assert.assertEquals(3, memberships.size());
int found = 0;
for (BusinessGroupMembershipViewImpl membership : memberships) {
Assert.assertNotNull(membership.getIdentityKey());
Assert.assertNotNull(membership.getCreationDate());
Assert.assertNotNull(membership.getLastModified());
if (membership.getGroupKey() != null && group1.getKey().equals(membership.getGroupKey())) {
found++;
}
if (membership.getGroupKey() != null && group2.getKey().equals(membership.getGroupKey())) {
found++;
}
if (membership.getGroupKey() != null && group3.getKey().equals(membership.getGroupKey())) {
found++;
}
}
Assert.assertEquals(3, found);
}
use of org.olat.group.model.BusinessGroupMembershipViewImpl in project OpenOLAT by OpenOLAT.
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);
}
use of org.olat.group.model.BusinessGroupMembershipViewImpl in project OpenOLAT by OpenOLAT.
the class BusinessGroupDAO method getMembershipInfoInBusinessGroups.
public List<BusinessGroupMembershipViewImpl> getMembershipInfoInBusinessGroups(Collection<Long> groupKeys, Identity... identity) {
StringBuilder sb = new StringBuilder();
sb.append("select membership from bgmembershipview as membership ");
boolean and = false;
if (identity != null && identity.length > 0) {
and = and(sb, and);
sb.append("membership.identityKey in (:identIds) ");
}
if (groupKeys != null && !groupKeys.isEmpty()) {
and = and(sb, and);
sb.append("membership.groupKey in (:groupKeys)");
}
TypedQuery<BusinessGroupMembershipViewImpl> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), BusinessGroupMembershipViewImpl.class);
if (identity != null && identity.length > 0) {
List<Long> ids = new ArrayList<Long>(identity.length);
for (Identity id : identity) {
ids.add(id.getKey());
}
query.setParameter("identIds", ids);
}
if (groupKeys != null && !groupKeys.isEmpty()) {
query.setParameter("groupKeys", groupKeys);
}
List<BusinessGroupMembershipViewImpl> res = query.getResultList();
return res;
}
Aggregations