use of uk.ac.cam.cl.dtg.isaac.api.managers.EventDeadlineException in project isaac-api by isaacphysics.
the class EventsFacade method addMeToWaitingList.
/**
* Add current user to waiting list for the given event.
*
* @param request
* - so we can determine if the user is logged in
* @param eventId
* - event id
* @return the new booking
*/
@POST
@Path("{event_id}/waiting_list")
@Produces(MediaType.APPLICATION_JSON)
@GZIP
@ApiOperation(value = "Add the current user to an event waiting list.")
public final Response addMeToWaitingList(@Context final HttpServletRequest request, @PathParam("event_id") final String eventId, final Map<String, String> additionalInformation) {
try {
RegisteredUserDTO user = userManager.getCurrentRegisteredUser(request);
IsaacEventPageDTO event = this.getAugmentedEventDTOById(request, eventId);
EventBookingDTO eventBookingDTO = bookingManager.requestWaitingListBooking(event, user, additionalInformation);
this.getLogManager().logEvent(userManager.getCurrentUser(request), request, SegueServerLogType.EVENT_WAITING_LIST_BOOKING, ImmutableMap.of(EVENT_ID_FKEY_FIELDNAME, event.getId()));
return Response.ok(this.mapper.map(eventBookingDTO, EventBookingDTO.class)).build();
} catch (NoUserLoggedInException e) {
return SegueErrorResponse.getNotLoggedInResponse();
} catch (SegueDatabaseException e) {
String errorMsg = "Database error occurred while trying to book a user onto an event.";
log.error(errorMsg, e);
return new SegueErrorResponse(Status.INTERNAL_SERVER_ERROR, errorMsg).toResponse();
} catch (ContentManagerException e) {
return new SegueErrorResponse(Status.INTERNAL_SERVER_ERROR, "Content Database error occurred while trying to retrieve all event booking information.").toResponse();
} catch (EmailMustBeVerifiedException e) {
return new SegueErrorResponse(Status.BAD_REQUEST, "In order to book on this event your user account must have a verified email address. Please verify your address to make a booking.").toResponse();
} catch (DuplicateBookingException e) {
return new SegueErrorResponse(Status.BAD_REQUEST, "You have already been booked on this event. Unable to create a duplicate booking.").toResponse();
} catch (EventDeadlineException e) {
return new SegueErrorResponse(Status.BAD_REQUEST, "The booking deadline for this event has passed. No more bookings are being accepted.").toResponse();
} catch (EventIsNotFullException e) {
return new SegueErrorResponse(Status.CONFLICT, "There are spaces on this event and the deadline has not passed. Please use the request booking endpoint to book you on to it.").toResponse();
}
}
use of uk.ac.cam.cl.dtg.isaac.api.managers.EventDeadlineException in project isaac-api by isaacphysics.
the class EventsFacade method createReservationsForGivenUsers.
/**
* Add event reservations for the given users.
*
* @param request
* - so we can determine who is making the request
* @param eventId
* - event id
* @param userIds
* - the users to reserve spaces for
* @return the list of bookings/reservations
*/
@POST
@Path("{event_id}/reservations")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Add event reservations for the given users.")
public final Response createReservationsForGivenUsers(@Context final HttpServletRequest request, @PathParam("event_id") final String eventId, final List<Long> userIds) {
RegisteredUserDTO reservingUser;
IsaacEventPageDTO event;
try {
event = this.getRawEventDTOById(eventId);
} catch (SegueDatabaseException | ContentManagerException e) {
event = null;
}
if (null == event) {
return new SegueErrorResponse(Status.BAD_REQUEST, "No event found with this ID.").toResponse();
}
if (!EventBookingManager.eventAllowsGroupBookings(event)) {
return new SegueErrorResponse(Status.FORBIDDEN, "This event does not accept group bookings.").toResponse();
}
List<RegisteredUserDTO> usersToReserve = Lists.newArrayList();
try {
reservingUser = userManager.getCurrentRegisteredUser(request);
if (!Arrays.asList(Role.TEACHER, Role.EVENT_LEADER, Role.EVENT_MANAGER, Role.ADMIN).contains(reservingUser.getRole())) {
return SegueErrorResponse.getIncorrectRoleResponse();
}
// Enforce permission
for (Long userId : userIds) {
RegisteredUserDTO userToReserve = userManager.getUserDTOById(userId);
if (userAssociationManager.hasPermission(reservingUser, userToReserve)) {
usersToReserve.add(userToReserve);
} else {
return new SegueErrorResponse(Status.FORBIDDEN, "You do not have permission to book or reserve some of these users onto this event.").toResponse();
}
}
List<EventBookingDTO> bookings = bookingManager.requestReservations(event, usersToReserve, reservingUser);
this.getLogManager().logEvent(reservingUser, request, SegueServerLogType.EVENT_RESERVATIONS_CREATED, ImmutableMap.of(EVENT_ID_FKEY_FIELDNAME, event.getId(), USER_ID_FKEY_FIELDNAME, reservingUser.getId(), USER_ID_LIST_FKEY_FIELDNAME, userIds.toArray(), BOOKING_STATUS_FIELDNAME, BookingStatus.RESERVED.toString()));
return Response.ok(this.mapper.mapAsList(bookings, EventBookingDTO.class)).build();
} catch (NoUserLoggedInException e) {
return SegueErrorResponse.getNotLoggedInResponse();
} catch (SegueDatabaseException e) {
String errorMsg = "Database error occurred while trying to reserve space for a user onto an event.";
log.error(errorMsg, e);
return new SegueErrorResponse(Status.INTERNAL_SERVER_ERROR, errorMsg).toResponse();
} catch (EventIsFullException e) {
return new SegueErrorResponse(Status.CONFLICT, "There are not enough spaces available for this event. Please try again with fewer users.").toResponse();
} catch (EventGroupReservationLimitException e) {
return new SegueErrorResponse(Status.CONFLICT, String.format("You can only request a maximum of %d student reservations for this event.", event.getGroupReservationLimit())).toResponse();
} catch (EventDeadlineException e) {
return new SegueErrorResponse(Status.BAD_REQUEST, "The booking deadline for this event has passed. No more bookings or reservations are being accepted.").toResponse();
} catch (DuplicateBookingException e) {
return new SegueErrorResponse(Status.BAD_REQUEST, "One of the users requested is already booked or reserved on this event. Unable to create a duplicate booking.").toResponse();
} catch (NoUserException e) {
return SegueErrorResponse.getResourceNotFoundResponse("Unable to locate one of the users specified.");
}
}
use of uk.ac.cam.cl.dtg.isaac.api.managers.EventDeadlineException in project isaac-api by isaacphysics.
the class EventsFacade method createBookingForMe.
/**
* createBooking for the current user.
*
* @param request
* - so we can determine if the user is logged in
* @param eventId
* - event id
* @return the new booking if allowed to book.
*/
@POST
@Path("{event_id}/bookings")
@Produces(MediaType.APPLICATION_JSON)
@GZIP
@ApiOperation(value = "Create an event booking for the current user.")
public final Response createBookingForMe(@Context final HttpServletRequest request, @PathParam("event_id") final String eventId, final Map<String, String> additionalInformation) {
try {
RegisteredUserDTO user = userManager.getCurrentRegisteredUser(request);
IsaacEventPageDTO event = this.getAugmentedEventDTOById(request, eventId);
if (EventStatus.CLOSED.equals(event.getEventStatus())) {
return new SegueErrorResponse(Status.BAD_REQUEST, "Sorry booking for this event is closed. Please try again later.").toResponse();
}
if (EventStatus.WAITING_LIST_ONLY.equals(event.getEventStatus())) {
return new SegueErrorResponse(Status.BAD_REQUEST, "Sorry booking for this event is restricted. You can only be added to a waiting list.").toResponse();
}
if (bookingManager.isUserBooked(eventId, user.getId())) {
return new SegueErrorResponse(Status.BAD_REQUEST, "You are already booked on this event.").toResponse();
}
// reservedBy is null. If there is a reservation for me, it will be updated to CONFIRMED.
EventBookingDTO eventBookingDTO = bookingManager.requestBooking(event, user, additionalInformation);
this.getLogManager().logEvent(userManager.getCurrentUser(request), request, SegueServerLogType.EVENT_BOOKING, ImmutableMap.of(EVENT_ID_FKEY_FIELDNAME, event.getId()));
return Response.ok(this.mapper.map(eventBookingDTO, EventBookingDTO.class)).build();
} catch (NoUserLoggedInException e) {
return SegueErrorResponse.getNotLoggedInResponse();
} catch (SegueDatabaseException e) {
String errorMsg = "Database error occurred while trying to book a user onto an event.";
log.error(errorMsg, e);
return new SegueErrorResponse(Status.INTERNAL_SERVER_ERROR, errorMsg).toResponse();
} catch (ContentManagerException e) {
return new SegueErrorResponse(Status.INTERNAL_SERVER_ERROR, "Content Database error occurred while trying to retrieve all event booking information.").toResponse();
} catch (EmailMustBeVerifiedException e) {
return new SegueErrorResponse(Status.BAD_REQUEST, "In order to book on this event your user account must have a verified email address. Please verify your address to make a booking.").toResponse();
} catch (DuplicateBookingException e) {
return new SegueErrorResponse(Status.BAD_REQUEST, "You have already been booked on this event. Unable to create a duplicate booking.").toResponse();
} catch (EventIsFullException e) {
return new SegueErrorResponse(Status.CONFLICT, "This event is already full. Unable to book you on to it.").toResponse();
} catch (EventDeadlineException e) {
return new SegueErrorResponse(Status.BAD_REQUEST, "The booking deadline for this event has passed. No more bookings are being accepted.").toResponse();
}
}
Aggregations