-
Notifications
You must be signed in to change notification settings - Fork 25
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
base: master
Are you sure you want to change the base?
Conversation
… 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
src/main/java/org/folio/circulation/domain/policy/lostitem/LostItemPolicy.java
Outdated
Show resolved
Hide resolved
src/main/java/org/folio/circulation/infrastructure/storage/ActualCostRecordRepository.java
Outdated
Show resolved
Hide resolved
src/main/java/org/folio/circulation/infrastructure/storage/ActualCostRecordRepository.java
Outdated
Show resolved
Hide resolved
src/main/java/org/folio/circulation/infrastructure/storage/ActualCostRecordRepository.java
Outdated
Show resolved
Hide resolved
src/main/java/org/folio/circulation/infrastructure/storage/ActualCostRecordRepository.java
Outdated
Show resolved
Hide resolved
src/main/java/org/folio/circulation/infrastructure/storage/ActualCostRecordRepository.java
Outdated
Show resolved
Hide resolved
src/main/java/org/folio/circulation/infrastructure/storage/ActualCostRecordRepository.java
Outdated
Show resolved
Hide resolved
src/main/java/org/folio/circulation/infrastructure/storage/inventory/ItemRepository.java
Outdated
Show resolved
Hide resolved
src/main/java/org/folio/circulation/infrastructure/storage/inventory/ItemRepository.java
Outdated
Show resolved
Hide resolved
src/main/java/org/folio/circulation/resources/ExpiredActualCostProcessingResource.java
Outdated
Show resolved
Hide resolved
src/main/java/org/folio/circulation/resources/ExpiredActualCostProcessingResource.java
Outdated
Show resolved
Hide resolved
src/main/java/org/folio/circulation/resources/ExpiredActualCostProcessingResource.java
Show resolved
Hide resolved
… CIRC-1556 � Conflicts: � src/main/java/org/folio/circulation/infrastructure/storage/inventory/ItemRepository.java
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, |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var ?
.flatMapFuture(accountRepository::findAccountsForLoans) | ||
.flatMapFuture(lostItemPolicyRepository::findLostItemPoliciesForLoans) | ||
.flatMapFuture(actualCostRecordRepository::fetchActualCostRecords) | ||
.flatMapFuture(loans -> allOf(loans.getRecords(), | ||
closeLoanWithLostItemService::tryCloseLoanForActualCostExpiration)) |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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
Kudos, SonarCloud Quality Gate passed! |
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))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to one method
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))); |
There was a problem hiding this comment.
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
Resolves: https://issues.folio.org/browse/CIRC-1556