Search in sources :

Example 1 with EnrollState

use of org.olat.group.model.EnrollState 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)

Example 2 with EnrollState

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

the class ACFrontendManager method allowAccesToResource.

@Override
public boolean allowAccesToResource(final Identity identity, final Offer offer) {
    // check if offer is ok: key is stupid but further check as date, validity...
    if (offer.getKey() == null) {
        return false;
    }
    // check the resource
    OLATResource resource = offer.getResource();
    if (resource == null || resource.getKey() == null || resource.getResourceableId() == null || resource.getResourceableTypeName() == null) {
        return false;
    }
    String resourceType = resource.getResourceableTypeName();
    if ("BusinessGroup".equals(resourceType)) {
        BusinessGroup group = businessGroupService.loadBusinessGroup(resource);
        if (group != null) {
            MailPackage mailing = new MailPackage(offer.isConfirmationEmail());
            EnrollState result = businessGroupService.enroll(identity, null, identity, group, mailing);
            return !result.isFailed();
        }
    } else {
        RepositoryEntry entry = repositoryManager.lookupRepositoryEntry(resource, false);
        if (entry != null) {
            if (!repositoryEntryRelationDao.hasRole(identity, entry, GroupRoles.participant.name())) {
                repositoryEntryRelationDao.addRole(identity, entry, GroupRoles.participant.name());
                if (offer.isConfirmationEmail()) {
                    MailPackage mailing = new MailPackage(offer.isConfirmationEmail());
                    RepositoryMailing.sendEmail(identity, identity, entry, RepositoryMailing.Type.addParticipantItself, mailing);
                }
            }
            return true;
        }
    }
    return false;
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) BusinessGroup(org.olat.group.BusinessGroup) OLATResource(org.olat.resource.OLATResource) EnrollState(org.olat.group.model.EnrollState) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 3 with EnrollState

use of org.olat.group.model.EnrollState in project OpenOLAT by OpenOLAT.

the class ACFrontendManager method allowAccesToResource.

@Override
public boolean allowAccesToResource(final Identity identity, final Offer offer) {
    // check if offer is ok: key is stupid but further check as date, validity...
    if (offer.getKey() == null) {
        return false;
    }
    // check the resource
    OLATResource resource = offer.getResource();
    if (resource == null || resource.getKey() == null || resource.getResourceableId() == null || resource.getResourceableTypeName() == null) {
        return false;
    }
    String resourceType = resource.getResourceableTypeName();
    if ("BusinessGroup".equals(resourceType)) {
        BusinessGroup group = businessGroupService.loadBusinessGroup(resource);
        if (group != null) {
            MailPackage mailing = new MailPackage(offer.isConfirmationEmail());
            EnrollState result = businessGroupService.enroll(identity, null, identity, group, mailing);
            return !result.isFailed();
        }
    } else {
        RepositoryEntry entry = repositoryManager.lookupRepositoryEntry(resource, false);
        if (entry != null) {
            if (!repositoryEntryRelationDao.hasRole(identity, entry, GroupRoles.participant.name())) {
                repositoryEntryRelationDao.addRole(identity, entry, GroupRoles.participant.name());
                if (offer.isConfirmationEmail()) {
                    MailPackage mailing = new MailPackage(offer.isConfirmationEmail());
                    RepositoryMailing.sendEmail(identity, identity, entry, RepositoryMailing.Type.addParticipantItself, mailing);
                }
            }
            return true;
        }
    }
    return false;
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) BusinessGroup(org.olat.group.BusinessGroup) OLATResource(org.olat.resource.OLATResource) EnrollState(org.olat.group.model.EnrollState) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 4 with EnrollState

use of org.olat.group.model.EnrollState in project OpenOLAT by OpenOLAT.

the class EnrollmentManager method doEnroll.

