use of org.olat.resource.accesscontrol.ResourceReservation in project OpenOLAT by OpenOLAT.
the class BusinessGroupServiceTest method testAcceptPendingParticipation_deletedGroup.
@Test
public void testAcceptPendingParticipation_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_coach", cal.getTime(), group.getResource());
dbInstance.commitAndCloseSession();
Assert.assertNotNull(reservation);
// delete the group
businessGroupService.deleteBusinessGroup(group);
dbInstance.commitAndCloseSession();
// accept reservation
acService.acceptReservationToResource(id, reservation);
dbInstance.commitAndCloseSession();
// 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 OpenOLAT.
the class BusinessGroupServiceTest method testCancelPendingParticipation_participant.
@Test
public void testCancelPendingParticipation_participant() {
// 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);
// check that the user is not participant
Assert.assertFalse(businessGroupService.hasRoles(id, group, GroupRoles.participant.name()));
// accept reservation
acService.removeReservation(id, id, reservation);
dbInstance.commitAndCloseSession();
// check that the user is not participant
Assert.assertFalse(businessGroupService.hasRoles(id, group, GroupRoles.participant.name()));
// 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 OpenOLAT.
the class BusinessGroupServiceImpl method acceptPendingParticipation.
@Override
public void acceptPendingParticipation(Identity ureqIdentity, Identity reservationOwner, OLATResource resource) {
ResourceReservation reservation = reservationDao.loadReservation(reservationOwner, resource);
if (reservation != null && "BusinessGroup".equals(resource.getResourceableTypeName())) {
BusinessGroup group = businessGroupDAO.loadForUpdate(resource.getResourceableId());
List<BusinessGroupModifiedEvent.Deferred> events = new ArrayList<BusinessGroupModifiedEvent.Deferred>();
if (group != null) {
String type = reservation.getType();
if ("group_coach".equals(type)) {
if (!businessGroupRelationDAO.hasRole(reservationOwner, group, GroupRoles.coach.name())) {
internalAddCoach(ureqIdentity, reservationOwner, group, events);
}
} else if ("group_participant".equals(type)) {
if (!businessGroupRelationDAO.hasRole(reservationOwner, group, GroupRoles.participant.name())) {
internalAddParticipant(ureqIdentity, reservationOwner, group, events);
}
}
}
reservationDao.deleteReservation(reservation);
dbInstance.commit();
BusinessGroupModifiedEvent.fireDeferredEvents(events);
}
}
use of org.olat.resource.accesscontrol.ResourceReservation in project OpenOLAT by OpenOLAT.
the class BusinessGroupServiceImpl method addParticipant.
private boolean addParticipant(Identity ureqIdentity, Roles ureqRoles, Identity identityToAdd, BusinessGroup group, MailPackage mailing, List<BusinessGroupModifiedEvent.Deferred> events) {
if (!businessGroupRelationDAO.hasRole(identityToAdd, group, GroupRoles.participant.name())) {
boolean mustAccept = true;
if (ureqIdentity != null && ureqIdentity.equals(identityToAdd)) {
// adding itself, we hope that he knows what he makes
mustAccept = false;
} else if (ureqRoles == null || ureqIdentity == null) {
// administrative task
mustAccept = false;
} else {
mustAccept = groupModule.isAcceptMembership(ureqRoles);
}
if (mustAccept) {
ResourceReservation olderReservation = reservationDao.loadReservation(identityToAdd, group.getResource());
if (olderReservation == null) {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MONTH, 6);
Date expiration = cal.getTime();
ResourceReservation reservation = reservationDao.createReservation(identityToAdd, "group_participant", expiration, group.getResource());
if (reservation != null) {
BusinessGroupMailing.sendEmail(ureqIdentity, identityToAdd, group, MailType.addParticipant, mailing);
}
}
} else {
internalAddParticipant(ureqIdentity, identityToAdd, group, events);
BusinessGroupMailing.sendEmail(ureqIdentity, identityToAdd, group, MailType.addParticipant, mailing);
}
return true;
}
return false;
}
use of org.olat.resource.accesscontrol.ResourceReservation in project OpenOLAT by OpenOLAT.
the class BusinessGroupServiceImpl method enroll.
@Override
public EnrollState enroll(Identity ureqIdentity, Roles ureqRoles, Identity identity, BusinessGroup group, MailPackage mailing) {
final BusinessGroup reloadedGroup = businessGroupDAO.loadForUpdate(group);
log.info("doEnroll start: group=" + OresHelper.createStringRepresenting(group), identity.getName());
EnrollState enrollStatus = new EnrollState();
List<BusinessGroupModifiedEvent.Deferred> events = new ArrayList<BusinessGroupModifiedEvent.Deferred>();
ResourceReservation reservation = reservationDao.loadReservation(identity, reloadedGroup.getResource());
// reservation has the highest priority over max participant or other settings
if (reservation != null) {
addParticipant(ureqIdentity, ureqRoles, identity, reloadedGroup, mailing, events);
enrollStatus.setEnrolled(BGMembership.participant);
log.info("doEnroll (reservation) - setIsEnrolled ", identity.getName());
if (reservation != null) {
reservationDao.deleteReservation(reservation);
}
} else if (reloadedGroup.getMaxParticipants() != null) {
int participantsCounter = businessGroupRelationDAO.countEnrollment(reloadedGroup);
int reservations = reservationDao.countReservations(reloadedGroup.getResource());
log.info("doEnroll - participantsCounter: " + participantsCounter + ", reservations: " + reservations + " maxParticipants: " + reloadedGroup.getMaxParticipants().intValue(), identity.getName());
if ((participantsCounter + reservations) >= reloadedGroup.getMaxParticipants().intValue()) {
// already full, show error and updated choose page again
if (reloadedGroup.getWaitingListEnabled().booleanValue()) {
addToWaitingList(ureqIdentity, identity, reloadedGroup, mailing, events);
enrollStatus.setEnrolled(BGMembership.waiting);
} else {
// No Waiting List => List is full
enrollStatus.setI18nErrorMessage("error.group.full");
enrollStatus.setFailed(true);
}
} else {
// enough place
addParticipant(ureqIdentity, ureqRoles, identity, reloadedGroup, mailing, events);
enrollStatus.setEnrolled(BGMembership.participant);
log.info("doEnroll - setIsEnrolled ", identity.getName());
}
} else {
if (log.isDebug())
log.debug("doEnroll as participant beginTransaction");
addParticipant(ureqIdentity, ureqRoles, identity, reloadedGroup, mailing, events);
enrollStatus.setEnrolled(BGMembership.participant);
if (log.isDebug())
log.debug("doEnroll as participant committed");
}
dbInstance.commit();
BusinessGroupModifiedEvent.fireDeferredEvents(events);
log.info("doEnroll end", identity.getName());
return enrollStatus;
}
Aggregations