You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
CIRC-2681 cap hold-shelf expiry at due day - #1717
When putting a book on hold-shelf in a reading room, the calculated expiration date of the hold can be set to after the due date of the loan, which should not be possible.
The purpose of this PR is to cap the expiration day at the due day.
If the loan is subsequently renewed, and the due date thus extended, the standard expiration date should be used (the hold date + the configured expiry period, adjusted for closing days as configured).
This only applies to reading room loans ("for use at location").
Approach
Cap the default expiration date if necessary in HoldByBarcodeResource. Extend a capped expiration date if necessary in RenewalResource.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Unresolved hold-expiration defects can incorrectly extend holds, block renewals when no expiry period is configured, and turn expected validation or lookup failures into HTTP 500 errors.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Renewal recalculates shelf expiry from the current time instead of the original hold date, incorrectly extending the hold period even for holds that were never capped.
Renewal restarts the shelf-expiry period because the shared calculator uses the current time rather than the original hold date, extending even holds that were never capped. Pass the persisted forUseAtLocation.statusDate as the calculation base on renewal, retaining the current time for newly placed holds. Advance the mocked clock before renewal in the regression test so it detects this drift.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Inconsistent timestamps can restore expiration a day late when a calendar lookup crosses tenant midnight, while the test’s extra renewal leaves first-renewal restoration unverified.
The initial expiration uses a timestamp captured before the calendar lookup, but Loan.changeStatusOfUsageAtLocation records a fresh statusDate afterward. If the lookup crosses tenant midnight, renewal uses the later date and can restore an expiration a day beyond the original standard expiration. Persist and reuse the same captured hold timestamp for both calculations, and add a regression test that advances the clock across midnight during the lookup.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because a critical renewal error-handling path can turn calendar failures into unhandled exceptions, leaving requests without an HTTP response.
Expiry in the past: Expiry can land in the past. If the loan is already overdue when it goes on hold, the cap sets the expiry before the hold date. Either clamp it to max(cap, hold date), document that behavior, and add a test.
Uncapped due-date changes: Other due-date changes aren’t re-capped. ChangeDueDateResource and recall shortening can pull the due date earlier than the stored expiry. This may be out of scope, so check it against the ticket.
Renewal failure on service-point lookup: Renewal can now fail on a service-point lookup. The new getServicePointById(loan.getCheckoutServicePointId()) call in RenewalResource.java (~245-262) runs inside the renewal. If that service point is missing, a held use-at-location loan can’t be renewed. It should log and leave the stored expiry alone instead.
🟡 Minor
Null handling / Potential NPE:calculateExpirationDateForUseAtLocation returns completedFuture(null) when the expiry is null. No current caller reaches that branch, but it would throw an NPE if chained.
Redundant check: The !expiration.equals(currentExpiration) guard in RenewalResource is redundant.
Styling and async consistency: The new block in RenewalResource has odd indentation and spacing (context,servicePointRepository) and uses thenCompose where neighboring code uses thenComposeAsync.
Legacy data NPE risk: A held loan with no statusDate (legacy data) would NPE on renewal.
Test assertion weakness:willCapHoldShelfExpirationAtDueDateButReadjustAtRenewal never asserts which day the due date is, so it only discriminates if the due date isn’t the 31st.
* **Expiry in the past:** Expiry can land in the past. If the loan is already overdue when it goes on hold, the cap sets the expiry before the hold date. Either clamp it to `max(cap, hold date)`, document that behavior, and add a test.
In known real life reading room procedures, the expiry cannot land in the past. The reason is that overdue reading room loans are closed by the librarian (i.e. by the end of the day) after which the books are returned from the reading room shelf. Thus, an overdue loan cannot subsequently (i.e. next day) be picked up by the patron and therefore cannot be put on hold.
We can of course speculate that something went wrong and the overdue loan was not closed (or renewed) as it should be, and that the patron somehow managed to pick it up in the reading room even so, and subsequently also got it held. It has not been a requirement so far to technically prevent this scenario, so the librarian would need to resolve it somehow if it ever occurred. But it should not be resolved by pretending that the patron is supposed to be able to keep the item on hold into any date in the future. If anything, having the date in the past would be a better indication of a problem.
* **Uncapped due-date changes:** Other due-date changes aren’t re-capped. `ChangeDueDateResource` and recall shortening can pull the due date earlier than the stored expiry. This may be out of scope, so check it against the ticket.
We checked the ticket as preparation for the work. It only deals with renewals. We are aware of other due date change scenarios and might discuss with the sponsor (NLS)
* **Renewal failure on service-point lookup:** Renewal can now fail on a service-point lookup. The new `getServicePointById(loan.getCheckoutServicePointId())` call in `RenewalResource.java` (~245-262) runs inside the renewal. If that service point is missing, a held use-at-location loan can’t be renewed. It should log and leave the stored expiry alone instead.
Addressed.
🟡 Minor
* **Null handling / Potential NPE:** `calculateExpirationDateForUseAtLocation` returns `completedFuture(null)` when the expiry is null. No current caller reaches that branch, but it would throw an NPE if chained.
Addressed.
* **Redundant check:** The `!expiration.equals(currentExpiration)` guard in `RenewalResource` is redundant.
The redundant null check is remove. The equals check serves the purpose of not repeatedly updating a property with the value it already holds (best practice when possible I'd say).
* **Styling and async consistency:** The new block in `RenewalResource` has odd indentation and spacing (`context,servicePointRepository`) and uses `thenCompose` where neighboring code uses `thenComposeAsync`.
Addressed.
* **Legacy data NPE risk:** A held loan with no `statusDate` (legacy data) would NPE on renewal.
Addressed.
* **Test assertion weakness:** `willCapHoldShelfExpirationAtDueDateButReadjustAtRenewal` never asserts which day the due date is, so it only discriminates if the due date isn’t the 31st.
* **Test gaps:** Missing test cases for:
* A hold that needs no cap
* An overdue loan
* Renewing a non-held loan
* A policy with no hold-shelf expiry period
Tests and asserts added (though not for overdue loan ref. comments in top).
Also added an entry in NEWS, but see that the request for that was subsequently removed from the review. I remove the entry again?
Regarding the NEWS entry, please keep it. I had removed that requirement thinking it wasn't necessary, but it's definitely better to have it in. Thanks for adding it!
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
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.
-- with for-use-at-location
Purpose
When putting a book on hold-shelf in a reading room, the calculated expiration date of the hold can be set to after the due date of the loan, which should not be possible.
The purpose of this PR is to cap the expiration day at the due day.
If the loan is subsequently renewed, and the due date thus extended, the standard expiration date should be used (the hold date + the configured expiry period, adjusted for closing days as configured).
This only applies to reading room loans ("for use at location").
Approach
Cap the default expiration date if necessary in HoldByBarcodeResource. Extend a capped expiration date if necessary in RenewalResource.