use of org.folio.circulation.infrastructure.storage.feesandfines.AccountRepository in project mod-circulation by folio-org.
the class LoanCollectionResource method get.
@Override
void get(RoutingContext routingContext) {
final WebContext context = new WebContext(routingContext);
final Clients clients = Clients.create(context, client);
final var userRepository = new UserRepository(clients);
final var loanRepository = new LoanRepository(clients, new ItemRepository(clients), userRepository);
final ServicePointRepository servicePointRepository = new ServicePointRepository(clients);
final LoanRepresentation loanRepresentation = new LoanRepresentation();
final LoanPolicyRepository loanPolicyRepository = new LoanPolicyRepository(clients);
final OverdueFinePolicyRepository overdueFinePolicyRepository = new OverdueFinePolicyRepository(clients);
final LostItemPolicyRepository lostItemPolicyRepository = new LostItemPolicyRepository(clients);
final AccountRepository accountRepository = new AccountRepository(clients);
final PatronGroupRepository patronGroupRepository = new PatronGroupRepository(clients);
String id = routingContext.request().getParam("id");
loanRepository.getById(id).thenComposeAsync(accountRepository::findAccountsAndActionsForLoan).thenComposeAsync(servicePointRepository::findServicePointsForLoan).thenComposeAsync(userRepository::findUserForLoan).thenComposeAsync(loanPolicyRepository::findPolicyForLoan).thenComposeAsync(overdueFinePolicyRepository::findOverdueFinePolicyForLoan).thenComposeAsync(lostItemPolicyRepository::findLostItemPolicyForLoan).thenComposeAsync(patronGroupRepository::findGroupForLoan).thenApply(loanResult -> loanResult.map(loanRepresentation::extendedLoan)).thenApply(r -> r.map(JsonHttpResponse::ok)).thenAccept(context::writeResultToHttpResponse);
}
use of org.folio.circulation.infrastructure.storage.feesandfines.AccountRepository 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.infrastructure.storage.feesandfines.AccountRepository in project mod-circulation by folio-org.
the class OverdueFineServiceTest method setUp.
@BeforeEach
public void setUp() {
overdueFinePolicyRepository = mock(OverdueFinePolicyRepository.class);
accountRepository = mock(AccountRepository.class);
itemRepository = mock(ItemRepository.class);
feeFineOwnerRepository = mock(FeeFineOwnerRepository.class);
feeFineRepository = mock(FeeFineRepository.class);
overduePeriodCalculatorService = mock(OverduePeriodCalculatorService.class);
UserRepository userRepository = mock(UserRepository.class);
feeFineActionRepository = mock(FeeFineActionRepository.class);
scheduledNoticesRepository = mock(ScheduledNoticesRepository.class);
servicePointRepository = mock(ServicePointRepository.class);
FeeFineService feeFineService = mock(FeeFineService.class);
FeeFineFacade feeFineFacade = new FeeFineFacade(accountRepository, feeFineActionRepository, userRepository, servicePointRepository, feeFineService);
overdueFineService = new OverdueFineService(overdueFinePolicyRepository, itemRepository, feeFineOwnerRepository, feeFineRepository, scheduledNoticesRepository, overduePeriodCalculatorService, feeFineFacade);
when(userRepository.getUser(any(String.class))).thenReturn(completedFuture(succeeded(LOGGED_IN_USER)));
}
use of org.folio.circulation.infrastructure.storage.feesandfines.AccountRepository 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);
}
use of org.folio.circulation.infrastructure.storage.feesandfines.AccountRepository in project mod-circulation by folio-org.
the class LoanCollectionResource method getMany.
@Override
void getMany(RoutingContext routingContext) {
WebContext context = new WebContext(routingContext);
Clients clients = Clients.create(context, client);
final var userRepository = new UserRepository(clients);
final var itemRepository = new ItemRepository(clients);
final var loanRepository = new LoanRepository(clients, itemRepository, userRepository);
final ServicePointRepository servicePointRepository = new ServicePointRepository(clients);
final LoanRepresentation loanRepresentation = new LoanRepresentation();
final LoanPolicyRepository loanPolicyRepository = new LoanPolicyRepository(clients);
final OverdueFinePolicyRepository overdueFinePolicyRepository = new OverdueFinePolicyRepository(clients);
final LostItemPolicyRepository lostItemPolicyRepository = new LostItemPolicyRepository(clients);
final AccountRepository accountRepository = new AccountRepository(clients);
final PatronGroupRepository patronGroupRepository = new PatronGroupRepository(clients);
loanRepository.findBy(routingContext.request().query()).thenCompose(multiLoanRecordsResult -> multiLoanRecordsResult.after(accountRepository::findAccountsForLoans)).thenCompose(multiLoanRecordsResult -> multiLoanRecordsResult.after(servicePointRepository::findServicePointsForLoans)).thenCompose(multiLoanRecordsResult -> multiLoanRecordsResult.after(userRepository::findUsersForLoans)).thenCompose(multiLoanRecordsResult -> multiLoanRecordsResult.after(loanPolicyRepository::findLoanPoliciesForLoans)).thenCompose(multiLoanRecordsResult -> multiLoanRecordsResult.after(overdueFinePolicyRepository::findOverdueFinePoliciesForLoans)).thenCompose(multiLoanRecordsResult -> multiLoanRecordsResult.after(lostItemPolicyRepository::findLostItemPoliciesForLoans)).thenCompose(multiLoanRecordsResult -> multiLoanRecordsResult.after(patronGroupRepository::findPatronGroupsByIds)).thenApply(multipleLoanRecordsResult -> multipleLoanRecordsResult.map(loans -> loans.asJson(loanRepresentation::extendedLoan, "loans"))).thenApply(r -> r.map(JsonHttpResponse::ok)).thenAccept(context::writeResultToHttpResponse);
}
Aggregations