From 93ca94e40e5b331ae3dd8ddd551fb074678a4f15 Mon Sep 17 00:00:00 2001 From: Alexander Kurash Date: Wed, 25 Oct 2023 13:09:11 +0300 Subject: [PATCH] CIRC-1942 - Revert CIRC-1793 (Add the field loan.additionalInfo) (#1351) * Revert "CIRC-1793 Add the field "loan.additionalInfo" to the Loan Object in the Notice context (#1332)" This reverts commit 794e6878 * CIRC-1942 Remove unused method (cherry picked from commit f6cab56ee7c101be75176e2b6d3c440631d2c35d) --- descriptors/ModuleDescriptor-template.json | 36 +++++-------- .../org/folio/circulation/domain/Loan.java | 33 +++++------- .../folio/circulation/domain/LoanHistory.java | 29 ---------- .../domain/notice/TemplateContextUtil.java | 2 - .../FeeFineScheduledNoticeHandler.java | 1 - .../schedule/LoanScheduledNoticeHandler.java | 2 +- .../RequestScheduledNoticeHandler.java | 9 ---- .../session/PatronActionSessionService.java | 25 ++------- .../storage/loans/LoanHistoryRepository.java | 53 ------------------- .../storage/loans/LoanRepository.java | 23 -------- .../resources/ChangeDueDateResource.java | 2 +- .../resources/CheckInByBarcodeResource.java | 2 +- .../resources/CheckOutByBarcodeResource.java | 2 +- .../EndPatronActionSessionResource.java | 2 +- .../ExpiredSessionProcessingResource.java | 2 +- .../resources/LoanCollectionResource.java | 2 +- .../resources/LoanNoticeSender.java | 10 ++-- .../resources/RequestNoticeSender.java | 25 ++------- .../resources/renewal/RenewalResource.java | 2 +- .../folio/circulation/support/Clients.java | 13 ----- 20 files changed, 44 insertions(+), 231 deletions(-) delete mode 100644 src/main/java/org/folio/circulation/domain/LoanHistory.java delete mode 100644 src/main/java/org/folio/circulation/infrastructure/storage/loans/LoanHistoryRepository.java diff --git a/descriptors/ModuleDescriptor-template.json b/descriptors/ModuleDescriptor-template.json index f81ac5111f..1578880be3 100644 --- a/descriptors/ModuleDescriptor-template.json +++ b/descriptors/ModuleDescriptor-template.json @@ -623,8 +623,7 @@ "circulation-storage.patron-notice-policies.item.get", "patron-notice.post", "patron-action-session-storage.patron-action-sessions.item.delete", - "pubsub.publish.post", - "circulation-storage.loans-history.collection.get" + "pubsub.publish.post" ] } ] @@ -882,8 +881,7 @@ "users.collection.get", "addresstypes.collection.get", "pubsub.publish.post", - "templates.item.get", - "circulation-storage.loans-history.collection.get" + "templates.item.get" ], "unit": "minute", "delay": "2" @@ -956,8 +954,7 @@ "anonymize-storage-loans.post", "accounts.collection.get", "feefineactions.collection.get", - "pubsub.publish.post", - "circulation-storage.loans-history.collection.get" + "pubsub.publish.post" ], "unit": "minute", "delay": "60" @@ -1640,8 +1637,7 @@ "patron-notice.post", "configuration.entries.collection.get", "calendar.endpoint.dates.get", - "pubsub.publish.post", - "circulation-storage.loans-history.collection.get" + "pubsub.publish.post" ], "visible": false }, @@ -1750,8 +1746,7 @@ "actual-cost-record-storage.actual-cost-records.item.get", "actual-cost-fee-fine-cancel.post", "departments.item.get", - "departments.collection.get", - "circulation-storage.loans-history.collection.get" + "departments.collection.get" ], "visible": false }, @@ -1803,8 +1798,7 @@ "manualblocks.item.get", "actual-cost-record-storage.actual-cost-records.collection.get", "actual-cost-record-storage.actual-cost-records.item.get", - "actual-cost-fee-fine-cancel.post", - "circulation-storage.loans-history.collection.get" + "actual-cost-fee-fine-cancel.post" ], "visible": false }, @@ -1840,8 +1834,7 @@ "patron-notice.post", "anonymize-storage-loans.post", "feefineactions.collection.get", - "pubsub.publish.post", - "circulation-storage.loans-history.collection.get" + "pubsub.publish.post" ], "visible": false }, @@ -1969,8 +1962,7 @@ "configuration.entries.collection.get", "manualblocks.collection.get", "pubsub.publish.post", - "automated-patron-blocks.collection.get", - "circulation-storage.loans-history.collection.get" + "automated-patron-blocks.collection.get" ], "visible": false }, @@ -2049,8 +2041,7 @@ "scheduled-notice-storage.scheduled-notices.item.post", "pubsub.publish.post", "manualblocks.collection.get", - "automated-patron-blocks.collection.get", - "circulation-storage.loans-history.collection.get" + "automated-patron-blocks.collection.get" ], "visible": false }, @@ -2128,8 +2119,7 @@ "manualblocks.collection.get", "automated-patron-blocks.collection.get", "pubsub.publish.post", - "circulation-storage.fixed-due-date-schedules.collection.get", - "circulation-storage.loans-history.collection.get" + "circulation-storage.fixed-due-date-schedules.collection.get" ], "visible": false }, @@ -2180,8 +2170,7 @@ "users.item.get", "addresstypes.collection.get", "pubsub.publish.post", - "patron-notice.post", - "circulation-storage.loans-history.collection.get" + "patron-notice.post" ], "visible": false }, @@ -2264,8 +2253,7 @@ "scheduled-notice-storage.scheduled-notices.item.post", "pubsub.publish.post", "configuration.entries.collection.get", - "patron-notice.post", - "circulation-storage.loans-history.collection.get" + "patron-notice.post" ], "visible": false }, diff --git a/src/main/java/org/folio/circulation/domain/Loan.java b/src/main/java/org/folio/circulation/domain/Loan.java index 6b6282661c..317d8ed3cd 100644 --- a/src/main/java/org/folio/circulation/domain/Loan.java +++ b/src/main/java/org/folio/circulation/domain/Loan.java @@ -112,8 +112,6 @@ public class Loan implements ItemRelatedRecord, UserRelatedRecord { @Getter private boolean dueDateChangedByNearExpireUser; - @Getter - private final String latestPatronInfoAddedComment; public static Loan from(JsonObject representation) { defaultStatusAndAction(representation); @@ -126,7 +124,7 @@ public static Loan from(JsonObject representation) { return new Loan(representation, null, null, null, null, null, getDateTimeProperty(representation, DUE_DATE), getDateTimeProperty(representation, DUE_DATE), - new Policies(loanPolicy, overdueFinePolicy, lostItemPolicy), emptyList(), null, false, false, null); + new Policies(loanPolicy, overdueFinePolicy, lostItemPolicy), emptyList(), null, false, false); } public JsonObject asJson() { @@ -313,7 +311,7 @@ public Item getItem() { public Loan replaceRepresentation(JsonObject newRepresentation) { return new Loan(newRepresentation, item, user, proxy, checkinServicePoint, - checkoutServicePoint, originalDueDate, previousDueDate, policies, accounts, actualCostRecord,dueDateChangedByHold, dueDateChangedByNearExpireUser, latestPatronInfoAddedComment); + checkoutServicePoint, originalDueDate, previousDueDate, policies, accounts, actualCostRecord,dueDateChangedByHold, dueDateChangedByNearExpireUser); } public Loan withItem(Item newItem) { @@ -324,7 +322,7 @@ public Loan withItem(Item newItem) { } return new Loan(newRepresentation, newItem, user, proxy, checkinServicePoint, - checkoutServicePoint, originalDueDate, previousDueDate, policies, accounts, actualCostRecord,dueDateChangedByHold, dueDateChangedByNearExpireUser, latestPatronInfoAddedComment); + checkoutServicePoint, originalDueDate, previousDueDate, policies, accounts, actualCostRecord,dueDateChangedByHold, dueDateChangedByNearExpireUser); } @Override @@ -340,12 +338,12 @@ public Loan withUser(User newUser) { } return new Loan(newRepresentation, item, newUser, proxy, checkinServicePoint, - checkoutServicePoint, originalDueDate, previousDueDate, policies, accounts, actualCostRecord,dueDateChangedByHold, dueDateChangedByNearExpireUser, latestPatronInfoAddedComment); + checkoutServicePoint, originalDueDate, previousDueDate, policies, accounts, actualCostRecord,dueDateChangedByHold, dueDateChangedByNearExpireUser); } public Loan withActualCostRecord(ActualCostRecord actualCostRecord) { return new Loan(representation, item, user, proxy, checkinServicePoint, checkoutServicePoint, - originalDueDate, previousDueDate, policies, accounts, actualCostRecord,dueDateChangedByHold, dueDateChangedByNearExpireUser, latestPatronInfoAddedComment); + originalDueDate, previousDueDate, policies, accounts, actualCostRecord,dueDateChangedByHold, dueDateChangedByNearExpireUser); } public Loan withPatronGroupAtCheckout(PatronGroup patronGroup) { @@ -368,22 +366,22 @@ Loan withProxy(User newProxy) { } return new Loan(newRepresentation, item, user, newProxy, checkinServicePoint, - checkoutServicePoint, originalDueDate, previousDueDate, policies, accounts, actualCostRecord,dueDateChangedByHold, dueDateChangedByNearExpireUser, latestPatronInfoAddedComment); + checkoutServicePoint, originalDueDate, previousDueDate, policies, accounts, actualCostRecord,dueDateChangedByHold, dueDateChangedByNearExpireUser); } public Loan withCheckinServicePoint(ServicePoint newCheckinServicePoint) { return new Loan(representation, item, user, proxy, newCheckinServicePoint, - checkoutServicePoint, originalDueDate, previousDueDate, policies, accounts, actualCostRecord,dueDateChangedByHold, dueDateChangedByNearExpireUser, latestPatronInfoAddedComment); + checkoutServicePoint, originalDueDate, previousDueDate, policies, accounts, actualCostRecord,dueDateChangedByHold, dueDateChangedByNearExpireUser); } public Loan withCheckoutServicePoint(ServicePoint newCheckoutServicePoint) { return new Loan(representation, item, user, proxy, checkinServicePoint, - newCheckoutServicePoint, originalDueDate, previousDueDate, policies, accounts, actualCostRecord,dueDateChangedByHold, dueDateChangedByNearExpireUser, latestPatronInfoAddedComment); + newCheckoutServicePoint, originalDueDate, previousDueDate, policies, accounts, actualCostRecord,dueDateChangedByHold, dueDateChangedByNearExpireUser); } public Loan withAccounts(Collection newAccounts) { return new Loan(representation, item, user, proxy, checkinServicePoint, - checkoutServicePoint, originalDueDate, previousDueDate, policies, newAccounts, actualCostRecord,dueDateChangedByHold, dueDateChangedByNearExpireUser, latestPatronInfoAddedComment); + checkoutServicePoint, originalDueDate, previousDueDate, policies, newAccounts, actualCostRecord,dueDateChangedByHold, dueDateChangedByNearExpireUser); } public Loan withLoanPolicy(LoanPolicy newLoanPolicy) { @@ -391,7 +389,7 @@ public Loan withLoanPolicy(LoanPolicy newLoanPolicy) { return new Loan(representation, item, user, proxy, checkinServicePoint, checkoutServicePoint, originalDueDate, previousDueDate, - policies.withLoanPolicy(newLoanPolicy), accounts, actualCostRecord,dueDateChangedByHold, dueDateChangedByNearExpireUser, latestPatronInfoAddedComment); + policies.withLoanPolicy(newLoanPolicy), accounts, actualCostRecord,dueDateChangedByHold, dueDateChangedByNearExpireUser); } public Loan withOverdueFinePolicy(OverdueFinePolicy newOverdueFinePolicy) { @@ -399,7 +397,7 @@ public Loan withOverdueFinePolicy(OverdueFinePolicy newOverdueFinePolicy) { return new Loan(representation, item, user, proxy, checkinServicePoint, checkoutServicePoint, originalDueDate, previousDueDate, - policies.withOverdueFinePolicy(newOverdueFinePolicy), accounts, actualCostRecord,dueDateChangedByHold, dueDateChangedByNearExpireUser, latestPatronInfoAddedComment); + policies.withOverdueFinePolicy(newOverdueFinePolicy), accounts, actualCostRecord,dueDateChangedByHold, dueDateChangedByNearExpireUser); } public Loan withLostItemPolicy(LostItemPolicy newLostItemPolicy) { @@ -407,12 +405,7 @@ public Loan withLostItemPolicy(LostItemPolicy newLostItemPolicy) { return new Loan(representation, item, user, proxy, checkinServicePoint, checkoutServicePoint, originalDueDate, previousDueDate, - policies.withLostItemPolicy(newLostItemPolicy), accounts, actualCostRecord,dueDateChangedByHold, dueDateChangedByNearExpireUser, latestPatronInfoAddedComment); - } - - public Loan withLatestPatronInfoAddedComment(String newLatestPatronInfoAddedComment) { - return new Loan(representation, item, user, proxy, checkinServicePoint, - checkoutServicePoint, originalDueDate, previousDueDate, policies, accounts, actualCostRecord,dueDateChangedByHold, dueDateChangedByNearExpireUser, newLatestPatronInfoAddedComment); + policies.withLostItemPolicy(newLostItemPolicy), accounts, actualCostRecord,dueDateChangedByHold, dueDateChangedByNearExpireUser); } public String getLoanPolicyId() { @@ -705,7 +698,7 @@ public void closeLoanAsLostAndPaid() { public Loan copy() { final JsonObject representationCopy = representation.copy(); return new Loan(representationCopy, item, user, proxy, checkinServicePoint, - checkoutServicePoint, originalDueDate, previousDueDate, policies, accounts, actualCostRecord,dueDateChangedByHold, dueDateChangedByNearExpireUser, latestPatronInfoAddedComment); + checkoutServicePoint, originalDueDate, previousDueDate, policies, accounts, actualCostRecord,dueDateChangedByHold, dueDateChangedByNearExpireUser); } public Loan ageOverdueItemToLost(ZonedDateTime ageToLostDate) { diff --git a/src/main/java/org/folio/circulation/domain/LoanHistory.java b/src/main/java/org/folio/circulation/domain/LoanHistory.java deleted file mode 100644 index 146546b490..0000000000 --- a/src/main/java/org/folio/circulation/domain/LoanHistory.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.folio.circulation.domain; - -import io.vertx.core.json.JsonObject; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.ToString; - -import static lombok.AccessLevel.PRIVATE; -import static org.folio.circulation.support.json.JsonPropertyFetcher.getObjectProperty; -import static org.folio.circulation.support.json.JsonPropertyFetcher.getProperty; - -@AllArgsConstructor(access = PRIVATE) -@ToString(onlyExplicitlyIncluded = true) -@Getter -public class LoanHistory { - private final String id; - @ToString.Include - private final JsonObject representation; - - private final String operation; - - private final Loan loan; - - public static LoanHistory from(JsonObject representation) { - return new LoanHistory(getProperty(representation, "id"), - representation, getProperty(representation, "operation"), - Loan.from(getObjectProperty(representation, "loan"))); - } -} diff --git a/src/main/java/org/folio/circulation/domain/notice/TemplateContextUtil.java b/src/main/java/org/folio/circulation/domain/notice/TemplateContextUtil.java index 8ed7afa6bd..f0e3f7f83d 100644 --- a/src/main/java/org/folio/circulation/domain/notice/TemplateContextUtil.java +++ b/src/main/java/org/folio/circulation/domain/notice/TemplateContextUtil.java @@ -315,8 +315,6 @@ private static JsonObject createLoanContext(Loan loan) { } } - write(loanContext, "additionalInfo", loan.getLatestPatronInfoAddedComment()); - return loanContext; } diff --git a/src/main/java/org/folio/circulation/domain/notice/schedule/FeeFineScheduledNoticeHandler.java b/src/main/java/org/folio/circulation/domain/notice/schedule/FeeFineScheduledNoticeHandler.java index 78ae648016..7471a2f6cc 100644 --- a/src/main/java/org/folio/circulation/domain/notice/schedule/FeeFineScheduledNoticeHandler.java +++ b/src/main/java/org/folio/circulation/domain/notice/schedule/FeeFineScheduledNoticeHandler.java @@ -76,7 +76,6 @@ private CompletableFuture> fetchLoan( // this also fetches user and item return loanRepository.findLoanForAccount(context.getAccount()) - .thenCompose(r -> r.after(loanRepository::fetchLatestPatronInfoAddedComment)) .thenCompose(r -> r.after(loanPolicyRepository::findPolicyForLoan)) .thenApply(mapResult(context::withLoan)) .thenApply(r -> r.next(this::failWhenLoanIsIncomplete)); diff --git a/src/main/java/org/folio/circulation/domain/notice/schedule/LoanScheduledNoticeHandler.java b/src/main/java/org/folio/circulation/domain/notice/schedule/LoanScheduledNoticeHandler.java index 682601d5e2..374e165db8 100644 --- a/src/main/java/org/folio/circulation/domain/notice/schedule/LoanScheduledNoticeHandler.java +++ b/src/main/java/org/folio/circulation/domain/notice/schedule/LoanScheduledNoticeHandler.java @@ -114,9 +114,9 @@ protected CompletableFuture> updateNotice( protected CompletableFuture> fetchLoan( ScheduledNoticeContext context) { + // Also fetches user, item and item-related records (holdings, instance, location, etc.) return loanRepository.getById(context.getNotice().getLoanId()) - .thenCompose(r -> r.after(loanRepository::fetchLatestPatronInfoAddedComment)) .thenCompose(r -> r.after(loanPolicyRepository::findPolicyForLoan)) .thenApply(mapResult(context::withLoan)) .thenApply(r -> r.next(this::failWhenLoanIsIncomplete)); diff --git a/src/main/java/org/folio/circulation/domain/notice/schedule/RequestScheduledNoticeHandler.java b/src/main/java/org/folio/circulation/domain/notice/schedule/RequestScheduledNoticeHandler.java index df2557605f..04912e1d67 100644 --- a/src/main/java/org/folio/circulation/domain/notice/schedule/RequestScheduledNoticeHandler.java +++ b/src/main/java/org/folio/circulation/domain/notice/schedule/RequestScheduledNoticeHandler.java @@ -7,7 +7,6 @@ import static org.folio.circulation.domain.notice.schedule.TriggeringEvent.HOLD_EXPIRATION; import static org.folio.circulation.support.results.Result.failed; import static org.folio.circulation.support.results.Result.ofAsync; -import static org.folio.circulation.support.results.Result.succeeded; import static org.folio.circulation.support.results.ResultBinding.mapResult; import static org.folio.circulation.support.utils.DateTimeUtil.isAfterMillis; import static org.folio.circulation.support.utils.DateTimeUtil.isBeforeMillis; @@ -161,16 +160,8 @@ protected CompletableFuture> fetchRequestRelatedR } return requestRepository.fetchRelatedRecords(context.getRequest()) - .thenApply(r -> r.next(this::fetchLatestPatronInfoAddedComment)) .thenApply(mapResult(context::withRequest)) .thenApply(r -> r.next(this::failWhenRequestHasNoUser)); } - private Result fetchLatestPatronInfoAddedComment(Request request){ - if(request.getLoan() != null){ - return loanRepository.fetchLatestPatronInfoAddedComment(request.getLoan()).thenApply(mapResult(request::withLoan)).join(); - } - return succeeded(request); - } - } diff --git a/src/main/java/org/folio/circulation/domain/notice/session/PatronActionSessionService.java b/src/main/java/org/folio/circulation/domain/notice/session/PatronActionSessionService.java index 69d3568889..dbe2ecfd06 100644 --- a/src/main/java/org/folio/circulation/domain/notice/session/PatronActionSessionService.java +++ b/src/main/java/org/folio/circulation/domain/notice/session/PatronActionSessionService.java @@ -32,7 +32,6 @@ import org.folio.circulation.domain.notice.PatronNoticeEventBuilder; import org.folio.circulation.domain.notice.combiner.LoanNoticeContextCombiner; import org.folio.circulation.domain.representations.logs.NoticeLogContext; -import org.folio.circulation.infrastructure.storage.loans.LoanRepository; import org.folio.circulation.infrastructure.storage.sessions.PatronActionSessionRepository; import org.folio.circulation.services.EventPublisher; import org.folio.circulation.support.Clients; @@ -55,15 +54,13 @@ public class PatronActionSessionService { private final PatronActionSessionRepository patronActionSessionRepository; private final ImmediatePatronNoticeService patronNoticeService; - private final LoanRepository loanRepository; protected final EventPublisher eventPublisher; public static PatronActionSessionService using(Clients clients, - PatronActionSessionRepository patronActionSessionRepository, LoanRepository loanRepository) { + PatronActionSessionRepository patronActionSessionRepository) { return new PatronActionSessionService(patronActionSessionRepository, new ImmediatePatronNoticeService(clients, new LoanNoticeContextCombiner()), - loanRepository, new EventPublisher(clients.pubSubPublishingService())); } @@ -126,7 +123,6 @@ private CompletableFuture>> processSessions( return ofAsync(() -> sessions) .thenApply(mapResult(this::discardInvalidSessions)) - .thenCompose(r -> r.after(this::fetchLatestPatronInfoAddedComment)) .thenCompose(r -> r.after(this::sendNotice)) .thenCompose(ignored -> deleteSessions(sessions)); } @@ -196,19 +192,6 @@ private CompletableFuture>> sendNotice( .thenApply(mapResult(v -> sessions)); } - private CompletableFuture>> fetchLatestPatronInfoAddedComment( - List sessions) { - List> futures = new ArrayList<>(); - - sessions.forEach(s -> futures.add(loanRepository.fetchLatestPatronInfoAddedComment(s.getLoan()) - .thenApply(r -> s.withLoan(r.value())))); - - return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])) - .thenApply(v -> succeeded(futures.stream() - .map(CompletableFuture::join) - .collect(Collectors.toList()))); - } - private CompletableFuture> publishNoticeErrorEvent( List sessions, String errorMessage) { @@ -231,13 +214,13 @@ private Result handleResult(Result result) { return succeeded(null); } - private List buildNoticeEvents(List sessions) { + private static List buildNoticeEvents(List sessions) { return sessions.stream() - .map(this::buildPatronNoticeEvent) + .map(PatronActionSessionService::buildPatronNoticeEvent) .collect(Collectors.toList()); } - private PatronNoticeEvent buildPatronNoticeEvent(PatronSessionRecord session) { + private static PatronNoticeEvent buildPatronNoticeEvent(PatronSessionRecord session) { Loan loan = session.getLoan(); return new PatronNoticeEventBuilder() diff --git a/src/main/java/org/folio/circulation/infrastructure/storage/loans/LoanHistoryRepository.java b/src/main/java/org/folio/circulation/infrastructure/storage/loans/LoanHistoryRepository.java deleted file mode 100644 index c58724d621..0000000000 --- a/src/main/java/org/folio/circulation/infrastructure/storage/loans/LoanHistoryRepository.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.folio.circulation.infrastructure.storage.loans; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.folio.circulation.domain.Loan; -import org.folio.circulation.domain.LoanAction; -import org.folio.circulation.domain.LoanHistory; -import org.folio.circulation.domain.MultipleRecords; -import org.folio.circulation.support.Clients; -import org.folio.circulation.support.CollectionResourceClient; -import org.folio.circulation.support.fetching.GetManyRecordsRepository; -import org.folio.circulation.support.http.client.CqlQuery; -import org.folio.circulation.support.http.client.Offset; -import org.folio.circulation.support.http.client.PageLimit; -import org.folio.circulation.support.http.client.Response; -import org.folio.circulation.support.results.Result; - -import java.lang.invoke.MethodHandles; -import java.util.concurrent.CompletableFuture; - -import static org.folio.circulation.support.CqlSortBy.sortBy; -import static org.folio.circulation.support.http.client.CqlQuery.exactMatch; -import static org.folio.circulation.support.CqlSortClause.descending; -import static org.folio.circulation.support.results.ResultBinding.flatMapResult; - -public class LoanHistoryRepository implements GetManyRecordsRepository { - private static final String RECORDS_PROPERTY_NAME = "loansHistory"; - private static final Logger log = LogManager.getLogger(MethodHandles.lookup().lookupClass()); - private final CollectionResourceClient loansHistoryStorageClient; - - public LoanHistoryRepository(Clients clients) { - loansHistoryStorageClient = clients.loansHistoryStorageClient(); - } - - public CompletableFuture>> getLatestPatronInfoAdded(Loan loan) { - return exactMatch("loan.id", loan.getId()) - .combine(exactMatch("loan.action", LoanAction.PATRON_INFO_ADDED.getValue()), CqlQuery::and) - .map(q -> q.sortBy(sortBy(descending("createdDate")))) - .after(q -> getMany(q, PageLimit.one(), Offset.zeroOffset())); - } - - @Override - public CompletableFuture>> getMany(CqlQuery cqlQuery, PageLimit pageLimit, Offset offset) { - log.debug("getMany:: parameters cqlQuery: {}, pageLimit: {}, offset: {}", cqlQuery, pageLimit, offset); - return loansHistoryStorageClient.getMany(cqlQuery, pageLimit, offset) - .thenApply(flatMapResult(this::mapResponseToLoans)); - } - - private Result> mapResponseToLoans(Response response) { - log.debug("mapResponseToLoans:: parameters response: {}", response); - return MultipleRecords.from(response, LoanHistory::from, RECORDS_PROPERTY_NAME); - } -} diff --git a/src/main/java/org/folio/circulation/infrastructure/storage/loans/LoanRepository.java b/src/main/java/org/folio/circulation/infrastructure/storage/loans/LoanRepository.java index 114c1c3c6e..b0279ec8da 100644 --- a/src/main/java/org/folio/circulation/infrastructure/storage/loans/LoanRepository.java +++ b/src/main/java/org/folio/circulation/infrastructure/storage/loans/LoanRepository.java @@ -49,9 +49,7 @@ import org.folio.circulation.domain.Account; import org.folio.circulation.domain.Item; import org.folio.circulation.domain.Loan; -import org.folio.circulation.domain.LoanAction; import org.folio.circulation.domain.LoanAndRelatedRecords; -import org.folio.circulation.domain.LoanHistory; import org.folio.circulation.domain.MultipleRecords; import org.folio.circulation.domain.Request; import org.folio.circulation.domain.policy.Policy; @@ -80,7 +78,6 @@ public class LoanRepository implements GetManyRecordsRepository { private final CollectionResourceClient loansStorageClient; private final ItemRepository itemRepository; private final UserRepository userRepository; - private final LoanHistoryRepository loanHistoryRepository; private static final Logger log = LogManager.getLogger(MethodHandles.lookup().lookupClass()); private static final String ITEM_STATUS = "itemStatus"; private static final String ITEM_ID = "itemId"; @@ -94,7 +91,6 @@ public LoanRepository(Clients clients, ItemRepository itemRepository, loansStorageClient = clients.loansStorage(); this.itemRepository = itemRepository; this.userRepository = userRepository; - loanHistoryRepository = new LoanHistoryRepository(clients); } public CompletableFuture> createLoan( @@ -210,25 +206,6 @@ private CompletableFuture> fetchUser(Result result) { return result.combineAfter(userRepository::getUser, Loan::withUser); } - public CompletableFuture> fetchLatestPatronInfoAddedComment(Loan loan){ - log.debug("fetchLatestPatronInfoAddedComment:: parameters loan: {}", loan); - if(LoanAction.PATRON_INFO_ADDED.getValue().equals(loan.getAction())){ - // If latest action is patron info then we don't need to check history - return CompletableFuture.completedFuture(Result.succeeded(loan.withLatestPatronInfoAddedComment(loan.getActionComment()))); - } - return loanHistoryRepository.getLatestPatronInfoAdded(loan) - .thenApply(r -> r.map(records -> loan.withLatestPatronInfoAddedComment(mapToLatestPatronInfoAddedComment(records)))); - } - - private String mapToLatestPatronInfoAddedComment(MultipleRecords loanHistoryRecords) { - LoanHistory loanHistory = loanHistoryRecords.firstOrNull(); - String latestPatronInfoAddedComment = null; - if(loanHistory != null){ - latestPatronInfoAddedComment = loanHistory.getLoan().getActionComment(); - } - return latestPatronInfoAddedComment; - } - public CompletableFuture>> findLoansToAnonymize( PageLimit pageLimit) { diff --git a/src/main/java/org/folio/circulation/resources/ChangeDueDateResource.java b/src/main/java/org/folio/circulation/resources/ChangeDueDateResource.java index 03f06c3f5e..66613a895f 100644 --- a/src/main/java/org/folio/circulation/resources/ChangeDueDateResource.java +++ b/src/main/java/org/folio/circulation/resources/ChangeDueDateResource.java @@ -84,7 +84,7 @@ private CompletableFuture> processChangeDueDate( final EventPublisher eventPublisher = new EventPublisher(routingContext); - final LoanNoticeSender loanNoticeSender = LoanNoticeSender.using(clients, loanRepository); + final LoanNoticeSender loanNoticeSender = LoanNoticeSender.using(clients); final ConfigurationRepository configurationRepository = new ConfigurationRepository(clients); log.info("starting change due date process for loan {}", request.getLoanId()); diff --git a/src/main/java/org/folio/circulation/resources/CheckInByBarcodeResource.java b/src/main/java/org/folio/circulation/resources/CheckInByBarcodeResource.java index 1e5376e0a0..a85b262c23 100644 --- a/src/main/java/org/folio/circulation/resources/CheckInByBarcodeResource.java +++ b/src/main/java/org/folio/circulation/resources/CheckInByBarcodeResource.java @@ -73,7 +73,7 @@ private void checkIn(RoutingContext routingContext) { final PatronActionSessionService patronActionSessionService = PatronActionSessionService.using(clients, - PatronActionSessionRepository.using(clients, loanRepository, userRepository), loanRepository); + PatronActionSessionRepository.using(clients, loanRepository, userRepository)); final RequestNoticeSender requestNoticeSender = RequestNoticeSender.using(clients); diff --git a/src/main/java/org/folio/circulation/resources/CheckOutByBarcodeResource.java b/src/main/java/org/folio/circulation/resources/CheckOutByBarcodeResource.java index 018aed3291..bebe9c4c02 100644 --- a/src/main/java/org/folio/circulation/resources/CheckOutByBarcodeResource.java +++ b/src/main/java/org/folio/circulation/resources/CheckOutByBarcodeResource.java @@ -130,7 +130,7 @@ private void checkOut(RoutingContext routingContext) { final PatronActionSessionService patronActionSessionService = PatronActionSessionService.using(clients, PatronActionSessionRepository.using(clients, loanRepository, - userRepository), loanRepository); + userRepository)); final var requestScheduledNoticeService = RequestScheduledNoticeService.using(clients); diff --git a/src/main/java/org/folio/circulation/resources/EndPatronActionSessionResource.java b/src/main/java/org/folio/circulation/resources/EndPatronActionSessionResource.java index 6ac67e3182..7be337fff5 100644 --- a/src/main/java/org/folio/circulation/resources/EndPatronActionSessionResource.java +++ b/src/main/java/org/folio/circulation/resources/EndPatronActionSessionResource.java @@ -46,7 +46,7 @@ private void process(RoutingContext routingContext) { final var loanRepository = new LoanRepository(clients, itemRepository, userRepository); PatronActionSessionService patronActionSessionService = PatronActionSessionService.using(clients, - PatronActionSessionRepository.using(clients, loanRepository, userRepository), loanRepository); + PatronActionSessionRepository.using(clients, loanRepository, userRepository)); List> resultListOfEndSessionRequestResult = EndPatronSessionRequest.from(routingContext.getBodyAsJson()); diff --git a/src/main/java/org/folio/circulation/resources/ExpiredSessionProcessingResource.java b/src/main/java/org/folio/circulation/resources/ExpiredSessionProcessingResource.java index ae23315efd..c6e72fadf6 100644 --- a/src/main/java/org/folio/circulation/resources/ExpiredSessionProcessingResource.java +++ b/src/main/java/org/folio/circulation/resources/ExpiredSessionProcessingResource.java @@ -63,7 +63,7 @@ private void process(RoutingContext routingContext) { final var loanRepository = new LoanRepository(clients, itemRepository, userRepository); final PatronActionSessionService patronSessionService = PatronActionSessionService.using(clients, - PatronActionSessionRepository.using(clients, loanRepository, userRepository), loanRepository); + PatronActionSessionRepository.using(clients, loanRepository, userRepository)); final PatronExpiredSessionRepository patronExpiredSessionRepository = PatronExpiredSessionRepository.using(clients); diff --git a/src/main/java/org/folio/circulation/resources/LoanCollectionResource.java b/src/main/java/org/folio/circulation/resources/LoanCollectionResource.java index 0ec466b7aa..d9fb083f8b 100644 --- a/src/main/java/org/folio/circulation/resources/LoanCollectionResource.java +++ b/src/main/java/org/folio/circulation/resources/LoanCollectionResource.java @@ -177,7 +177,7 @@ void replace(RoutingContext routingContext) { final EventPublisher eventPublisher = new EventPublisher(routingContext); - final LoanNoticeSender loanNoticeSender = LoanNoticeSender.using(clients, loanRepository); + final LoanNoticeSender loanNoticeSender = LoanNoticeSender.using(clients); getExistingLoan(loanRepository , loan) .thenApply(e -> e.map(existingLoan -> new LoanAndRelatedRecords(loan, existingLoan))) diff --git a/src/main/java/org/folio/circulation/resources/LoanNoticeSender.java b/src/main/java/org/folio/circulation/resources/LoanNoticeSender.java index 1e3adf434f..4651e4126d 100644 --- a/src/main/java/org/folio/circulation/resources/LoanNoticeSender.java +++ b/src/main/java/org/folio/circulation/resources/LoanNoticeSender.java @@ -21,7 +21,6 @@ import org.folio.circulation.domain.notice.SingleImmediatePatronNoticeService; import org.folio.circulation.domain.representations.logs.NoticeLogContext; import org.folio.circulation.infrastructure.storage.loans.LoanPolicyRepository; -import org.folio.circulation.infrastructure.storage.loans.LoanRepository; import org.folio.circulation.resources.context.RenewalContext; import org.folio.circulation.services.EventPublisher; import org.folio.circulation.support.Clients; @@ -38,14 +37,12 @@ public class LoanNoticeSender { private final ImmediatePatronNoticeService patronNoticeService; private final LoanPolicyRepository loanPolicyRepository; private final EventPublisher eventPublisher; - private final LoanRepository loanRepository; - public static LoanNoticeSender using(Clients clients, LoanRepository loanRepository) { + public static LoanNoticeSender using(Clients clients) { return new LoanNoticeSender( new SingleImmediatePatronNoticeService(clients), new LoanPolicyRepository(clients), - new EventPublisher(clients.pubSubPublishingService()), - loanRepository + new EventPublisher(clients.pubSubPublishingService()) ); } @@ -78,8 +75,7 @@ private CompletableFuture> sendLoanNotice(Loan loan, NoticeEventTyp return succeeded(loan) .next(this::validateLoan) .mapFailure(failure -> publishNoticeErrorEvent(failure, loan, eventType)) - .next(l -> loanRepository.fetchLatestPatronInfoAddedComment(l).join()) - .after(l -> sendNotice(l, eventType)); + .after(l -> sendNotice(loan, eventType)); } private Result validateLoan(Loan loan) { diff --git a/src/main/java/org/folio/circulation/resources/RequestNoticeSender.java b/src/main/java/org/folio/circulation/resources/RequestNoticeSender.java index 94506b87d9..ac04bf9903 100644 --- a/src/main/java/org/folio/circulation/resources/RequestNoticeSender.java +++ b/src/main/java/org/folio/circulation/resources/RequestNoticeSender.java @@ -104,11 +104,9 @@ public Result sendNoticeOnRequestCreated( .count(); if (request.hasItemId()) { - fetchLatestPatronInfoAddedComment(request) - .thenApply(r -> r.after(this::sendConfirmationNoticeForRequestWithItemId)); + sendConfirmationNoticeForRequestWithItemId(request); } else { - fetchLatestPatronInfoAddedComment(request) - .thenApply(r -> r.after(this::sendConfirmationNoticeForRequestWithoutItemId)); + sendConfirmationNoticeForRequestWithoutItemId(request); } return succeeded(records); @@ -129,8 +127,7 @@ public Result sendNoticeOnRequestCancelled( } public Result sendNoticeOnRequestMoved(RequestAndRelatedRecords records) { - fetchLatestPatronInfoAddedComment(records.getRequest()) - .thenApply(r -> r.after(this::sendNoticeOnRecall)); + sendNoticeOnRecall(records.getRequest()); return succeeded(records); } @@ -140,7 +137,6 @@ public Result sendNoticeOnRequestUpdated( if (records.getRequest().getStatus() == RequestStatus.CLOSED_CANCELLED) { requestRepository.loadCancellationReason(records.getRequest()) - .thenCompose(r -> r.after(this::fetchLatestPatronInfoAddedComment)) .thenApply(r -> r.map(records::withRequest)) .thenAccept(r -> r.next(this::sendNoticeOnRequestCancelled)); } @@ -148,15 +144,6 @@ public Result sendNoticeOnRequestUpdated( return succeeded(records); } - private CompletableFuture> fetchLatestPatronInfoAddedComment(Request request) { - if(request.hasLoan()){ - return loanRepository.fetchLatestPatronInfoAddedComment(request.getLoan()) - .thenApply(r -> r.map(request::withLoan)); - } else { - return CompletableFuture.completedFuture(succeeded(request)); - } - } - public Result sendNoticeOnRequestAwaitingPickup(CheckInContext context) { final Item item = context.getItem(); final RequestQueue requestQueue = context.getRequestQueue(); @@ -204,7 +191,6 @@ private CompletableFuture> sendConfirmationNoticeForRequestWithItem PatronNoticeEvent event = createPatronNoticeEvent(request, getEventType(request)); return patronNoticeService.acceptNoticeEvent(event) - .whenComplete((r, t) -> fetchLatestPatronInfoAddedComment(request)) .whenComplete((r, t) -> sendNoticeOnRecall(request)); } @@ -236,9 +222,7 @@ private CompletableFuture> sendNoticeForRequestWithoutItemId(Reques UUID templateId = templateIdExtractor.apply(tlrSettings); if (request.isTitleLevel() && tlrSettings.isTitleLevelRequestsFeatureEnabled() && templateId != null) { - return fetchLatestPatronInfoAddedComment(request) - .thenApply(r -> sendNotice(request, templateId, eventType)) - .join(); + return sendNotice(request, templateId, eventType); } return emptyAsync(); @@ -262,7 +246,6 @@ private CompletableFuture> fetchDataAndSendRequestAwaitingPickupNot return ofAsync(() -> request) .thenCompose(r -> r.combineAfter(this::fetchServicePoint, Request::withPickupServicePoint)) .thenCompose(r -> r.combineAfter(this::fetchRequester, Request::withRequester)) - .thenCompose(r -> r.after(this::fetchLatestPatronInfoAddedComment)) .thenApply(r -> r.mapFailure(failure -> publishNoticeErrorEvent(failure, request))) .thenApply(r -> r.map(req -> createPatronNoticeEvent(req, AVAILABLE))) .thenCompose(r -> r.after(patronNoticeService::acceptNoticeEvent)); diff --git a/src/main/java/org/folio/circulation/resources/renewal/RenewalResource.java b/src/main/java/org/folio/circulation/resources/renewal/RenewalResource.java index 6fed81706b..b3078348b4 100644 --- a/src/main/java/org/folio/circulation/resources/renewal/RenewalResource.java +++ b/src/main/java/org/folio/circulation/resources/renewal/RenewalResource.java @@ -150,7 +150,7 @@ private void renew(RoutingContext routingContext) { final EventPublisher eventPublisher = new EventPublisher(routingContext); - final LoanNoticeSender loanNoticeSender = LoanNoticeSender.using(clients, loanRepository); + final LoanNoticeSender loanNoticeSender = LoanNoticeSender.using(clients); final AutomatedPatronBlocksRepository automatedPatronBlocksRepository = new AutomatedPatronBlocksRepository(clients); diff --git a/src/main/java/org/folio/circulation/support/Clients.java b/src/main/java/org/folio/circulation/support/Clients.java index 492320ffad..af5d877dea 100644 --- a/src/main/java/org/folio/circulation/support/Clients.java +++ b/src/main/java/org/folio/circulation/support/Clients.java @@ -20,7 +20,6 @@ public class Clients { private final CollectionResourceClient usersStorageClient; private final CollectionResourceClient addressTypesStorageClient; private final CollectionResourceClient loansStorageClient; - private final CollectionResourceClient loansHistoryStorageClient; private final CollectionResourceClient locationsStorageClient; private final CollectionResourceClient institutionsStorageClient; private final CollectionResourceClient campusesStorageClient; @@ -85,7 +84,6 @@ private Clients(OkapiHttpClient client, WebContext context) { usersStorageClient = createUsersStorageClient(client, context); addressTypesStorageClient = createAddressTypesStorageClient(client, context); loansStorageClient = createLoansStorageClient(client, context); - loansHistoryStorageClient = createLoansHistoryStorageClient(client, context); overdueFinesPoliciesPoliciesStorageClient = createOverdueFinesPoliciesStorageClient(client, context); lostItemPoliciesStorageClient = createLostItemPoliciesStorageClient(client, context); locationsStorageClient = createLocationsStorageClient(client, context); @@ -184,10 +182,6 @@ public CollectionResourceClient loansStorage() { return loansStorageClient; } - public CollectionResourceClient loansHistoryStorageClient() { - return loansHistoryStorageClient; - } - public CollectionResourceClient anonymizeStorageLoansClient() { return anonymizeStorageLoansClient; } @@ -496,13 +490,6 @@ private static CollectionResourceClient createLoansStorageClient( return getCollectionResourceClient(client, context, "/loan-storage/loans"); } - private static CollectionResourceClient createLoansHistoryStorageClient( - OkapiHttpClient client, WebContext context) - throws MalformedURLException { - - return getCollectionResourceClient(client, context, "/loan-storage/loan-history"); - } - private static CollectionResourceClient createAnonymizeStorageLoansClient( OkapiHttpClient client, WebContext context) throws MalformedURLException {