Skip to content

Commit

Permalink
CIRC-1942 - Revert CIRC-1793 (Add the field loan.additionalInfo) (#1351)
Browse files Browse the repository at this point in the history
* Revert "CIRC-1793 Add the field "loan.additionalInfo" to the Loan Object in the Notice context (#1332)"

This reverts commit 794e687

* CIRC-1942 Remove unused method

(cherry picked from commit f6cab56)
  • Loading branch information
alexanderkurash committed Oct 25, 2023
1 parent 118f5f3 commit 93ca94e
Show file tree
Hide file tree
Showing 20 changed files with 44 additions and 231 deletions.
36 changes: 12 additions & 24 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
]
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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
},
Expand Down
33 changes: 13 additions & 20 deletions src/main/java/org/folio/circulation/domain/Loan.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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() {
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -368,51 +366,46 @@ 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<Account> 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) {
requireNonNull(newLoanPolicy, "newLoanPolicy cannot be null");

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) {
requireNonNull(newOverdueFinePolicy, "newOverdueFinePolicy cannot be null");

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) {
requireNonNull(newLostItemPolicy, "newLostItemPolicy cannot be null");

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() {
Expand Down Expand Up @@ -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) {
Expand Down
29 changes: 0 additions & 29 deletions src/main/java/org/folio/circulation/domain/LoanHistory.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,6 @@ private static JsonObject createLoanContext(Loan loan) {
}
}

write(loanContext, "additionalInfo", loan.getLatestPatronInfoAddedComment());

return loanContext;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ private CompletableFuture<Result<ScheduledNoticeContext>> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ protected CompletableFuture<Result<ScheduledNotice>> updateNotice(

protected CompletableFuture<Result<ScheduledNoticeContext>> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -161,16 +160,8 @@ protected CompletableFuture<Result<ScheduledNoticeContext>> fetchRequestRelatedR
}

return requestRepository.fetchRelatedRecords(context.getRequest())
.thenApply(r -> r.next(this::fetchLatestPatronInfoAddedComment))
.thenApply(mapResult(context::withRequest))
.thenApply(r -> r.next(this::failWhenRequestHasNoUser));
}

private Result<Request> fetchLatestPatronInfoAddedComment(Request request){
if(request.getLoan() != null){
return loanRepository.fetchLatestPatronInfoAddedComment(request.getLoan()).thenApply(mapResult(request::withLoan)).join();
}
return succeeded(request);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()));
}

Expand Down Expand Up @@ -126,7 +123,6 @@ private CompletableFuture<Result<List<PatronSessionRecord>>> processSessions(

return ofAsync(() -> sessions)
.thenApply(mapResult(this::discardInvalidSessions))
.thenCompose(r -> r.after(this::fetchLatestPatronInfoAddedComment))
.thenCompose(r -> r.after(this::sendNotice))
.thenCompose(ignored -> deleteSessions(sessions));
}
Expand Down Expand Up @@ -196,19 +192,6 @@ private CompletableFuture<Result<List<PatronSessionRecord>>> sendNotice(
.thenApply(mapResult(v -> sessions));
}

private CompletableFuture<Result<List<PatronSessionRecord>>> fetchLatestPatronInfoAddedComment(
List<PatronSessionRecord> sessions) {
List<CompletableFuture<PatronSessionRecord>> 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<Result<Void>> publishNoticeErrorEvent(
List<PatronSessionRecord> sessions, String errorMessage) {

Expand All @@ -231,13 +214,13 @@ private Result<Void> handleResult(Result<?> result) {
return succeeded(null);
}

private List<PatronNoticeEvent> buildNoticeEvents(List<PatronSessionRecord> sessions) {
private static List<PatronNoticeEvent> buildNoticeEvents(List<PatronSessionRecord> 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()
Expand Down
Loading

0 comments on commit 93ca94e

Please sign in to comment.