Search in sources :

Example 6 with ResourceReservation

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());
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) ResourceReservation(org.olat.resource.accesscontrol.ResourceReservation) Calendar(java.util.Calendar) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 7 with ResourceReservation

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());
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) ResourceReservation(org.olat.resource.accesscontrol.ResourceReservation) Calendar(java.util.Calendar) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 8 with ResourceReservation

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);
    }
}
Also used : ResourceReservation(org.olat.resource.accesscontrol.ResourceReservation) BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) BusinessGroupModifiedEvent(org.olat.group.ui.edit.BusinessGroupModifiedEvent)

Example 9 with ResourceReservation

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;
}
Also used : ResourceReservation(org.olat.resource.accesscontrol.ResourceReservation) Calendar(java.util.Calendar) Date(java.util.Date)

Example 10 with ResourceReservation

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;
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) ResourceReservation(org.olat.resource.accesscontrol.ResourceReservation) ArrayList(java.util.ArrayList) EnrollState(org.olat.group.model.EnrollState) BusinessGroupModifiedEvent(org.olat.group.ui.edit.BusinessGroupModifiedEvent)

Aggregations

ResourceReservation (org.olat.resource.accesscontrol.ResourceReservation)36 Identity (org.olat.core.id.Identity)24 Calendar (java.util.Calendar)20 BusinessGroup (org.olat.group.BusinessGroup)20 ArrayList (java.util.ArrayList)14 Date (java.util.Date)12 Test (org.junit.Test)10 OLATResource (org.olat.resource.OLATResource)8 BusinessGroupModifiedEvent (org.olat.group.ui.edit.BusinessGroupModifiedEvent)6 HashMap (java.util.HashMap)4 Order (org.olat.resource.accesscontrol.Order)4 OrderLine (org.olat.resource.accesscontrol.OrderLine)4 OrderPart (org.olat.resource.accesscontrol.OrderPart)4 HashSet (java.util.HashSet)2 Locale (java.util.Locale)2 ActionType (org.olat.core.logging.activity.ActionType)2 BusinessGroupMembership (org.olat.group.BusinessGroupMembership)2 BusinessGroupShort (org.olat.group.BusinessGroupShort)2 BusinessGroupMembershipViewImpl (org.olat.group.model.BusinessGroupMembershipViewImpl)2 EnrollState (org.olat.group.model.EnrollState)2