use of org.olat.resource.accesscontrol.ResourceReservation 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.resource.accesscontrol.ResourceReservation in project openolat by klemens.
the class ACFrontendManager method reserveAccessToResource.
@Override
public boolean reserveAccessToResource(final Identity identity, final OfferAccess offer) {
final OLATResource resource = offer.getOffer().getResource();
String resourceType = resource.getResourceableTypeName();
if ("BusinessGroup".equals(resourceType)) {
boolean reserved = false;
final BusinessGroup group = businessGroupDao.loadForUpdate(resource.getResourceableId());
if (group.getMaxParticipants() == null && group.getMaxParticipants() <= 0) {
// don't need reservation
reserved = true;
} else {
BusinessGroup reloadedGroup = businessGroupService.loadBusinessGroup(resource);
ResourceReservation reservation = reservationDao.loadReservation(identity, resource);
if (reservation != null) {
reserved = true;
}
int currentCount = businessGroupService.countMembers(reloadedGroup, GroupRoles.participant.name());
int reservations = reservationDao.countReservations(resource);
if (currentCount + reservations < reloadedGroup.getMaxParticipants().intValue()) {
reservationDao.createReservation(identity, offer.getMethod().getType(), null, resource);
reserved = true;
}
}
return reserved;
}
return true;
}
use of org.olat.resource.accesscontrol.ResourceReservation in project openolat by klemens.
the class ACFrontendManager method cleanupReservations.
@Override
public void cleanupReservations() {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.HOUR_OF_DAY, -1);
Date oneHourTimeout = cal.getTime();
List<ResourceReservation> oldReservations = reservationDao.loadExpiredReservation(oneHourTimeout);
for (ResourceReservation reservation : oldReservations) {
log.audit("Remove reservation:" + reservation);
reservationDao.deleteReservation(reservation);
}
}
use of org.olat.resource.accesscontrol.ResourceReservation in project openolat by klemens.
the class BusinessGroupServiceTest method testCancelPendingParticipation_deletedGroup.
@Test
public void testCancelPendingParticipation_deletedGroup() {
// create a group
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Reserv-bg-" + UUID.randomUUID().toString());
BusinessGroup group = businessGroupService.createBusinessGroup(null, "Free group", "But you must wait", new Integer(0), new Integer(2), false, false, null);
// create a reservation
Calendar cal = Calendar.getInstance();
cal.add(Calendar.HOUR, 6);
ResourceReservation reservation = reservationDao.createReservation(id, "group_participant", cal.getTime(), group.getResource());
dbInstance.commitAndCloseSession();
Assert.assertNotNull(reservation);
// delete the group
businessGroupService.deleteBusinessGroup(group);
dbInstance.commitAndCloseSession();
// accept reservation
acService.removeReservation(id, id, reservation);
dbInstance.commitAndCloseSession();
// check that the user is not participant
boolean participant2 = businessGroupService.hasRoles(id, group, GroupRoles.participant.name());
Assert.assertFalse(participant2);
// check that the reservations are deleted
List<ResourceReservation> reservations = reservationDao.loadReservations(id);
Assert.assertNotNull(reservations);
Assert.assertTrue(reservations.isEmpty());
}
use of org.olat.resource.accesscontrol.ResourceReservation in project openolat by klemens.
the class BusinessGroupServiceTest method testAcceptPendingParticipation_coach.
@Test
public void testAcceptPendingParticipation_coach() {
// create a group
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Reserv-bg-" + UUID.randomUUID().toString());
BusinessGroup group = businessGroupService.createBusinessGroup(null, "Free group", "But you must wait", new Integer(0), new Integer(2), false, false, null);
// create a reservation
Calendar cal = Calendar.getInstance();
cal.add(Calendar.HOUR, 6);
ResourceReservation reservation = reservationDao.createReservation(id, "group_coach", cal.getTime(), group.getResource());
dbInstance.commitAndCloseSession();
Assert.assertNotNull(reservation);
// check that the user is not participant
Assert.assertFalse(businessGroupService.hasRoles(id, group, GroupRoles.coach.name()));
// accept reservation
acService.acceptReservationToResource(id, reservation);
dbInstance.commitAndCloseSession();
// check that the user is participant
Assert.assertTrue(businessGroupService.hasRoles(id, group, GroupRoles.coach.name()));
// check that the reservations are deleted
List<ResourceReservation> reservations = reservationDao.loadReservations(id);
Assert.assertNotNull(reservations);
Assert.assertTrue(reservations.isEmpty());
}
Aggregations