Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into CIRC-1933
Browse files Browse the repository at this point in the history
  • Loading branch information
OleksandrVidinieiev committed Dec 20, 2023
2 parents 13ee6fb + dac5819 commit 8ef15f5
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 197 deletions.
196 changes: 16 additions & 180 deletions src/main/java/org/folio/circulation/domain/CheckInContext.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.folio.circulation.domain;

import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Optional;
import java.util.UUID;
Expand All @@ -9,7 +10,9 @@
import org.folio.circulation.support.utils.ClockUtil;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;
import lombok.With;

/**
* The loan captures a snapshot of the item status
Expand All @@ -21,6 +24,8 @@
*
* Which requires passing the records between processes.
*/
@With
@Getter
@AllArgsConstructor
@ToString(onlyExplicitlyIncluded = true)
public class CheckInContext {
Expand All @@ -37,156 +42,26 @@ public class CheckInContext {
private final ZonedDateTime checkInProcessedDateTime;
private final boolean inHouseUse;
private final ItemStatus itemStatusBeforeCheckIn;
private final ZoneId timeZone;

public CheckInContext(CheckInByBarcodeRequest checkInRequest) {
this(checkInRequest, null, null, null, null, null, null, null,
ClockUtil.getZonedDateTime(), false, null);
ClockUtil.getZonedDateTime(), false, null, null);
}

public CheckInContext withTlrSettings(TlrSettingsConfiguration tlrSettingsConfiguration) {
return new CheckInContext(
this.checkInRequest,
tlrSettingsConfiguration,
this.item,
this.loan,
this.requestQueue,
this.checkInServicePoint,
this.highestPriorityFulfillableRequest,
this.loggedInUserId,
this.checkInProcessedDateTime,
this.inHouseUse,
this.itemStatusBeforeCheckIn);
}

public CheckInContext withItem(Item item) {

//When the item is updated, also update the item for the loan,
//as they should be the same
/**
* Updates the item in the check-in context.
* Also updates the item for the loan, as they should be the same.
* @param item the item to put into the check-in context
* @return new CheckInContext with an updated item and loan
*/
public CheckInContext withItemAndUpdatedLoan(Item item) {
final Loan updatedLoan = Optional.ofNullable(loan)
.map(l -> l.withItem(item))
.orElse(null);

return new CheckInContext(
this.checkInRequest,
this.tlrSettings,
item,
updatedLoan,
this.requestQueue,
this.checkInServicePoint,
this.highestPriorityFulfillableRequest,
this.loggedInUserId,
this.checkInProcessedDateTime,
this.inHouseUse,
this.itemStatusBeforeCheckIn);
}

public CheckInContext withLoan(Loan loan) {
return new CheckInContext(
this.checkInRequest,
this.tlrSettings,
this.item,
loan,
this.requestQueue,
this.checkInServicePoint,
this.highestPriorityFulfillableRequest,
this.loggedInUserId,
this.checkInProcessedDateTime,
this.inHouseUse,
this.itemStatusBeforeCheckIn);
}

public CheckInContext withRequestQueue(RequestQueue requestQueue) {
return new CheckInContext(
this.checkInRequest,
this.tlrSettings,
this.item,
this.loan,
requestQueue,
this.checkInServicePoint,
null, // needs to be reset when requestQueue is updated
this.loggedInUserId,
this.checkInProcessedDateTime,
this.inHouseUse,
this.itemStatusBeforeCheckIn);
}

public CheckInContext withCheckInServicePoint(ServicePoint checkInServicePoint) {
return new CheckInContext(
this.checkInRequest,
this.tlrSettings,
this.item,
this.loan,
this.requestQueue,
checkInServicePoint,
this.highestPriorityFulfillableRequest,
this.loggedInUserId,
this.checkInProcessedDateTime,
this.inHouseUse,
this.itemStatusBeforeCheckIn);
}

public CheckInContext withHighestPriorityFulfillableRequest(Request request) {
return new CheckInContext(
this.checkInRequest,
this.tlrSettings,
this.item,
this.loan,
this.requestQueue,
this.checkInServicePoint,
request,
loggedInUserId,
this.checkInProcessedDateTime,
this.inHouseUse,
this.itemStatusBeforeCheckIn);
}

public CheckInContext withLoggedInUserId(String userId) {
return new CheckInContext(
this.checkInRequest,
this.tlrSettings,
this.item,
this.loan,
this.requestQueue,
this.checkInServicePoint,
this.highestPriorityFulfillableRequest,
userId,
this.checkInProcessedDateTime,
this.inHouseUse,
this.itemStatusBeforeCheckIn);
}

public CheckInContext withInHouseUse(boolean inHouseUse) {
return new CheckInContext(
this.checkInRequest,
this.tlrSettings,
this.item,
this.loan,
this.requestQueue,
this.checkInServicePoint,
this.highestPriorityFulfillableRequest,
this.loggedInUserId,
this.checkInProcessedDateTime,
inHouseUse,
this.itemStatusBeforeCheckIn);
}

public CheckInContext withItemStatusBeforeCheckIn(ItemStatus itemStatus) {
return new CheckInContext(
this.checkInRequest,
this.tlrSettings,
this.item,
this.loan,
this.requestQueue,
this.checkInServicePoint,
this.highestPriorityFulfillableRequest,
this.loggedInUserId,
this.checkInProcessedDateTime,
this.inHouseUse,
itemStatus);
}

public boolean isInHouseUse() {
return inHouseUse;
return withItem(item)
.withLoan(updatedLoan);
}

public String getCheckInRequestBarcode() {
Expand All @@ -201,43 +76,4 @@ public UUID getSessionId() {
return checkInRequest.getSessionId();
}

public TlrSettingsConfiguration getTlrSettings() {
return tlrSettings;
}

public Item getItem() {
return item;
}

public Loan getLoan() {
return loan;
}

public CheckInByBarcodeRequest getCheckInRequest() {
return checkInRequest;
}

public RequestQueue getRequestQueue() {
return requestQueue;
}

public ServicePoint getCheckInServicePoint() {
return checkInServicePoint;
}

public Request getHighestPriorityFulfillableRequest() {
return highestPriorityFulfillableRequest;
}

public String getLoggedInUserId() {
return loggedInUserId;
}

public ZonedDateTime getCheckInProcessedDateTime() {
return checkInProcessedDateTime;
}

public ItemStatus getItemStatusBeforeCheckIn() {
return itemStatusBeforeCheckIn;
}
}
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 @@ -10,6 +10,7 @@
import static org.folio.circulation.support.utils.LogUtil.listAsString;

import java.lang.invoke.MethodHandles;
import java.time.ZoneId;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -137,17 +138,17 @@ private static void populateItemData(LoanAndRelatedRecords loanAndRelatedRecords

private static void populateLoanData(CheckInContext checkInContext, JsonObject logEventPayload, User userFromLastLoan) {
if (nonNull(checkInContext.getLoan())) {
populateLoanData(checkInContext.getLoan(), logEventPayload);
populateLoanData(checkInContext.getLoan(), logEventPayload, checkInContext.getTimeZone());
} else {
enrichWithUserBarcode(logEventPayload, userFromLastLoan);
}
}

private static void populateLoanData(LoanAndRelatedRecords loanAndRelatedRecords, JsonObject logEventPayload) {
populateLoanData(loanAndRelatedRecords.getLoan(), logEventPayload);
populateLoanData(loanAndRelatedRecords.getLoan(), logEventPayload, loanAndRelatedRecords.getTimeZone());
}

private static void populateLoanData(Loan checkInCheckOutLoan, JsonObject logEventPayload) {
private static void populateLoanData(Loan checkInCheckOutLoan, JsonObject logEventPayload, ZoneId zoneId) {
log.debug("populateLoanData:: parameters checkInCheckOutLoan: {}, logEventPayload: {}",
checkInCheckOutLoan, logEventPayload);

Expand All @@ -156,6 +157,7 @@ private static void populateLoanData(Loan checkInCheckOutLoan, JsonObject logEve
write(logEventPayload, SYSTEM_RETURN_DATE.value(), checkInCheckOutLoan.getSystemReturnDate());
write(logEventPayload, RETURN_DATE.value(), checkInCheckOutLoan.getReturnDate());
write(logEventPayload, DUE_DATE.value(), checkInCheckOutLoan.getDueDate());
write(logEventPayload, ZONE_ID.value(), zoneId.getId());
ofNullable(checkInCheckOutLoan.getUser())
.ifPresent(user -> {
write(logEventPayload, USER_ID.value(), user.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public enum LogEventPayloadField {
SYSTEM_RETURN_DATE("systemReturnDate"),
RETURN_DATE("returnDate"),
DUE_DATE("dueDate"),
ZONE_ID("zoneId"),
USER_ID("userId"),
USER_BARCODE("userBarcode"),
PROXY_BARCODE("proxyBarcode"),
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
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,14 @@ private void checkIn(RoutingContext routingContext) {
.next(notUsed -> checkInRequestResult)
.map(CheckInContext::new)
.combineAfter(processAdapter::findItem, (records, item) -> records
.withItem(item)
.withItemAndUpdatedLoan(item)
.withItemStatusBeforeCheckIn(item.getStatus()))
.thenApply(checkInValidators::refuseWhenItemIsNotAllowedForCheckIn)
.thenApply(checkInValidators::refuseWhenClaimedReturnedIsNotResolved)
.thenComposeAsync(r -> r.combineAfter(configurationRepository::lookupTlrSettings,
CheckInContext::withTlrSettings))
.thenComposeAsync(r -> r.combineAfter(configurationRepository::findTimeZoneConfiguration,
CheckInContext::withTimeZone))
.thenComposeAsync(findItemResult -> findItemResult.combineAfter(
processAdapter::getRequestQueue, CheckInContext::withRequestQueue))
.thenComposeAsync(r -> r.after(processAdapter::findFulfillableRequest))
Expand All @@ -104,11 +106,11 @@ private void checkIn(RoutingContext routingContext) {
processAdapter::updateRequestQueue, CheckInContext::withRequestQueue))
.thenComposeAsync(r -> r.after(processAdapter::findFulfillableRequest))
.thenComposeAsync(updateRequestQueueResult -> updateRequestQueueResult.combineAfter(
processAdapter::updateItem, CheckInContext::withItem))
processAdapter::updateItem, CheckInContext::withItemAndUpdatedLoan))
.thenApply(handleItemStatus -> handleItemStatus.next(
requestNoticeSender::sendNoticeOnRequestAwaitingPickup))
.thenComposeAsync(updateItemResult -> updateItemResult.combineAfter(
processAdapter::getDestinationServicePoint, CheckInContext::withItem))
processAdapter::getDestinationServicePoint, CheckInContext::withItemAndUpdatedLoan))
.thenComposeAsync(updateItemResult -> updateItemResult.combineAfter(
processAdapter::getCheckInServicePoint, CheckInContext::withCheckInServicePoint))
.thenComposeAsync(updateItemResult -> updateItemResult.combineAfter(
Expand Down
Loading

0 comments on commit 8ef15f5

Please sign in to comment.