Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CIRC-1556 Close declared lost loan (Lost and paid status) for actual cost #1159

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

Mykyta-Varenyk
Copy link
Contributor

@Mykyta-Varenyk Mykyta-Varenyk commented Jun 30, 2022

… been paid or enough time for charging has passed
…into CIRC-1556

� Conflicts:
�	src/main/java/org/folio/circulation/domain/ActualCostRecord.java
�	src/main/java/org/folio/circulation/infrastructure/storage/ActualCostRecordRepository.java
�	src/main/java/org/folio/circulation/resources/RequestFromRepresentationService.java
�	src/main/java/org/folio/circulation/storage/mappers/ActualCostRecordMapper.java
�	src/test/java/api/support/fixtures/FeeFineAccountFixture.java
@alexanderkurash alexanderkurash changed the title Circ 1556 CIRC-1556 Close declared lost and aged to lost loan (Lost and paid status) for actual cost Jul 6, 2022
final var loanRepository = new LoanRepository(clients, itemRepository, userRepository);
final var accountRepository = new AccountRepository(clients);
final var lostItemPolicyRepository = new LostItemPolicyRepository(clients);
private CompletableFuture<Result<Void>> processEvent(LoanRepository loanRepository,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move loanRepository.getById to the service, remove this method


public CloseLoanWithLostItemService(LoanRepository loanRepository, ItemRepository itemRepository,
AccountRepository accountRepository, LostItemPolicyRepository lostItemPolicyRepository,
EventPublisher eventPublisher, ActualCostRecordRepository actualCostRecordRepository) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty line

import static org.folio.circulation.support.utils.ClockUtil.getZoneId;
import static org.folio.circulation.support.utils.ClockUtil.getZonedDateTime;
public class CloseLoanWithLostItemService {
private final LoanRepository loanRepository;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty line

@@ -54,13 +51,19 @@ public void register(Router router) {

private void handleFeeFineClosedEvent(RoutingContext routingContext) {
final WebContext context = new WebContext(routingContext);
final EventPublisher eventPublisher = new EventPublisher(routingContext);
final var eventPublisher = new EventPublisher(routingContext);
final Clients clients = create(context, client);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var ?

Comment on lines 60 to 64
.flatMapFuture(accountRepository::findAccountsForLoans)
.flatMapFuture(lostItemPolicyRepository::findLostItemPoliciesForLoans)
.flatMapFuture(actualCostRecordRepository::fetchActualCostRecords)
.flatMapFuture(loans -> allOf(loans.getRecords(),
closeLoanWithLostItemService::tryCloseLoanForActualCostExpiration))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check this - do we take the Result status into account

return completedFuture(succeeded(loan));
}

boolean wasLoanOpen = loan.isOpen();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be checked earlier?


String expirationDate = actualCostRecord.getExpirationDate();

return expirationDate != null && getZonedDateTime().isAfter(DateFormatUtil.parseDateTime(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be parsed in ActualCostRecord

@roman-barannyk roman-barannyk changed the title CIRC-1556 Close declared lost and aged to lost loan (Lost and paid status) for actual cost CIRC-1556 Close declared lost loan (Lost and paid status) for actual cost Jul 14, 2022
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

89.9% 89.9% Coverage
0.0% 0.0% Duplication

Comment on lines +98 to +110
private CompletableFuture<Result<Map<String, ActualCostRecord>>> buildLoanIdToActualCostRecordMap(
Collection<Loan> loans) {

final Set<String> loanIds = loans.stream()
.filter(Objects::nonNull)
.map(Loan::getId)
.filter(Objects::nonNull)
.collect(Collectors.toSet());

return findWithMultipleCqlIndexValues(actualCostRecordStorageClient,
ACTUAL_COST_RECORDS, ActualCostRecordMapper::toDomain)
.find(byIndex(LOAN_ID_FIELD_NAME, loanIds))
.thenApply(mapResult(r -> r.toMap(ActualCostRecord::getLoanId)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to one method

Comment on lines +79 to +83
return loanResult.after(loan -> createActualCostRecordCqlFinder().findByQuery(
exactMatch(LOAN_ID_FIELD_NAME, loan.getId()), one())
.thenApply(records -> records.map(MultipleRecords::firstOrNull))
.thenApply(mapResult(ActualCostRecordMapper::toDomain))
.thenApply(mapResult(loan::withActualCostRecord)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call fetchActualCostRecords with one loan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants