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;
}
Aggregations