Search in sources :

Example 1 with CommonFailures

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

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);
}
Also used : ScheduledNoticesRepository(org.folio.circulation.infrastructure.storage.notices.ScheduledNoticesRepository) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) Clients(org.folio.circulation.support.Clients) CommonFailures(org.folio.circulation.support.results.CommonFailures) MultipleRecords(org.folio.circulation.domain.MultipleRecords) 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) MappingFunctions.toFixedValue(org.folio.circulation.support.results.MappingFunctions.toFixedValue) CompletableFuture(java.util.concurrent.CompletableFuture) RoutingContext(io.vertx.ext.web.RoutingContext) Result(org.folio.circulation.support.results.Result) RouteRegistration(org.folio.circulation.support.RouteRegistration) PageLimit(org.folio.circulation.support.http.client.PageLimit) AsynchronousResultBindings.safelyInitialise(org.folio.circulation.support.results.AsynchronousResultBindings.safelyInitialise) ScheduledNotice(org.folio.circulation.domain.notice.schedule.ScheduledNotice) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) RequestRepository(org.folio.circulation.infrastructure.storage.requests.RequestRepository) NoContentResponse(org.folio.circulation.support.http.server.NoContentResponse) HttpClient(io.vertx.core.http.HttpClient) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) WebContext(org.folio.circulation.support.http.server.WebContext) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) NoContentResponse(org.folio.circulation.support.http.server.NoContentResponse) ScheduledNoticesRepository(org.folio.circulation.infrastructure.storage.notices.ScheduledNoticesRepository) ConfigurationRepository(org.folio.circulation.infrastructure.storage.ConfigurationRepository) Clients(org.folio.circulation.support.Clients) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository)

Example 3 with CommonFailures

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);
}
Also used : 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) ZonedDateTime(java.time.ZonedDateTime) WebContext(org.folio.circulation.support.http.server.WebContext) ALL(org.folio.circulation.domain.notice.session.PatronActionType.ALL) Router(io.vertx.ext.web.Router) CompletableFuture(java.util.concurrent.CompletableFuture) RoutingContext(io.vertx.ext.web.RoutingContext) StringUtils(org.apache.commons.lang3.StringUtils) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) CommonFailures(org.folio.circulation.support.results.CommonFailures) PatronActionSessionRepository(org.folio.circulation.infrastructure.storage.sessions.PatronActionSessionRepository) PatronExpiredSessionRepository(org.folio.circulation.infrastructure.storage.sessions.PatronExpiredSessionRepository) MappingFunctions.toFixedValue(org.folio.circulation.support.results.MappingFunctions.toFixedValue) Result(org.folio.circulation.support.results.Result) Collectors(java.util.stream.Collectors) ExpiredSession(org.folio.circulation.domain.notice.session.ExpiredSession) Result.ofAsync(org.folio.circulation.support.results.Result.ofAsync) RouteRegistration(org.folio.circulation.support.RouteRegistration) List(java.util.List) ClockUtil(org.folio.circulation.support.utils.ClockUtil) PatronActionSessionService(org.folio.circulation.domain.notice.session.PatronActionSessionService) AsynchronousResultBindings.safelyInitialise(org.folio.circulation.support.results.AsynchronousResultBindings.safelyInitialise) NoContentResponse(org.folio.circulation.support.http.server.NoContentResponse) HttpClient(io.vertx.core.http.HttpClient) PatronExpiredSessionRepository(org.folio.circulation.infrastructure.storage.sessions.PatronExpiredSessionRepository) WebContext(org.folio.circulation.support.http.server.WebContext) Clients(org.folio.circulation.support.Clients) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) PatronActionSessionService(org.folio.circulation.domain.notice.session.PatronActionSessionService) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) NoContentResponse(org.folio.circulation.support.http.server.NoContentResponse) ConfigurationRepository(org.folio.circulation.infrastructure.storage.ConfigurationRepository)

