Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CIRC-1513 remove due date schedule notices after checkin #1121

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.folio.circulation.infrastructure.storage.feesandfines.FeeFineRepository;
import org.folio.circulation.infrastructure.storage.inventory.ItemRepository;
import org.folio.circulation.infrastructure.storage.loans.OverdueFinePolicyRepository;
import org.folio.circulation.infrastructure.storage.notices.ScheduledNoticesRepository;
import org.folio.circulation.resources.context.RenewalContext;
import org.folio.circulation.services.FeeFineFacade;
import org.folio.circulation.services.support.CreateAccountCommand;
Expand All @@ -42,7 +41,6 @@ public class OverdueFineService {
private final ItemRepository itemRepository;
private final FeeFineOwnerRepository feeFineOwnerRepository;
private final FeeFineRepository feeFineRepository;
private final ScheduledNoticesRepository scheduledNoticesRepository;
private final OverduePeriodCalculatorService overduePeriodCalculatorService;
private final FeeFineFacade feeFineFacade;

Expand Down Expand Up @@ -208,10 +206,7 @@ private CompletableFuture<Result<FeeFineAction>> createFeeFineRecord(Loan loan,
.thenCompose(r -> r.after(this::lookupFeeFine))
.thenCompose(r -> r.after(this::lookupItemRelatedRecords))
.thenCompose(r -> r.after(this::lookupFeeFineOwner))
.thenCompose(r -> r.after(this::createAccount))
.thenCompose(r -> r.after(feeFineAction -> scheduledNoticesRepository
.deleteOverdueNotices(loan.getId())
.thenApply(rs -> r)));
.thenCompose(r -> r.after(this::createAccount));
}

private CompletableFuture<Result<FeeFineAction>> createAccount(CalculationParameters params) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.folio.circulation.resources;

import static org.folio.circulation.domain.notice.schedule.TriggeringEvent.DUE_DATE;
import static org.folio.circulation.domain.representations.CheckOutByBarcodeRequest.ITEM_BARCODE;
import static org.folio.circulation.domain.validation.UserNotFoundValidator.refuseWhenLoggedInUserNotPresent;
import static org.folio.circulation.support.ValidationErrorFailure.singleValidationError;
import static org.folio.circulation.support.results.ResultBinding.mapResult;

import org.folio.circulation.domain.CheckInContext;
import org.folio.circulation.domain.Item;
import org.folio.circulation.domain.Loan;
import org.folio.circulation.domain.notice.schedule.RequestScheduledNoticeService;
import org.folio.circulation.domain.notice.session.PatronActionSessionService;
import org.folio.circulation.domain.representations.CheckInByBarcodeRequest;
Expand All @@ -14,6 +17,7 @@
import org.folio.circulation.infrastructure.storage.ConfigurationRepository;
import org.folio.circulation.infrastructure.storage.inventory.ItemRepository;
import org.folio.circulation.infrastructure.storage.loans.LoanRepository;
import org.folio.circulation.infrastructure.storage.notices.ScheduledNoticesRepository;
import org.folio.circulation.infrastructure.storage.requests.RequestQueueRepository;
import org.folio.circulation.infrastructure.storage.requests.RequestRepository;
import org.folio.circulation.infrastructure.storage.sessions.PatronActionSessionRepository;
Expand All @@ -29,6 +33,8 @@
import io.vertx.ext.web.Router;
import io.vertx.ext.web.RoutingContext;

import java.util.Optional;

public class CheckInByBarcodeResource extends Resource {
public CheckInByBarcodeResource(HttpClient client) {
super(client);
Expand Down Expand Up @@ -65,6 +71,8 @@ private void checkIn(RoutingContext routingContext) {

final RequestScheduledNoticeService requestScheduledNoticeService =
RequestScheduledNoticeService.using(clients);
final ScheduledNoticesRepository scheduledNoticesRepository =
ScheduledNoticesRepository.using(clients);

final PatronActionSessionService patronActionSessionService =
PatronActionSessionService.using(clients,
Expand Down Expand Up @@ -94,6 +102,8 @@ private void checkIn(RoutingContext routingContext) {
processAdapter::findSingleOpenLoan, CheckInContext::withLoan))
.thenComposeAsync(findLoanResult -> findLoanResult.combineAfter(
processAdapter::checkInLoan, CheckInContext::withLoan))
.thenApplyAsync(mapResult(checkInContext ->
removeDueDateNoticesForClosedLoan(checkInContext, scheduledNoticesRepository)))
.thenComposeAsync(checkInLoan -> checkInLoan.combineAfter(
processAdapter::updateRequestQueue, CheckInContext::withRequestQueue))
.thenComposeAsync(updateRequestQueueResult -> updateRequestQueueResult.combineAfter(
Expand Down Expand Up @@ -134,4 +144,17 @@ private ValidationErrorFailure errorWhenInIncorrectStatus(Item item) {

return singleValidationError(message, ITEM_BARCODE, item.getBarcode());
}

private CheckInContext removeDueDateNoticesForClosedLoan(CheckInContext context,
ScheduledNoticesRepository repository) {

String loanId = Optional.ofNullable(context)
.map(CheckInContext::getLoan)
.filter(Loan::isClosed)
.map(Loan::getId)
.orElse(null);

repository.deleteByLoanIdAndTriggeringEvent(loanId, DUE_DATE);
return context;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package org.folio.circulation.resources;

import static java.util.concurrent.CompletableFuture.completedFuture;
import static org.folio.circulation.domain.RequestLevel.TITLE;
import static org.folio.circulation.support.results.Result.succeeded;

import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.folio.circulation.domain.CheckInContext;
Expand All @@ -29,7 +27,6 @@
import org.folio.circulation.infrastructure.storage.loans.LoanPolicyRepository;
import org.folio.circulation.infrastructure.storage.loans.LoanRepository;
import org.folio.circulation.infrastructure.storage.loans.OverdueFinePolicyRepository;
import org.folio.circulation.infrastructure.storage.notices.ScheduledNoticesRepository;
import org.folio.circulation.infrastructure.storage.requests.RequestQueueRepository;
import org.folio.circulation.infrastructure.storage.requests.RequestRepository;
import org.folio.circulation.infrastructure.storage.users.AddressTypeRepository;
Expand Down Expand Up @@ -108,7 +105,6 @@ public static CheckInProcessAdapter newInstance(Clients clients,
new OverdueFinePolicyRepository(clients), itemRepository,
new FeeFineOwnerRepository(clients),
new FeeFineRepository(clients),
ScheduledNoticesRepository.using(clients),
new OverduePeriodCalculatorService(new CalendarRepository(clients),
new LoanPolicyRepository(clients)),
new FeeFineFacade(clients));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
import org.folio.circulation.infrastructure.storage.loans.LoanPolicyRepository;
import org.folio.circulation.infrastructure.storage.loans.LoanRepository;
import org.folio.circulation.infrastructure.storage.loans.OverdueFinePolicyRepository;
import org.folio.circulation.infrastructure.storage.notices.ScheduledNoticesRepository;
import org.folio.circulation.infrastructure.storage.requests.RequestQueueRepository;
import org.folio.circulation.infrastructure.storage.requests.RequestRepository;
import org.folio.circulation.infrastructure.storage.users.UserRepository;
Expand Down Expand Up @@ -246,7 +245,6 @@ private CompletableFuture<Result<RenewalContext>> processFeesFinesForRegularRene
itemRepository,
new FeeFineOwnerRepository(clients),
new FeeFineRepository(clients),
ScheduledNoticesRepository.using(clients),
new OverduePeriodCalculatorService(new CalendarRepository(clients),
new LoanPolicyRepository(clients)),
new FeeFineFacade(clients));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,14 +583,6 @@ void allDueDateNoticesAreDiscardedWhenLoanIsClosed() {

checkInFixture.checkInByBarcode(item);

verifyNumberOfScheduledNotices(5);

var processingTime = AFTER_RECURRING_PERIOD
.plusDate(AFTER_PERIOD.plusDate(dueDate))
.plusSeconds(1);

scheduledNoticeProcessingClient.runLoanNoticesProcessing(processingTime);

verifyNumberOfScheduledNotices(0);
verifyNumberOfSentNotices(0);
verifyNumberOfPublishedEvents(NOTICE, 0);
Expand Down
Loading