public EnrollStatus doEnroll(Identity identity, Roles roles, BusinessGroup group, ENCourseNode enNode, CoursePropertyManager coursePropertyManager, WindowControl wControl, Translator trans, List<Long> groupKeys, List<Long> areaKeys, CourseGroupManager cgm) {
    final EnrollStatus enrollStatus = new EnrollStatus();
    if (isLogDebugEnabled())
        logDebug("doEnroll");
    // check if the user is able to be enrolled
    int groupsEnrolledCount = getBusinessGroupsWhereEnrolled(identity, groupKeys, areaKeys, cgm.getCourseEntry()).size();
    int waitingListCount = getBusinessGroupsWhereInWaitingList(identity, groupKeys, areaKeys).size();
    int enrollCountConfig = enNode.getModuleConfiguration().getIntegerSafe(ENCourseNode.CONFIG_ALLOW_MULTIPLE_ENROLL_COUNT, 1);
    if ((groupsEnrolledCount + waitingListCount) < enrollCountConfig) {
        if (isLogDebugEnabled())
            logDebug("Identity is not enrolled identity=" + identity.getName() + "  group=" + group.getName());
        // 1. Check if group has max size defined. If so check if group is full
        // o_clusterREVIEW cg please review it - also where does the group.getMaxParticipants().equals("") come from??
        // and: why can't we just have a group here and a max participants count and an identity to enrol?
        // the group was chosen, so why do we need the groupNames and areaNames here???
        MailPackage doNotSendmailPackage = new MailPackage(false);
        EnrollState state = businessGroupService.enroll(identity, roles, identity, group, doNotSendmailPackage);
        if (state.isFailed()) {
            enrollStatus.setErrorMessage(trans.translate(state.getI18nErrorMessage()));
        } else {
            if (state.getEnrolled() == BGMembership.participant) {
                addUserToParticipantList(identity, group, enNode, coursePropertyManager, wControl, trans);
                enrollStatus.setIsEnrolled(true);
            } else if (state.getEnrolled() == BGMembership.waiting) {
                addUserToWaitingList(identity, group, enNode, coursePropertyManager, wControl, trans);
                enrollStatus.setIsInWaitingList(true);
            }
        }
    } else {
        enrollStatus.setErrorMessage(trans.translate("error.group.already.enrolled"));
    }
    if (isLogDebugEnabled())
        logDebug("doEnroll finished");
    return enrollStatus;
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) EnrollState(org.olat.group.model.EnrollState)

Example 5 with EnrollState

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

the class EnrollmentManager method doEnroll.

public EnrollStatus doEnroll(Identity identity, Roles roles, BusinessGroup group, ENCourseNode enNode, CoursePropertyManager coursePropertyManager, WindowControl wControl, Translator trans, List<Long> groupKeys, List<Long> areaKeys, CourseGroupManager cgm) {
    final EnrollStatus enrollStatus = new EnrollStatus();
    if (isLogDebugEnabled())
        logDebug("doEnroll");
    // check if the user is able to be enrolled
    int groupsEnrolledCount = getBusinessGroupsWhereEnrolled(identity, groupKeys, areaKeys, cgm.getCourseEntry()).size();
    int waitingListCount = getBusinessGroupsWhereInWaitingList(identity, groupKeys, areaKeys).size();
    int enrollCountConfig = enNode.getModuleConfiguration().getIntegerSafe(ENCourseNode.CONFIG_ALLOW_MULTIPLE_ENROLL_COUNT, 1);
    if ((groupsEnrolledCount + waitingListCount) < enrollCountConfig) {
        if (isLogDebugEnabled())
            logDebug("Identity is not enrolled identity=" + identity.getName() + "  group=" + group.getName());
        // 1. Check if group has max size defined. If so check if group is full
        // o_clusterREVIEW cg please review it - also where does the group.getMaxParticipants().equals("") come from??
        // and: why can't we just have a group here and a max participants count and an identity to enrol?
        // the group was chosen, so why do we need the groupNames and areaNames here???
        MailPackage doNotSendmailPackage = new MailPackage(false);
        EnrollState state = businessGroupService.enroll(identity, roles, identity, group, doNotSendmailPackage);
        if (state.isFailed()) {
            enrollStatus.setErrorMessage(trans.translate(state.getI18nErrorMessage()));
        } else {
            if (state.getEnrolled() == BGMembership.participant) {
                addUserToParticipantList(identity, group, enNode, coursePropertyManager, wControl, trans);
                enrollStatus.setIsEnrolled(true);
            } else if (state.getEnrolled() == BGMembership.waiting) {
                addUserToWaitingList(identity, group, enNode, coursePropertyManager, wControl, trans);
                enrollStatus.setIsInWaitingList(true);
            }
        }
    } else {
        enrollStatus.setErrorMessage(trans.translate("error.group.already.enrolled"));
    }
    if (isLogDebugEnabled())
        logDebug("doEnroll finished");
    return enrollStatus;
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) EnrollState(org.olat.group.model.EnrollState)

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