Example 4 with CommonFailures

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());
    }));
}
Also used : UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) Clients(org.folio.circulation.support.Clients) LOAN_RELATED_FEE_FINE_CLOSED(org.folio.circulation.domain.EventType.LOAN_RELATED_FEE_FINE_CLOSED) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) LoanRelatedFeeFineClosedEvent(org.folio.circulation.domain.subscribers.LoanRelatedFeeFineClosedEvent) WebContext(org.folio.circulation.support.http.server.WebContext) Router(io.vertx.ext.web.Router) CompletableFuture(java.util.concurrent.CompletableFuture) LoanRelatedFeeFineClosedEvent.fromJson(org.folio.circulation.domain.subscribers.LoanRelatedFeeFineClosedEvent.fromJson) ValidationErrorFailure.singleValidationError(org.folio.circulation.support.ValidationErrorFailure.singleValidationError) Resource(org.folio.circulation.resources.Resource) RoutingContext(io.vertx.ext.web.RoutingContext) AccountRepository(org.folio.circulation.infrastructure.storage.feesandfines.AccountRepository) LostItemPolicyRepository(org.folio.circulation.infrastructure.storage.loans.LostItemPolicyRepository) Clients.create(org.folio.circulation.support.Clients.create) Result.failed(org.folio.circulation.support.results.Result.failed) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) Account(org.folio.circulation.domain.Account) CommonFailures(org.folio.circulation.support.results.CommonFailures) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) Loan(org.folio.circulation.domain.Loan) MappingFunctions.toFixedValue(org.folio.circulation.support.results.MappingFunctions.toFixedValue) ValidationError(org.folio.circulation.support.http.server.ValidationError) Result(org.folio.circulation.support.results.Result) EventPublisher(org.folio.circulation.services.EventPublisher) NoContentResponse.noContent(org.folio.circulation.support.http.server.NoContentResponse.noContent) RouteRegistration(org.folio.circulation.support.RouteRegistration) Logger(org.apache.logging.log4j.Logger) StoreLoanAndItem(org.folio.circulation.StoreLoanAndItem) FeeFine.lostItemFeeTypes(org.folio.circulation.domain.FeeFine.lostItemFeeTypes) LogManager(org.apache.logging.log4j.LogManager) NoContentResponse(org.folio.circulation.support.http.server.NoContentResponse) HttpClient(io.vertx.core.http.HttpClient) WebContext(org.folio.circulation.support.http.server.WebContext) EventPublisher(org.folio.circulation.services.EventPublisher) CommonFailures(org.folio.circulation.support.results.CommonFailures)

Aggregations

HttpClient (io.vertx.core.http.HttpClient)4 Router (io.vertx.ext.web.Router)4 RoutingContext (io.vertx.ext.web.RoutingContext)4 ItemRepository (org.folio.circulation.infrastructure.storage.inventory.ItemRepository)4 LoanRepository (org.folio.circulation.infrastructure.storage.loans.LoanRepository)4 UserRepository (org.folio.circulation.infrastructure.storage.users.UserRepository)4 Clients (org.folio.circulation.support.Clients)4 RouteRegistration (org.folio.circulation.support.RouteRegistration)4 WebContext (org.folio.circulation.support.http.server.WebContext)4 CommonFailures (org.folio.circulation.support.results.CommonFailures)4 CompletableFuture (java.util.concurrent.CompletableFuture)3 ConfigurationRepository (org.folio.circulation.infrastructure.storage.ConfigurationRepository)3 NoContentResponse (org.folio.circulation.support.http.server.NoContentResponse)3 MappingFunctions.toFixedValue (org.folio.circulation.support.results.MappingFunctions.toFixedValue)3 Result (org.folio.circulation.support.results.Result)3 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 AccountRepository (org.folio.circulation.infrastructure.storage.feesandfines.AccountRepository)2 EventPublisher (org.folio.circulation.services.EventPublisher)2 AsynchronousResultBindings.safelyInitialise (org.folio.circulation.support.results.AsynchronousResultBindings.safelyInitialise)2