use of org.folio.circulation.resources.context.RenewalContext in project mod-circulation by folio-org.
the class RenewalResource method createAutomatedPatronBlocksValidator.
private Validator<RenewalContext> createAutomatedPatronBlocksValidator(JsonObject request, OkapiPermissions permissions, AutomatedPatronBlocksRepository automatedPatronBlocksRepository) {
Function<RenewalContext, CompletableFuture<Result<RenewalContext>>> validationFunction = new AutomatedPatronBlocksValidator(automatedPatronBlocksRepository)::refuseWhenRenewalActionIsBlockedForPatron;
final BlockOverrides blockOverrides = getOverrideBlocks(request);
return blockOverrides.getPatronBlockOverride().isRequested() ? new OverridingBlockValidator<>(PATRON_BLOCK, blockOverrides, permissions) : new BlockValidator<>(USER_IS_BLOCKED_AUTOMATICALLY, validationFunction);
}
use of org.folio.circulation.resources.context.RenewalContext in project mod-circulation by folio-org.
the class RenewalResource method renew.
private Result<RenewalContext> renew(RenewalContext context, ZonedDateTime renewDate) {
final var loan = context.getLoan();
final var requestQueue = context.getRequestQueue();
final var loanPolicy = loan.getLoanPolicy();
final Result<ZonedDateTime> proposedDueDateResult = calculateNewDueDate(loan, requestQueue, renewDate);
final List<ValidationError> errors = new ArrayList<>();
addErrorsIfDueDateResultFailed(loan, errors, proposedDueDateResult);
if (errors.isEmpty()) {
final BlockOverrides blockOverrides = BlockOverrides.from(getObjectProperty(context.getRenewalRequest(), "overrideBlocks"));
if (!blockOverrides.getPatronBlockOverride().isRequested() && !blockOverrides.getRenewalBlockOverride().isRequested()) {
return proposedDueDateResult.map(dueDate -> loan.renew(dueDate, loanPolicy.getId())).map(l -> context);
}
return proposedDueDateResult.map(dueDate -> loan.overrideRenewal(dueDate, loanPolicy.getId(), blockOverrides.getComment())).map(l -> context);
}
return failedValidation(errors);
}
use of org.folio.circulation.resources.context.RenewalContext in project mod-circulation by folio-org.
the class OverdueFineServiceTest method shouldNotCreateFeeFineRecordWhenItemDoesNotExist.
@ParameterizedTest
@MethodSource("testParameters")
void shouldNotCreateFeeFineRecordWhenItemDoesNotExist(Boolean renewal, Boolean dueDateChangedByRecall, Double overdueFine, String overdueFineInterval, Double maxOverdueFine, Double overdueRecallFine, String overdueRecallFineInterval, Double maxOverdueRecallFine, Integer periodCalculatorResult, Double correctOverdueFine) throws ExecutionException, InterruptedException {
Loan loan = createLoan(overdueFine, overdueFineInterval, overdueRecallFine, overdueRecallFineInterval, maxOverdueFine, maxOverdueRecallFine, dueDateChangedByRecall);
when(overdueFinePolicyRepository.findOverdueFinePolicyForLoan(any())).thenReturn(completedFuture(succeeded(loan)));
when(overduePeriodCalculatorService.getMinutes(any(), any())).thenReturn(completedFuture(succeeded(periodCalculatorResult)));
when(itemRepository.fetchItemRelatedRecords(any())).thenReturn(completedFuture(succeeded(null)));
when(feeFineOwnerRepository.findOwnerForServicePoint(SERVICE_POINT_ID.toString())).thenReturn(completedFuture(succeeded(createFeeFineOwner())));
when(feeFineRepository.getFeeFine(FEE_FINE_TYPE, true)).thenReturn(completedFuture(succeeded(createFeeFine())));
if (renewal) {
RenewalContext context = createRenewalContext(loan);
overdueFineService.createOverdueFineIfNecessary(context).get();
} else {
CheckInContext context = new CheckInContext(CheckInByBarcodeRequest.from(createCheckInByBarcodeRequest()).value()).withLoan(loan);
overdueFineService.createOverdueFineIfNecessary(context, LOGGED_IN_USER_ID).get();
}
verifyNoInteractions(feeFineOwnerRepository);
verifyNoInteractions(accountRepository);
verifyNoInteractions(feeFineActionRepository);
}
use of org.folio.circulation.resources.context.RenewalContext in project mod-circulation by folio-org.
the class OverdueFineServiceTest method shouldNotCreateFeeFineRecordWhenLoanIsNotProvided.
@ParameterizedTest
@MethodSource("testParameters")
void shouldNotCreateFeeFineRecordWhenLoanIsNotProvided(Boolean renewal, Boolean dueDateChangedByRecall, Double overdueFine, String overdueFineInterval, Double maxOverdueFine, Double overdueRecallFine, String overdueRecallFineInterval, Double maxOverdueRecallFine, Integer periodCalculatorResult, Double correctOverdueFine) throws ExecutionException, InterruptedException {
if (renewal) {
RenewalContext context = createRenewalContext(null);
overdueFineService.createOverdueFineIfNecessary(context).get();
} else {
CheckInContext context = mock(CheckInContext.class);
when(context.getLoan()).thenReturn(null);
overdueFineService.createOverdueFineIfNecessary(context, LOGGED_IN_USER_ID).get();
}
verifyNoInteractions(accountRepository);
verifyNoInteractions(feeFineActionRepository);
}
use of org.folio.circulation.resources.context.RenewalContext in project mod-circulation by folio-org.
the class OverdueFineServiceTest method shouldNotCreateFeeFineForRenewalWhenShouldForgiveOverdueFine.
@ParameterizedTest
@MethodSource("testParameters")
void shouldNotCreateFeeFineForRenewalWhenShouldForgiveOverdueFine(Boolean renewal, Boolean dueDateChangedByRecall, Double overdueFine, String overdueFineInterval, Double maxOverdueFine, Double overdueRecallFine, String overdueRecallFineInterval, Double maxOverdueRecallFine, Integer periodCalculatorResult, Double correctOverdueFine) throws ExecutionException, InterruptedException {
JsonObject overdueFinePolicyJson = createOverdueFinePolicyJson(overdueFine, overdueFineInterval, overdueRecallFine, overdueRecallFineInterval, maxOverdueFine, maxOverdueRecallFine).put("forgiveOverdueFine", true);
OverdueFinePolicy overdueFinePolicy = createOverdueFinePolicy(overdueFinePolicyJson);
Loan loan = createLoan(overdueFine, overdueFineInterval, overdueRecallFine, overdueRecallFineInterval, maxOverdueFine, maxOverdueRecallFine, dueDateChangedByRecall).withOverdueFinePolicy(overdueFinePolicy);
when(overdueFinePolicyRepository.findOverdueFinePolicyForLoan(any())).thenReturn(completedFuture(succeeded(loan)));
RenewalContext renewalRecords = createRenewalContext(loan);
overdueFineService.createOverdueFineIfNecessary(renewalRecords).get();
verifyNoInteractions(feeFineRepository);
verifyNoInteractions(itemRepository);
verifyNoInteractions(feeFineOwnerRepository);
verifyNoInteractions(accountRepository);
}
Aggregations