Search in sources :

Example 1 with LoansForTenantFinder

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);
}
Also used : Environment(org.folio.Environment) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) Clients(org.folio.circulation.support.Clients) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) ConfigurationRepository(org.folio.circulation.infrastructure.storage.ConfigurationRepository) WebContext(org.folio.circulation.support.http.server.WebContext) Router(io.vertx.ext.web.Router) RoutingContext(io.vertx.ext.web.RoutingContext) JsonHttpResponse(org.folio.circulation.support.http.server.JsonHttpResponse) AccountRepository(org.folio.circulation.infrastructure.storage.feesandfines.AccountRepository) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) AnonymizeStorageLoansRepository(org.folio.circulation.infrastructure.storage.loans.AnonymizeStorageLoansRepository) CommonFailures(org.folio.circulation.support.results.CommonFailures) MethodHandles(java.lang.invoke.MethodHandles) AnonymizeLoansRepresentation(org.folio.circulation.domain.representations.anonymization.AnonymizeLoansRepresentation) EventPublisher(org.folio.circulation.services.EventPublisher) RouteRegistration(org.folio.circulation.support.RouteRegistration) LoansForTenantFinder(org.folio.circulation.domain.anonymization.service.LoansForTenantFinder) Logger(org.apache.logging.log4j.Logger) DefaultLoanAnonymizationService(org.folio.circulation.domain.anonymization.DefaultLoanAnonymizationService) ClockUtil(org.folio.circulation.support.utils.ClockUtil) AsynchronousResultBindings.safelyInitialise(org.folio.circulation.support.results.AsynchronousResultBindings.safelyInitialise) LogManager(org.apache.logging.log4j.LogManager) AnonymizationCheckersService(org.folio.circulation.domain.anonymization.service.AnonymizationCheckersService) HttpClient(io.vertx.core.http.HttpClient) WebContext(org.folio.circulation.support.http.server.WebContext) EventPublisher(org.folio.circulation.services.EventPublisher) DefaultLoanAnonymizationService(org.folio.circulation.domain.anonymization.DefaultLoanAnonymizationService) ClockUtil(org.folio.circulation.support.utils.ClockUtil) AccountRepository(org.folio.circulation.infrastructure.storage.feesandfines.AccountRepository) LoansForTenantFinder(org.folio.circulation.domain.anonymization.service.LoansForTenantFinder) Clients(org.folio.circulation.support.Clients) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) AnonymizationCheckersService(org.folio.circulation.domain.anonymization.service.AnonymizationCheckersService) ConfigurationRepository(org.folio.circulation.infrastructure.storage.ConfigurationRepository) AnonymizeStorageLoansRepository(org.folio.circulation.infrastructure.storage.loans.AnonymizeStorageLoansRepository)

Aggregations

HttpClient (io.vertx.core.http.HttpClient)1 Router (io.vertx.ext.web.Router)1 RoutingContext (io.vertx.ext.web.RoutingContext)1 MethodHandles (java.lang.invoke.MethodHandles)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 Environment (org.folio.Environment)1 DefaultLoanAnonymizationService (org.folio.circulation.domain.anonymization.DefaultLoanAnonymizationService)1 AnonymizationCheckersService (org.folio.circulation.domain.anonymization.service.AnonymizationCheckersService)1 LoansForTenantFinder (org.folio.circulation.domain.anonymization.service.LoansForTenantFinder)1 AnonymizeLoansRepresentation (org.folio.circulation.domain.representations.anonymization.AnonymizeLoansRepresentation)1 ConfigurationRepository (org.folio.circulation.infrastructure.storage.ConfigurationRepository)1 AccountRepository (org.folio.circulation.infrastructure.storage.feesandfines.AccountRepository)1 ItemRepository (org.folio.circulation.infrastructure.storage.inventory.ItemRepository)1 AnonymizeStorageLoansRepository (org.folio.circulation.infrastructure.storage.loans.AnonymizeStorageLoansRepository)1 LoanRepository (org.folio.circulation.infrastructure.storage.loans.LoanRepository)1 UserRepository (org.folio.circulation.infrastructure.storage.users.UserRepository)1 EventPublisher (org.folio.circulation.services.EventPublisher)1 Clients (org.folio.circulation.support.Clients)1 RouteRegistration (org.folio.circulation.support.RouteRegistration)1