Search in sources :

Example 1 with DefaultLoanAnonymizationService

use of org.folio.circulation.domain.anonymization.DefaultLoanAnonymizationService 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)

Example 2 with DefaultLoanAnonymizationService

use of org.folio.circulation.domain.anonymization.DefaultLoanAnonymizationService in project mod-circulation by folio-org.

the class LoanAnonymizationResource method anonymizeLoans.

private void anonymizeLoans(RoutingContext routingContext) {
    final WebContext context = new WebContext(routingContext);
    final Clients clients = Clients.create(context, client);
    String borrowerId = routingContext.request().getParam("userId");
    final var loanRepository = new LoanRepository(clients, new ItemRepository(clients), new UserRepository(clients));
    final var accountRepository = new AccountRepository(clients);
    final var loansFinder = new LoansForBorrowerFinder(borrowerId, loanRepository, accountRepository);
    final var anonymizeStorageLoansRepository = new AnonymizeStorageLoansRepository(clients);
    final var eventPublisher = new EventPublisher(clients.pubSubPublishingService());
    final var loanAnonymizationService = new DefaultLoanAnonymizationService(new AnonymizationCheckersService(), anonymizeStorageLoansRepository, eventPublisher);
    log.info("Initializing loan anonymization for borrower: {}", borrowerId);
    loanAnonymizationService.anonymizeLoans(loansFinder::findLoansToAnonymize).thenApply(AnonymizeLoansRepresentation::from).thenApply(r -> r.map(JsonHttpResponse::ok)).thenAccept(context::writeResultToHttpResponse);
}
Also used : UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) Clients(org.folio.circulation.support.Clients) LoansForBorrowerFinder(org.folio.circulation.domain.anonymization.service.LoansForBorrowerFinder) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) MethodHandles(java.lang.invoke.MethodHandles) AnonymizeLoansRepresentation(org.folio.circulation.domain.representations.anonymization.AnonymizeLoansRepresentation) 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) EventPublisher(org.folio.circulation.services.EventPublisher) RouteRegistration(org.folio.circulation.support.RouteRegistration) Logger(org.apache.logging.log4j.Logger) DefaultLoanAnonymizationService(org.folio.circulation.domain.anonymization.DefaultLoanAnonymizationService) AccountRepository(org.folio.circulation.infrastructure.storage.feesandfines.AccountRepository) LogManager(org.apache.logging.log4j.LogManager) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) AnonymizationCheckersService(org.folio.circulation.domain.anonymization.service.AnonymizationCheckersService) AnonymizeStorageLoansRepository(org.folio.circulation.infrastructure.storage.loans.AnonymizeStorageLoansRepository) HttpClient(io.vertx.core.http.HttpClient) WebContext(org.folio.circulation.support.http.server.WebContext) JsonHttpResponse(org.folio.circulation.support.http.server.JsonHttpResponse) EventPublisher(org.folio.circulation.services.EventPublisher) DefaultLoanAnonymizationService(org.folio.circulation.domain.anonymization.DefaultLoanAnonymizationService) AccountRepository(org.folio.circulation.infrastructure.storage.feesandfines.AccountRepository) Clients(org.folio.circulation.support.Clients) LoansForBorrowerFinder(org.folio.circulation.domain.anonymization.service.LoansForBorrowerFinder) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) AnonymizeLoansRepresentation(org.folio.circulation.domain.representations.anonymization.AnonymizeLoansRepresentation) AnonymizationCheckersService(org.folio.circulation.domain.anonymization.service.AnonymizationCheckersService) AnonymizeStorageLoansRepository(org.folio.circulation.infrastructure.storage.loans.AnonymizeStorageLoansRepository)

Aggregations

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