forked from isaacphysics/isaac-api
-
Notifications
You must be signed in to change notification settings - Fork 1
788 - Waiting list bookings are not auto promoted #788 #405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mariusmarin-dev
wants to merge
5
commits into
main
Choose a base branch
from
788_auto_promotion_v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
422bc52
788 - Waiting list bookings are not auto promoted #788
mariusmarin-dev 61209b2
Test Fix
mariusmarin-dev 03ab99b
Test Fix 2
mariusmarin-dev 35364a5
Create CancelExpiredReservationsJob wrapper for backward compatibility
mariusmarin-dev f45fe39
Fix NullPointerException when IsaacCardDeck has null cards list
mariusmarin-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/java/uk/ac/cam/cl/dtg/segue/scheduler/jobs/CancelExpiredReservationsJob.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package uk.ac.cam.cl.dtg.segue.scheduler.jobs; | ||
|
|
||
| import org.quartz.Job; | ||
| import org.quartz.JobExecutionContext; | ||
| import org.quartz.JobExecutionException; | ||
|
|
||
| /** | ||
| * Legacy wrapper for backwards compatibility with existing Quartz scheduler database entries. | ||
| * This job delegates to ExpiredReservationsCleanUpJob which contains the actual implementation. | ||
| * | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocParagraphCheck> reported by reviewdog 🐶 tag on the next line. |
||
| * This allows us to keep the existing trigger name in the database while using the new | ||
| * ExpiredReservationsCleanUpJob implementation. | ||
| */ | ||
| public class CancelExpiredReservationsJob implements Job { | ||
|
|
||
| private final ExpiredReservationsCleanUpJob delegate = new ExpiredReservationsCleanUpJob(); | ||
|
|
||
| @Override | ||
| public void execute(final JobExecutionContext context) throws JobExecutionException { | ||
| delegate.execute(context); | ||
| } | ||
| } | ||
129 changes: 129 additions & 0 deletions
129
src/main/java/uk/ac/cam/cl/dtg/segue/scheduler/jobs/ExpiredReservationsCleanUpJob.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| package uk.ac.cam.cl.dtg.segue.scheduler.jobs; | ||
|
|
||
| import com.google.inject.Injector; | ||
| import java.util.List; | ||
| import org.quartz.Job; | ||
| import org.quartz.JobExecutionContext; | ||
| import org.quartz.JobExecutionException; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import uk.ac.cam.cl.dtg.isaac.api.managers.EventBookingManager; | ||
| import uk.ac.cam.cl.dtg.isaac.dao.EventBookingPersistenceManager; | ||
| import uk.ac.cam.cl.dtg.isaac.dto.IsaacEventPageDTO; | ||
| import uk.ac.cam.cl.dtg.isaac.dto.eventbookings.DetailedEventBookingDTO; | ||
| import uk.ac.cam.cl.dtg.isaac.dto.users.RegisteredUserDTO; | ||
| import uk.ac.cam.cl.dtg.segue.api.managers.IUserAccountManager; | ||
| import uk.ac.cam.cl.dtg.segue.auth.exceptions.NoUserException; | ||
| import uk.ac.cam.cl.dtg.segue.configuration.SegueGuiceConfigurationModule; | ||
| import uk.ac.cam.cl.dtg.segue.dao.ResourceNotFoundException; | ||
| import uk.ac.cam.cl.dtg.segue.dao.SegueDatabaseException; | ||
| import uk.ac.cam.cl.dtg.segue.dao.content.ContentManagerException; | ||
| import uk.ac.cam.cl.dtg.segue.dao.content.GitContentManager; | ||
|
|
||
| /** | ||
| * Scheduled job to clean up expired RESERVED event bookings and trigger auto-promotion of waiting list users. | ||
| * This job replaces the simple SQL cleanup with proper auto-promotion logic by: | ||
| * 1. Finding all RESERVED bookings that have passed their reservationCloseDate | ||
| * 2. For each expired reservation, calling cancelBooking() to trigger auto-promotion | ||
| * 3. Promoting waiting list users in chronological order as spots become available | ||
| * Previously, the SQL-only approach would cancel reservations but not promote waiting list users, | ||
| * leaving events marked as full of available spots. | ||
| */ | ||
| public class ExpiredReservationsCleanUpJob implements Job { | ||
| private static final Logger log = LoggerFactory.getLogger(ExpiredReservationsCleanUpJob.class); | ||
|
|
||
| private final EventBookingPersistenceManager bookingPersistenceManager; | ||
| private final EventBookingManager bookingManager; | ||
| private final IUserAccountManager userAccountManager; | ||
| private final GitContentManager contentManager; | ||
|
|
||
| /** | ||
| * Constructor for Quartz Job - must be no-arg and retrieve dependencies from injector. | ||
| */ | ||
| public ExpiredReservationsCleanUpJob() { | ||
| Injector injector = SegueGuiceConfigurationModule.getGuiceInjector(); | ||
| bookingPersistenceManager = injector.getInstance(EventBookingPersistenceManager.class); | ||
| bookingManager = injector.getInstance(EventBookingManager.class); | ||
| userAccountManager = injector.getInstance(IUserAccountManager.class); | ||
| contentManager = injector.getInstance(GitContentManager.class); | ||
| } | ||
|
|
||
| @Override | ||
| public void execute(final JobExecutionContext context) throws JobExecutionException { | ||
| try { | ||
| log.info("Starting ExpiredReservationsCleanUpJob"); | ||
|
|
||
| List<DetailedEventBookingDTO> expiredReservations = | ||
| bookingPersistenceManager.getExpiredReservedBookings(); | ||
|
|
||
| if (expiredReservations.isEmpty()) { | ||
| log.info("No expired reservations found"); | ||
| return; | ||
| } | ||
|
|
||
| log.info("Found {} expired RESERVED bookings to process", expiredReservations.size()); | ||
|
|
||
| int successCount = 0; | ||
| int failureCount = 0; | ||
|
|
||
| for (DetailedEventBookingDTO expiredBooking : expiredReservations) { | ||
| try { | ||
| // Get the event details | ||
| IsaacEventPageDTO event = (IsaacEventPageDTO) contentManager | ||
| .getContentById(expiredBooking.getEventId()); | ||
|
|
||
| if (event == null) { | ||
| log.warn("Event {} not found for expired booking {}. Skipping.", | ||
| expiredBooking.getEventId(), expiredBooking.getBookingId()); | ||
| failureCount++; | ||
| continue; | ||
| } | ||
|
|
||
| // Get the user details | ||
| RegisteredUserDTO user = userAccountManager | ||
| .getUserDTOById(expiredBooking.getUserBooked().getId()); | ||
|
|
||
| if (user == null) { | ||
| log.warn("User {} not found for expired booking {}. Skipping.", | ||
| expiredBooking.getUserBooked().getId(), expiredBooking.getBookingId()); | ||
| failureCount++; | ||
| continue; | ||
| } | ||
|
|
||
| // Cancel the booking - this triggers auto-promotion of waiting list users! | ||
| try { | ||
| bookingManager.cancelBooking(event, user); | ||
| log.info("Cancelled expired RESERVED booking for user {} on event {} (booking id: {})", | ||
| user.getId(), event.getId(), expiredBooking.getBookingId()); | ||
| successCount++; | ||
| } catch (SegueDatabaseException e) { | ||
| log.error("Database error while cancelling expired reservation {} for user {} on event {}", | ||
| expiredBooking.getBookingId(), user.getId(), event.getId(), e); | ||
| failureCount++; | ||
| } catch (ContentManagerException e) { | ||
| log.error("Content manager error while cancelling expired reservation {} for user {} on event {}", | ||
| expiredBooking.getBookingId(), user.getId(), event.getId(), e); | ||
| failureCount++; | ||
| } | ||
| } catch (NoUserException e) { | ||
| log.warn("User not found for expired booking {}", expiredBooking.getBookingId(), e); | ||
| failureCount++; | ||
| } catch (ResourceNotFoundException e) { | ||
| log.warn("Event not found for expired booking {}", expiredBooking.getBookingId(), e); | ||
| failureCount++; | ||
| } catch (ContentManagerException e) { | ||
| log.error("Content manager error while retrieving event for expired booking {}", | ||
| expiredBooking.getBookingId(), e); | ||
| failureCount++; | ||
| } | ||
| } | ||
|
|
||
| log.info("ExpiredReservationsCleanUpJob completed: {} successful cancellations, {} failures", | ||
| successCount, failureCount); | ||
|
|
||
| } catch (SegueDatabaseException e) { | ||
| log.error("Failed to retrieve expired reservations for ExpiredReservationsCleanUpJob", e); | ||
| throw new JobExecutionException(e); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / CodeQL
Missing Override annotation Note