use of org.folio.circulation.domain.override.BlockOverrides 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.domain.override.BlockOverrides 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.domain.override.BlockOverrides in project mod-circulation by folio-org.
the class CheckOutByBarcodeRequest method fromJson.
public static CheckOutByBarcodeRequest fromJson(JsonObject request) {
final String loanDate = getProperty(request, LOAN_DATE);
final String itemBarcode = getProperty(request, ITEM_BARCODE);
final String userBarcode = getProperty(request, USER_BARCODE);
final String proxyUserBarcode = getProperty(request, PROXY_USER_BARCODE);
final String checkoutServicePointId = getProperty(request, SERVICE_POINT_ID);
final BlockOverrides blockOverrides = BlockOverrides.from(getObjectProperty(request, OVERRIDE_BLOCKS));
return new CheckOutByBarcodeRequest(defaultLoanDate(loanDate), itemBarcode, userBarcode, proxyUserBarcode, checkoutServicePointId, blockOverrides);
}
use of org.folio.circulation.domain.override.BlockOverrides in project mod-circulation by folio-org.
the class RenewalResource method renew.
private void renew(RoutingContext routingContext) {
final WebContext webContext = new WebContext(routingContext);
final Clients clients = Clients.create(webContext, client);
final OkapiPermissions okapiPermissions = OkapiPermissions.from(webContext.getHeaders());
final CirculationErrorHandler errorHandler = new OverridingErrorHandler(okapiPermissions);
final var itemRepository = new ItemRepository(clients);
final var userRepository = new UserRepository(clients);
final var loanRepository = new LoanRepository(clients, itemRepository, userRepository);
final var requestRepository = RequestRepository.using(clients, itemRepository, userRepository, loanRepository);
final var requestQueueRepository = new RequestQueueRepository(requestRepository);
final LoanPolicyRepository loanPolicyRepository = new LoanPolicyRepository(clients);
final StoreLoanAndItem storeLoanAndItem = new StoreLoanAndItem(loanRepository, itemRepository);
final LoanRepresentation loanRepresentation = new LoanRepresentation();
final ConfigurationRepository configurationRepository = new ConfigurationRepository(clients);
final LoanScheduledNoticeService scheduledNoticeService = LoanScheduledNoticeService.using(clients);
final EventPublisher eventPublisher = new EventPublisher(routingContext);
final LoanNoticeSender loanNoticeSender = LoanNoticeSender.using(clients);
final AutomatedPatronBlocksRepository automatedPatronBlocksRepository = new AutomatedPatronBlocksRepository(clients);
final FeeFineScheduledNoticeService feeFineNoticesService = FeeFineScheduledNoticeService.using(clients);
// TODO: Validation check for same user should be in the domain service
JsonObject bodyAsJson = routingContext.getBodyAsJson();
BlockOverrides overrideBlocks = getOverrideBlocks(bodyAsJson);
OkapiPermissions permissions = OkapiPermissions.from(new WebContext(routingContext).getHeaders());
final Validator<RenewalContext> automatedPatronBlocksValidator = createAutomatedPatronBlocksValidator(bodyAsJson, permissions, automatedPatronBlocksRepository);
final Validator<RenewalContext> manualPatronBlocksValidator = createManualPatronBlocksValidator(bodyAsJson, permissions, clients);
final Validator<RenewalContext> overrideRenewValidator = new OverridingBlockValidator<>(RENEWAL_BLOCK, overrideBlocks, permissions);
isRenewalBlockOverrideRequested = overrideBlocks.getRenewalBlockOverride().isRequested() || overrideBlocks.getRenewalDueDateRequiredBlockOverride().isRequested();
findLoan(bodyAsJson, loanRepository, itemRepository, userRepository, errorHandler).thenApply(r -> r.map(loan -> RenewalContext.create(loan, bodyAsJson, webContext.getUserId()))).thenComposeAsync(r -> refuseWhenPatronIsInactive(r, errorHandler, USER_IS_INACTIVE)).thenComposeAsync(r -> refuseWhenRenewalActionIsBlockedForPatron(manualPatronBlocksValidator, r, errorHandler, USER_IS_BLOCKED_MANUALLY)).thenComposeAsync(r -> refuseWhenRenewalActionIsBlockedForPatron(automatedPatronBlocksValidator, r, errorHandler, USER_IS_BLOCKED_AUTOMATICALLY)).thenComposeAsync(r -> refuseIfNoPermissionsForRenewalOverride(overrideRenewValidator, r, errorHandler)).thenCompose(r -> r.after(ctx -> lookupLoanPolicy(ctx, loanPolicyRepository, errorHandler))).thenComposeAsync(r -> r.after(ctx -> lookupRequestQueue(ctx, requestQueueRepository, errorHandler))).thenCompose(r -> r.combineAfter(configurationRepository::findTimeZoneConfiguration, RenewalContext::withTimeZone)).thenComposeAsync(r -> r.after(context -> renew(context, clients, errorHandler))).thenApply(r -> r.next(errorHandler::failWithValidationErrors)).thenApply(r -> r.map(this::unsetDueDateChangedByRecallIfNoOpenRecallsInQueue)).thenComposeAsync(r -> r.after(storeLoanAndItem::updateLoanAndItemInStorage)).thenComposeAsync(r -> r.after(context -> processFeesFines(context, clients, itemRepository, userRepository, loanRepository))).thenApplyAsync(r -> r.next(feeFineNoticesService::scheduleOverdueFineNotices)).thenComposeAsync(r -> r.after(eventPublisher::publishDueDateChangedEvent)).thenApply(r -> r.next(scheduledNoticeService::rescheduleDueDateNotices)).thenApply(r -> r.next(loanNoticeSender::sendRenewalPatronNotice)).thenApply(r -> r.map(loanRepresentation::extendedLoan)).thenApply(r -> r.map(this::toResponse)).thenAccept(webContext::writeResultToHttpResponse);
}
use of org.folio.circulation.domain.override.BlockOverrides in project mod-circulation by folio-org.
the class RenewalResource method createManualPatronBlocksValidator.
private Validator<RenewalContext> createManualPatronBlocksValidator(JsonObject request, OkapiPermissions permissions, Clients clients) {
Function<RenewalContext, CompletableFuture<Result<RenewalContext>>> validationFunction = new UserManualBlocksValidator(clients)::refuseWhenUserIsBlocked;
final BlockOverrides blockOverrides = getOverrideBlocks(request);
return blockOverrides.getPatronBlockOverride().isRequested() ? new OverridingBlockValidator<>(PATRON_BLOCK, blockOverrides, permissions) : new BlockValidator<>(USER_IS_BLOCKED_MANUALLY, validationFunction);
}
Aggregations