use of org.folio.circulation.support.results.CommonFailures in project mod-circulation by folio-org.
the class ScheduledAnonymizationProcessingResource method scheduledAnonymizeLoans.
private void scheduledAnonymizeLoans(RoutingContext routingContext) {
final WebContext context = new WebContext(routingContext);
final Clients clients = Clients.create(context, client);
ConfigurationRepository configurationRepository = new ConfigurationRepository(clients);
final var itemRepository = new ItemRepository(clients);
final var userRepository = new UserRepository(clients);
final var loanRepository = new LoanRepository(clients, itemRepository, userRepository);
final var accountRepository = new AccountRepository(clients);
final var anonymizeStorageLoansRepository = new AnonymizeStorageLoansRepository(clients);
final var eventPublisher = new EventPublisher(clients.pubSubPublishingService());
final var loansFinder = new LoansForTenantFinder(loanRepository, accountRepository, Environment.getScheduledAnonymizationNumberOfLoansToCheck());
log.info("Initializing loan anonymization for current tenant");
safelyInitialise(configurationRepository::loanHistoryConfiguration).thenApply(r -> r.map(config -> new DefaultLoanAnonymizationService(new AnonymizationCheckersService(config, ClockUtil::getZonedDateTime), anonymizeStorageLoansRepository, eventPublisher))).thenCompose(r -> r.after(service -> service.anonymizeLoans(loansFinder::findLoansToAnonymize))).thenApply(AnonymizeLoansRepresentation::from).thenApply(r -> r.map(JsonHttpResponse::ok)).exceptionally(CommonFailures::failedDueToServerError).thenAccept(context::writeResultToHttpResponse);
}
use of org.folio.circulation.support.results.CommonFailures in project mod-circulation by folio-org.
the class ScheduledNoticeProcessingResource method process.
private void process(RoutingContext routingContext) {
final WebContext context = new WebContext(routingContext);
final Clients clients = Clients.create(context, client);
final ScheduledNoticesRepository scheduledNoticesRepository = ScheduledNoticesRepository.using(clients);
final ConfigurationRepository configurationRepository = new ConfigurationRepository(clients);
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);
safelyInitialise(configurationRepository::lookupSchedulerNoticesProcessingLimit).thenCompose(r -> r.after(limit -> findNoticesToSend(configurationRepository, scheduledNoticesRepository, limit))).thenCompose(r -> r.after(notices -> handleNotices(clients, requestRepository, loanRepository, notices))).thenApply(r -> r.map(toFixedValue(NoContentResponse::noContent))).exceptionally(CommonFailures::failedDueToServerError).thenAccept(context::writeResultToHttpResponse);
}
use of org.folio.circulation.support.results.CommonFailures in project mod-circulation by folio-org.
the class ExpiredSessionProcessingResource method process.
private void process(RoutingContext routingContext) {
final WebContext context = new WebContext(routingContext);
final Clients clients = Clients.create(context, client);
final ConfigurationRepository configurationRepository = new ConfigurationRepository(clients);
final var userRepository = new UserRepository(clients);
final var itemRepository = new ItemRepository(clients);
final var loanRepository = new LoanRepository(clients, itemRepository, userRepository);
final PatronActionSessionService patronSessionService = PatronActionSessionService.using(clients, PatronActionSessionRepository.using(clients, loanRepository, userRepository));
final PatronExpiredSessionRepository patronExpiredSessionRepository = PatronExpiredSessionRepository.using(clients);
safelyInitialise(configurationRepository::lookupSessionTimeout).thenCompose(r -> r.after(this::defineExpiredTime)).thenCompose(r -> r.after(inactivityTime -> patronExpiredSessionRepository.findPatronExpiredSessions(ALL, inactivityTime))).thenCompose(r -> r.after(expiredSessions -> attemptEndSessions(patronSessionService, expiredSessions))).thenApply(r -> r.map(toFixedValue(NoContentResponse::noContent))).exceptionally(CommonFailures::failedDueToServerError).thenAccept(context::writeResultToHttpResponse);
}
use of org.folio.circulation.support.results.CommonFailures in project mod-circulation by folio-org.
the class LoanRelatedFeeFineClosedHandlerResource method handleFeeFineClosedEvent.
private void handleFeeFineClosedEvent(RoutingContext routingContext) {
final WebContext context = new WebContext(routingContext);
final EventPublisher eventPublisher = new EventPublisher(routingContext);
log.info("Event {} received: {}", LOAN_RELATED_FEE_FINE_CLOSED, routingContext.getBodyAsString());
createAndValidateRequest(routingContext).after(request -> processEvent(context, request, eventPublisher)).thenCompose(r -> r.after(eventPublisher::publishClosedLoanEvent)).exceptionally(CommonFailures::failedDueToServerError).thenApply(r -> r.map(toFixedValue(NoContentResponse::noContent))).thenAccept(result -> result.applySideEffect(context::write, failure -> {
log.error("Cannot handle event [{}], error occurred {}", routingContext.getBodyAsString(), failure);
context.write(noContent());
}));
}
Aggregations