Skip to content

Commit

Permalink
Circ 1984 - set reminderFee as loan action (#1404)
Browse files Browse the repository at this point in the history
* CIRC-1984 - Loan details record. Action for reminder fees are labelled as Checked out.

* Tweak to deduplicate CIRC-1984

* Expand import .* CIRC-1984

* Review obs CIRC-1984

---------

Co-authored-by: edijstimuls <[email protected]>
  • Loading branch information
nielserik and edijstimuls authored Dec 19, 2023
1 parent 2cb412c commit dac5819
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
13 changes: 9 additions & 4 deletions src/main/java/org/folio/circulation/domain/Loan.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ public void changeAction(String action) {
write(representation, LoanProperties.ACTION, action);
}

public Loan withAction(LoanAction action) {
changeAction(action);
return this;
}

public String getAction() {
return getProperty(representation, ACTION);
}
Expand Down Expand Up @@ -645,11 +650,11 @@ public Loan withIncrementedRemindersLastFeeBilled(ZonedDateTime date) {
}

public Loan withRemindersLastFeeBilled(int number, ZonedDateTime date) {
JsonObject lastFeeBilled = getNestedObjectProperty(representation,REMINDERS,LAST_FEE_BILLED);
JsonObject lastFeeBilled = getNestedObjectProperty(representation, REMINDERS, LAST_FEE_BILLED);
if (lastFeeBilled == null) {
write(representation,REMINDERS,new JsonObject());
write(representation.getJsonObject(REMINDERS),LAST_FEE_BILLED,new JsonObject());
lastFeeBilled = getNestedObjectProperty(representation,REMINDERS,LAST_FEE_BILLED);
write(representation, REMINDERS, new JsonObject());
write(representation.getJsonObject(REMINDERS), LAST_FEE_BILLED, new JsonObject());
lastFeeBilled = getNestedObjectProperty(representation, REMINDERS, LAST_FEE_BILLED);
}
write(lastFeeBilled, BILL_DATE, date);
write(lastFeeBilled, BILL_NUMBER, number);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/folio/circulation/domain/LoanAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ public enum LoanAction {
PATRON_INFO_ADDED("patronInfoAdded"),
STAFF_INFO_ADDED("staffInfoAdded"),
RESOLVE_CLAIM_AS_RETURNED_BY_PATRON("checkedInReturnedByPatron"),
RESOLVE_CLAIM_AS_FOUND_BY_LIBRARY("checkedInFoundByLibrary");
RESOLVE_CLAIM_AS_FOUND_BY_LIBRARY("checkedInFoundByLibrary"),

REMINDER_FEE("reminderFee");

private final String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.folio.circulation.domain.FeeFineOwner;
import org.folio.circulation.domain.Item;
import org.folio.circulation.domain.Loan;
import org.folio.circulation.domain.LoanAction;
import org.folio.circulation.domain.policy.RemindersPolicy;
import org.folio.circulation.infrastructure.storage.CalendarRepository;
import org.folio.circulation.infrastructure.storage.ConfigurationRepository;
Expand Down Expand Up @@ -159,7 +160,9 @@ private CompletableFuture<Result<ScheduledNoticeContext>> updateLoan(ScheduledNo
}

return loanRepository.updateLoan(
context.getLoan().withIncrementedRemindersLastFeeBilled(systemTime))
context.getLoan()
.withIncrementedRemindersLastFeeBilled(systemTime)
.withAction(LoanAction.REMINDER_FEE))
.thenApply(r -> r.map(v -> context));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,10 @@ public CompletableFuture<Result<LoanAndRelatedRecords>> updateLoan(

public CompletableFuture<Result<Loan>> updateLoan(Loan loan) {
log.debug("updateLoan:: parameters loan: {}", loan);
if(loan == null) {
if (loan == null) {
log.info("updateLoan:: loan is null");
return completedFuture(of(() -> null));
}

JsonObject storageLoan = mapToStorageRepresentation(loan, loan.getItem());

return loansStorageClient.put(loan.getId(), storageLoan)
Expand Down
21 changes: 18 additions & 3 deletions src/test/java/api/loans/ReminderFeeTests.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package api.loans;

import api.support.APITests;
import api.support.builders.*;
import api.support.builders.CheckOutByBarcodeRequestBuilder;
import api.support.builders.FeeFineOwnerBuilder;
import api.support.builders.HoldingBuilder;
import api.support.builders.ItemBuilder;
import api.support.http.IndividualResource;
import api.support.http.ItemResource;
import api.support.http.UserResource;
import io.vertx.core.json.JsonObject;
import org.folio.circulation.domain.LoanAction;
import org.folio.circulation.support.utils.DateFormatUtil;
import org.hamcrest.core.Is;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -15,13 +20,15 @@
import java.util.Collections;
import java.util.UUID;

import static api.support.fixtures.CalendarExamples.*;
import static api.support.fixtures.CalendarExamples.CASE_FIRST_DAY_CLOSED_FOLLOWING_OPEN;
import static api.support.fixtures.CalendarExamples.FIRST_DAY;
import static api.support.fixtures.ItemExamples.basedUponSmallAngryPlanet;
import static api.support.utl.PatronNoticeTestHelper.*;
import static java.time.ZoneOffset.UTC;
import static java.util.concurrent.TimeUnit.DAYS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.awaitility.Awaitility.waitAtMost;
import static org.folio.circulation.domain.representations.LoanProperties.ACTION;
import static org.folio.circulation.domain.representations.logs.LogEventType.NOTICE;
import static org.folio.circulation.domain.representations.logs.LogEventType.NOTICE_ERROR;
import static org.folio.circulation.support.utils.ClockUtil.getZonedDateTime;
Expand Down Expand Up @@ -139,7 +146,11 @@ void willProcessRemindersAllDaysOpenAllowOnClosed() {
.to(borrower)
.on(loanDate)
.at(servicePointsFixture.cd1()));
final JsonObject loan = response.getJson();
JsonObject loan = response.getJson();

// Assert that loan action is Checked out initially
assertThat(loan.getString(ACTION), Is.is(LoanAction.CHECKED_OUT.getValue()));

ZonedDateTime dueDate = DateFormatUtil.parseDateTime(loan.getString("dueDate"));

waitAtMost(1, SECONDS).until(scheduledNoticesClient::getAll, hasSize(1));
Expand Down Expand Up @@ -222,6 +233,10 @@ void willProcessRemindersAllDaysOpenAllowOnClosed() {
verifyNumberOfPublishedEvents(NOTICE, 3);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
waitAtMost(1, SECONDS).until(accountsClient::getAll, hasSize(2));

// Assert that loan action is changed to Reminder fee after sending reminders
loan = loansFixture.getLoanById(response.getId()).getJson();
assertThat(loan.getString(ACTION), Is.is(LoanAction.REMINDER_FEE.getValue()));
}

@Test
Expand Down

0 comments on commit dac5819

Please sign in to comment.