use of org.folio.circulation.domain.anonymization.service.LoansForTenantFinder 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);
}
Aggregations