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);
}
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);
}
Aggregations