Search in sources :

Example 6 with EnrollState

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

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

EnrollState (org.olat.group.model.EnrollState)6 MailPackage (org.olat.core.util.mail.MailPackage)4 BusinessGroup (org.olat.group.BusinessGroup)4 ArrayList (java.util.ArrayList)2 BusinessGroupModifiedEvent (org.olat.group.ui.edit.BusinessGroupModifiedEvent)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2 OLATResource (org.olat.resource.OLATResource)2 ResourceReservation (org.olat.resource.accesscontrol.ResourceReservation)2