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 #401
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
6
commits into
main
Choose a base branch
from
788_auto_promotion
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
6 commits
Select commit
Hold shift + click to select a range
b64b666
788 - Waiting list bookings are not auto promoted #788
mariusmarin-dev 4c0ed65
788 - Waiting list bookings are not auto promoted #788
mariusmarin-dev 8410a5a
788 - Waiting list bookings are not auto promoted #788
mariusmarin-dev 388c0e4
Update cancel reservation cronjob
mariusmarin-dev 1fe0c96
Update cancel reservation cronjob
mariusmarin-dev ecf32af
Add null check con cardDeck
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -216,6 +216,23 @@ public List<DetailedEventBookingDTO> adminGetBookingsByEventId(final String even | |
| public List<DetailedEventBookingDTO> adminGetBookingsByEventIdAndStatus(final String eventId, | ||
| final BookingStatus status) | ||
| throws SegueDatabaseException { | ||
| return adminGetBookingsByEventIdAndStatus(eventId, status, false); | ||
| } | ||
|
|
||
| /** | ||
| * Get event bookings by an event id and status with control over deleted user inclusion. | ||
| * WARNING: This pulls PII such as dietary info, email, and other stuff that should not (always) make it to end users. | ||
| * | ||
| * @param eventId of interest | ||
| * @param status of interest | ||
| * @param includeDeletedUsers if true, include bookings from deleted users; if false, exclude them | ||
| * @return event bookings | ||
| * @throws SegueDatabaseException if an error occurs. | ||
| */ | ||
| public List<DetailedEventBookingDTO> adminGetBookingsByEventIdAndStatus(final String eventId, | ||
| final BookingStatus status, | ||
| final boolean includeDeletedUsers) | ||
| throws SegueDatabaseException { | ||
| try { | ||
| ContentDTO c = this.contentManager.getContentById(eventId); | ||
|
|
||
|
|
@@ -224,7 +241,8 @@ public List<DetailedEventBookingDTO> adminGetBookingsByEventIdAndStatus(final St | |
| } | ||
|
|
||
| if (c instanceof IsaacEventPageDTO eventPageDTO) { | ||
| return this.convertToDTO(Lists.newArrayList(dao.findAllByEventIdAndStatus(eventId, status)), eventPageDTO); | ||
| return this.convertToDTO(Lists.newArrayList(dao | ||
| .findAllByEventIdAndStatus(eventId, status, includeDeletedUsers)), eventPageDTO); | ||
| } else { | ||
| log.error(EXCEPTION_MESSAGE_NOT_EVENT); | ||
| throw new SegueDatabaseException(EXCEPTION_MESSAGE_NOT_EVENT); | ||
|
|
@@ -491,4 +509,14 @@ public List<DetailedEventBookingDTO> getBookingsByEventIdForUsers(String competi | |
| throws SegueDatabaseException { | ||
| return this.getBookingByEventIdAndUsersId(competitionId, userIds); | ||
| } | ||
|
|
||
| /** | ||
| * Get all RESERVED bookings that have expired. | ||
| * | ||
| * @return list of expired reservations | ||
| * @throws SegueDatabaseException if an error occurs. | ||
| */ | ||
| public List<DetailedEventBookingDTO> getExpiredReservations() throws SegueDatabaseException { | ||
| return convertToDTO(Lists.newArrayList(dao.findExpiredReservations())); | ||
| } | ||
| } | ||
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 |
|---|---|---|
|
|
@@ -146,6 +146,19 @@ Map<BookingStatus, Map<Role, Integer>> getEventBookingStatusCounts(String eventI | |
| Iterable<EventBooking> findAllByEventIdAndStatus(String eventId, @Nullable BookingStatus status) | ||
| throws SegueDatabaseException; | ||
|
|
||
| /** | ||
| * Find all bookings for a given event with a given status, with control over deleted user inclusion. | ||
| * | ||
| * @param eventId the event of interest. | ||
| * @param status - The event status that should match in the bookings returned. | ||
| * @param includeDeletedUsers if true, include bookings from deleted users; if false, exclude them. | ||
| * @return an iterable with all the events matching the criteria. | ||
| * @throws SegueDatabaseException - if an error occurs. | ||
| */ | ||
| Iterable<EventBooking> findAllByEventIdAndStatus(String eventId, @Nullable BookingStatus status, | ||
| boolean includeDeletedUsers) | ||
| throws SegueDatabaseException; | ||
|
|
||
| /** | ||
| * Find all bookings for a given event. | ||
| * | ||
|
|
@@ -200,4 +213,12 @@ Iterable<EventBooking> findAllByEventIdAndStatus(String eventId, @Nullable Booki | |
| * @param userId - user id | ||
| */ | ||
| void deleteAdditionalInformation(Long userId) throws SegueDatabaseException; | ||
|
|
||
| /** | ||
| * Find all RESERVED bookings that have expired (reservationCloseDate has passed). | ||
| * | ||
| * @return an iterable with all expired reservations. | ||
| * @throws SegueDatabaseException - if an error occurs. | ||
| */ | ||
| Iterable<EventBooking> findExpiredReservations() throws SegueDatabaseException; | ||
| } | ||
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 |
|---|---|---|
|
|
@@ -54,6 +54,7 @@ | |
| * <br> | ||
| * Postgres aware EventBookings. | ||
| */ | ||
| @SuppressWarnings("checkstyle:InvalidJavadocPosition") | ||
| public class PgEventBookings implements EventBookings { | ||
| private static final Logger log = LoggerFactory.getLogger(PgEventBookings.class); | ||
|
|
||
|
|
@@ -634,11 +635,34 @@ public Map<BookingStatus, Map<Role, Integer>> getEventBookingStatusCounts(final | |
| @Override | ||
| public Iterable<EventBooking> findAllByEventIdAndStatus(final String eventId, @Nullable final BookingStatus status) | ||
| throws SegueDatabaseException { | ||
| return findAllByEventIdAndStatus(eventId, status, false); | ||
| } | ||
|
|
||
| /** | ||
| * Find all bookings for a given event with a given status. | ||
| * <br> | ||
| * Useful for finding all on a waiting list or confirmed. | ||
| * | ||
| * @param eventId the event of interest. | ||
| * @param status The event status that should match in the bookings returned. Can be null | ||
| * @param includeDeletedUsers if true, include bookings from deleted users; if false, exclude them | ||
| * @return an iterable with all the events matching the criteria. | ||
| * @throws SegueDatabaseException if an error occurs. | ||
| */ | ||
| @Override | ||
| public Iterable<EventBooking> findAllByEventIdAndStatus( | ||
| final String eventId, | ||
| @Nullable final BookingStatus status, | ||
| final boolean includeDeletedUsers) | ||
| throws SegueDatabaseException { | ||
| Validate.notBlank(eventId); | ||
|
|
||
| StringBuilder sb = new StringBuilder(); | ||
| sb.append("SELECT event_bookings.* FROM event_bookings JOIN users ON users.id=user_id WHERE event_id=?" | ||
| + " AND NOT users.deleted"); | ||
| sb.append("SELECT event_bookings.* FROM event_bookings JOIN users ON users.id=user_id WHERE event_id=?"); | ||
|
|
||
| if (!includeDeletedUsers) { | ||
| sb.append(" AND NOT users.deleted"); | ||
| } | ||
|
|
||
| if (status != null) { | ||
| sb.append(" AND status = ?"); | ||
|
|
@@ -767,6 +791,35 @@ public Iterable<EventBooking> findAllReservationsByUserId(final Long userId) thr | |
| * @return a new PgEventBooking | ||
| * @throws SQLException if an error occurs. | ||
| */ | ||
| /** | ||
| * Find all bookings that are RESERVED and have expired reservation close dates. | ||
| * | ||
| * @return an iterable with all expired reservations. | ||
| * @throws SegueDatabaseException if an error occurs. | ||
| */ | ||
| @Override | ||
| public Iterable<EventBooking> findExpiredReservations() throws SegueDatabaseException { | ||
| String query = "SELECT event_bookings.* FROM event_bookings " | ||
| + "WHERE status = ? " | ||
| + "AND (additional_booking_information->>'reservationCloseDate')::timestamptz < NOW()"; | ||
|
|
||
| try (Connection conn = ds.getDatabaseConnection(); | ||
| PreparedStatement pst = conn.prepareStatement(query) | ||
| ) { | ||
| pst.setString(1, BookingStatus.RESERVED.name()); | ||
|
|
||
| try (ResultSet results = pst.executeQuery()) { | ||
| List<EventBooking> returnResult = Lists.newArrayList(); | ||
| while (results.next()) { | ||
| returnResult.add(buildPgEventBooking(results)); | ||
| } | ||
| return returnResult; | ||
| } | ||
| } catch (SQLException e) { | ||
| throw new SegueDatabaseException(EXCEPTION_MESSAGE_POSTGRES_ERROR, e); | ||
| } | ||
| } | ||
|
|
||
| private PgEventBooking buildPgEventBooking(final ResultSet results) throws SQLException, SegueDatabaseException { | ||
| return new PgEventBooking( | ||
| results.getLong("id"), | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -177,6 +177,7 @@ | |
| import uk.ac.cam.cl.dtg.segue.scheduler.SegueJobService; | ||
| import uk.ac.cam.cl.dtg.segue.scheduler.SegueScheduledDatabaseScriptJob; | ||
| import uk.ac.cam.cl.dtg.segue.scheduler.SegueScheduledJob; | ||
| import uk.ac.cam.cl.dtg.segue.scheduler.jobs.CancelExpiredReservationsJob; | ||
| import uk.ac.cam.cl.dtg.segue.scheduler.jobs.DeleteEventAdditionalBookingInformationJob; | ||
| import uk.ac.cam.cl.dtg.segue.scheduler.jobs.DeleteEventAdditionalBookingInformationOneYearJob; | ||
| import uk.ac.cam.cl.dtg.segue.scheduler.jobs.EventFeedbackEmailJob; | ||
|
|
@@ -1002,11 +1003,14 @@ private static SegueJobService getSegueJobService(final PropertiesLoader propert | |
| "SQL scheduled job that deletes old AnonymousUsers", | ||
| CRON_STRING_0230_DAILY, "db_scripts/scheduled/anonymous-user-clean-up.sql"); | ||
|
|
||
| SegueScheduledJob cleanUpExpiredReservations = new SegueScheduledDatabaseScriptJob( | ||
| SegueScheduledJob cleanUpExpiredReservations = SegueScheduledJob.createCustomJob( | ||
| "cleanUpExpiredReservations", | ||
| CRON_GROUP_NAME_SQL_MAINTENANCE, | ||
| "SQL scheduled job that deletes expired reservations for the event booking system", | ||
| CRON_STRING_0700_DAILY, "db_scripts/scheduled/expired-reservations-clean-up.sql"); | ||
| CRON_GROUP_NAME_JAVA_JOB, | ||
| "Java scheduled job that cancels expired reservations and promotes waiting list users", | ||
| CRON_STRING_0700_DAILY, | ||
| Maps.newHashMap(), | ||
| new CancelExpiredReservationsJob() | ||
| ); | ||
|
|
||
| SegueScheduledJob deleteEventAdditionalBookingInformation = SegueScheduledJob.createCustomJob( | ||
| "deleteEventAdditionalBookingInformation", | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -408,8 +408,11 @@ private Content augmentChildContent(final Content content, final String canonica | |
|
|
||
| // hack to get cards to count as children: | ||
| if (content instanceof IsaacCardDeck) { | ||
| for (IsaacCard card : ((IsaacCardDeck) content).getCards()) { | ||
| this.augmentChildContent(card, canonicalSourceFile, newParentId, parentPublished); | ||
| IsaacCardDeck deck = (IsaacCardDeck) content; | ||
| if (deck.getCards() != null) { | ||
| for (IsaacCard card : deck.getCards()) { | ||
| this.augmentChildContent(card, canonicalSourceFile, newParentId, parentPublished); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
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 warning
Code scanning / CodeQL
Boxed variable is never null Warning
Copilot Autofix
AI 14 days ago
In general, to fix a "boxed variable is never null" issue, you should change the variable’s type from the boxed type (e.g.
Integer,Boolean) to the corresponding primitive type (int,boolean) when all assignments are from primitive expressions and there is no need to representnull. This improves clarity and avoids unnecessary boxing/unboxing.Here, we keep the method return type as
Integerbecause it legitimately may returnnullwhennumberOfPlacesisnull. We only change the local variableplacesAvailablein both branches fromIntegertoint, since its value is always derived from primitive arithmetic and is nevernull. This change is local, does not alter any method contracts, and does not require any additional imports or helper methods. Specifically:Integer placesAvailabletoint placesAvailable.Integer placesAvailabletoint placesAvailable.