Skip to content

Commit

Permalink
Merge pull request #58 from indexdata/CIRC-2019
Browse files Browse the repository at this point in the history
Circ 2019
  • Loading branch information
nielserik authored Apr 19, 2024
2 parents 9d70230 + bc28ec2 commit 16718b2
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 17 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 24.2.1 2024-03-29

* Fix item details not fully populated when response contains more than 50 loans (CIRC-2059)

## 24.2.0 2024-03-21

* Update `feesfines` interface version to 19.0 (CIRC-1914)
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>mod-circulation</artifactId>
<groupId>org.folio</groupId>
<version>24.3.0-SNAPSHOT</version>
<version>24.2.2-SNAPSHOT</version>
<licenses>
<license>
<name>Apache License 2.0</name>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/folio/circulation/domain/Loan.java
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ public Loan overrideRenewal(ZonedDateTime dueDate, String basedUponLoanPolicyId,
changeDueDate(dueDate);
incrementRenewalCount();
changeActionComment(actionComment);
resetReminders();

return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package org.folio.circulation.domain;

import static java.util.Objects.isNull;
import static org.folio.circulation.domain.representations.LoanProperties.BORROWER;
import static org.folio.circulation.domain.representations.LoanProperties.LOAN_POLICY;
import static org.folio.circulation.domain.representations.LoanProperties.LOST_ITEM_POLICY;
import static org.folio.circulation.domain.representations.LoanProperties.OVERDUE_FINE_POLICY;
import static org.folio.circulation.domain.representations.LoanProperties.PATRON_GROUP_ID_AT_CHECKOUT;
import static org.folio.circulation.domain.representations.LoanProperties.*;
import static org.folio.circulation.support.json.JsonPropertyWriter.write;

import java.lang.invoke.MethodHandles;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.folio.circulation.domain.policy.Policy;
import org.folio.circulation.domain.policy.RemindersPolicy;
import org.folio.circulation.domain.representations.ItemSummaryRepresentation;
import org.folio.circulation.domain.representations.LoanProperties;
import org.folio.circulation.resources.context.RenewalContext;
Expand Down Expand Up @@ -59,6 +56,13 @@ public JsonObject extendedLoan(Loan loan) {
extendedRepresentation.remove(BORROWER);
}

if (loan.getOverdueFinePolicy().isReminderFeesPolicy()
&& loan.getLastReminderFeeBilledNumber() != null) {
extendedRepresentation.getJsonObject(REMINDERS).put(
"renewalBlocked",
!loan.getOverdueFinePolicy().getRemindersPolicy().getAllowRenewalOfItemsWithReminderFees());
}

addPolicy(extendedRepresentation, loan.getLoanPolicy(), LOAN_POLICY);
addPolicy(extendedRepresentation, loan.getOverdueFinePolicy(), OVERDUE_FINE_POLICY);
addPolicy(extendedRepresentation, loan.getLostItemPolicy(), LOST_ITEM_POLICY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.folio.circulation.domain.Loan;
import org.folio.circulation.domain.override.BlockOverrides;
import org.folio.circulation.domain.policy.OverdueFinePolicy;
import org.folio.circulation.resources.context.RenewalContext;
import org.folio.circulation.support.HttpFailure;
Expand All @@ -14,6 +15,7 @@

import static java.util.concurrent.CompletableFuture.completedFuture;
import static org.folio.circulation.support.ValidationErrorFailure.singleValidationError;
import static org.folio.circulation.support.json.JsonPropertyFetcher.getObjectProperty;
import static org.folio.circulation.support.results.Result.failed;
import static org.folio.circulation.support.results.Result.succeeded;

Expand All @@ -27,13 +29,12 @@ public CompletableFuture<Result<RenewalContext>> blockRenewalIfReminderFeesExist

Result<RenewalContext> blockRenewalIfRuledByRemindersFeePolicy(RenewalContext renewalContext) {
log.debug("blockRenewalIfRuledByRemindersFeePolicy:: parameters: renewalContext: {}", renewalContext);

Loan loan = renewalContext.getLoan();
Integer lastFeeBilledCount = loan.getLastReminderFeeBilledNumber();
OverdueFinePolicy overdueFinePolicy = loan.getOverdueFinePolicy();
Boolean allowRenewalWithReminders = overdueFinePolicy.getRemindersPolicy().getAllowRenewalOfItemsWithReminderFees();

if ((lastFeeBilledCount != null && lastFeeBilledCount > 0) && Boolean.FALSE.equals(allowRenewalWithReminders)) {
BlockOverrides overrides = BlockOverrides.from(getObjectProperty(renewalContext.getRenewalRequest(), "overrideBlocks"));
final boolean overrideRenewalBlock = overrides.getRenewalBlockOverride().isRequested();
final boolean overrideRenewalBlockDueDateRequired = overrides.getRenewalDueDateRequiredBlockOverride().isRequested();
if (overrideRenewalBlock || overrideRenewalBlockDueDateRequired) {
return succeeded(renewalContext);
} else if (renewalBlockedDueToReminders(renewalContext)) {
String reason = "Renewals not allowed for loans with reminders.";
log.info("createBlockedRenewalDueToReminderFeesPolicyError:: {}", reason);
return failed(createBlockedRenewalDueToReminderFeesPolicyError("Renewals not allowed for loans with reminders.", reason));
Expand All @@ -48,4 +49,19 @@ private HttpFailure createBlockedRenewalDueToReminderFeesPolicyError(String mess

return singleValidationError(new ValidationError(message, "reason", reason));
}

private static boolean renewalBlockedDueToReminders(RenewalContext renewalContext) {
Loan loan = renewalContext.getLoan();
return loanHasReminders(loan) && policyBlocksRenewalWithReminders(loan);
}

private static Boolean loanHasReminders(Loan loan) {
return loan.getLastReminderFeeBilledNumber() != null && loan.getLastReminderFeeBilledNumber() > 0;
}

private static boolean policyBlocksRenewalWithReminders (Loan loan) {
OverdueFinePolicy overdueFinePolicy = loan.getOverdueFinePolicy();
Boolean allowRenewalWithReminders = overdueFinePolicy.getRemindersPolicy().getAllowRenewalOfItemsWithReminderFees();
return Boolean.FALSE.equals(allowRenewalWithReminders);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ public static ValidationError errorForNotMatchingOverrideCases(LoanPolicy loanPo
"renewal date falls outside of the date ranges in the loan policy, " +
"items cannot be renewed when there is an active recall request, " +
DECLARED_LOST_ITEM_RENEWED_ERROR + ", item is Aged to lost, " +
"renewal would not change the due date";
"renewal would not change the due date, " +
"loan has reminder fees";

return loanPolicyValidationError(loanPolicy, reason);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,10 @@ private Result<Loan> overrideRenewal(Loan loan, ZonedDateTime systemDate,
return processRenewal(newDueDateResult, loan, comment);
}

if (loan.getLastReminderFeeBilledNumber() != null && loan.getLastReminderFeeBilledNumber()>0) {
return processRenewal(newDueDateResult, loan, comment);
}

return failedValidation(errorForNotMatchingOverrideCases(loanPolicy));

} catch (Exception e) {
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/api/loans/OverrideRenewByBarcodeTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,8 @@ void cannotOverrideRenewalWhenLoanDoesNotMatchAnyOfOverrideCases() {
"renewal date falls outside of the date ranges in the loan policy, " +
"items cannot be renewed when there is an active recall request, " +
"item is Declared lost, item is Aged to lost, " +
"renewal would not change the due date"))));
"renewal would not change the due date, " +
"loan has reminder fees"))));
}

@Test
Expand Down
6 changes: 4 additions & 2 deletions src/test/java/api/requests/RequestsAPILoanRenewalTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,8 @@ void forbidRenewalOverrideWhenRecallIsForDifferentItemOfSameInstance() {
"renewal date falls outside of the date ranges in the loan policy, " +
"items cannot be renewed when there is an active recall request, " +
"item is Declared lost, item is Aged to lost, " +
"renewal would not change the due date"))));
"renewal would not change the due date, " +
"loan has reminder fees"))));
}

@Test
Expand Down Expand Up @@ -623,7 +624,8 @@ void forbidRenewalOverrideWhenTitleLevelRecallRequestExistsForDifferentItemOfSam
"renewal date falls outside of the date ranges in the loan policy, " +
"items cannot be renewed when there is an active recall request, " +
"item is Declared lost, item is Aged to lost, " +
"renewal would not change the due date"))));
"renewal would not change the due date, " +
"loan has reminder fees"))));
}

@Test
Expand Down

0 comments on commit 16718b2

Please sign in to comment.