-
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
Open
Mykyta-Varenyk
wants to merge
21
commits into
master
Choose a base branch
from
CIRC-1556
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
46ed0c6
CIRC-1556 When actual cost is selected, close the loan only if it has…
Mykyta-Varenyk 11a57a2
CIRC-1556 Create actual cost expiration timer
Mykyta-Varenyk b7b6f3d
Merge branch 'master' of https://github.com/folio-org/mod-circulation…
Mykyta-Varenyk 03d72da
Fix conflicts
Mykyta-Varenyk 4097f26
CIRC-1556 Fix comments
Mykyta-Varenyk f3ff403
CIRC-1556 Refactor
Mykyta-Varenyk 3e2b0dc
CIRC-1556 Add module permissions
Mykyta-Varenyk 7353375
CIRC-1556 refactoring
roman-barannyk b600334
CIRC-1556 fix code smells
roman-barannyk 574d5de
CIRC-1556 Extend ItemRelatedRecord
alexanderkurash 55acdb5
CIRC-1556 refactoring according to code review
roman-barannyk 508e5bf
Merge branch 'CIRC-1556' of github.com:folio-org/mod-circulation into…
roman-barannyk 69f0cad
CIRC-1556 refactoring according to code review
roman-barannyk 382f457
CIRC-1556 fix code smell
roman-barannyk 8274392
CIRC-1556 fix code smell
roman-barannyk b202b6e
CIRC-1557 Refactor close loan service
alexanderkurash 6205170
CIRC-1557 refactoring after code review
roman-barannyk ad237f3
CIRC-1557 remove code smells
roman-barannyk 01e300c
CIRC-1557 remove unused imports
roman-barannyk 2b0ddf6
CIRC-1557 refactoring after code review
roman-barannyk 0f3057c
CIRC-1557 remove unused import
roman-barannyk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
|
||
public interface ItemRelatedRecord { | ||
String getItemId(); | ||
ItemRelatedRecord withItem(Item item); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,45 @@ | ||
package org.folio.circulation.infrastructure.storage; | ||
|
||
import static java.util.concurrent.CompletableFuture.completedFuture; | ||
import static java.util.function.Function.identity; | ||
import static org.folio.circulation.support.fetching.MultipleCqlIndexValuesCriteria.byIndex; | ||
import static org.folio.circulation.support.fetching.RecordFetching.findWithMultipleCqlIndexValues; | ||
import static org.folio.circulation.support.http.ResponseMapping.forwardOnFailure; | ||
import static org.folio.circulation.support.http.ResponseMapping.mapUsingJson; | ||
import static org.folio.circulation.support.http.client.CqlQuery.exactMatch; | ||
import static org.folio.circulation.support.http.client.PageLimit.one; | ||
import static org.folio.circulation.support.results.Result.ofAsync; | ||
import static org.folio.circulation.support.results.Result.succeeded; | ||
import static org.folio.circulation.support.results.ResultBinding.mapResult; | ||
|
||
import java.util.Collection; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.stream.Collectors; | ||
|
||
import org.folio.circulation.domain.ActualCostRecord; | ||
import org.folio.circulation.domain.Loan; | ||
import org.folio.circulation.domain.MultipleRecords; | ||
import org.folio.circulation.storage.mappers.ActualCostRecordMapper; | ||
import org.folio.circulation.support.Clients; | ||
import org.folio.circulation.support.CollectionResourceClient; | ||
import org.folio.circulation.support.fetching.CqlQueryFinder; | ||
import org.folio.circulation.support.http.client.CqlQuery; | ||
import org.folio.circulation.support.http.client.PageLimit; | ||
import org.folio.circulation.support.http.client.Response; | ||
import org.folio.circulation.support.http.client.ResponseInterpreter; | ||
import org.folio.circulation.support.results.Result; | ||
|
||
import io.vertx.core.json.JsonObject; | ||
|
||
public class ActualCostRecordRepository { | ||
private final CollectionResourceClient actualCostRecordStorageClient; | ||
|
||
private static final String ACTUAL_COST_RECORDS = "actualCostRecords"; | ||
private static final String LOAN_ID_FIELD_NAME = "loanId"; | ||
|
||
public ActualCostRecordRepository(Clients clients) { | ||
actualCostRecordStorageClient = clients.actualCostRecordsStorage(); | ||
} | ||
|
@@ -52,6 +72,47 @@ public CompletableFuture<Result<ActualCostRecord>> getActualCostRecordByAccountI | |
} | ||
|
||
private Result<MultipleRecords<ActualCostRecord>> mapResponseToActualCostRecords(Response response) { | ||
return MultipleRecords.from(response, ActualCostRecordMapper::toDomain, "actualCostRecords"); | ||
return MultipleRecords.from(response, ActualCostRecordMapper::toDomain, ACTUAL_COST_RECORDS); | ||
} | ||
|
||
public CompletableFuture<Result<Loan>> findByLoan(Result<Loan> loanResult) { | ||
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))); | ||
} | ||
|
||
public CompletableFuture<Result<MultipleRecords<Loan>>> fetchActualCostRecords( | ||
MultipleRecords<Loan> multipleLoans) { | ||
|
||
if (multipleLoans.getRecords().isEmpty()) { | ||
return completedFuture(succeeded(multipleLoans)); | ||
} | ||
|
||
return buildLoanIdToActualCostRecordMap(multipleLoans.getRecords()) | ||
.thenApply(r -> r.map(actualCostRecordMap -> multipleLoans.mapRecords( | ||
loan -> loan.withActualCostRecord(actualCostRecordMap.getOrDefault(loan.getId(), null))))); | ||
} | ||
|
||
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))); | ||
Comment on lines
+98
to
+110
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move to one method |
||
} | ||
|
||
private CqlQueryFinder<JsonObject> createActualCostRecordCqlFinder() { | ||
return new CqlQueryFinder<>(actualCostRecordStorageClient, ACTUAL_COST_RECORDS, | ||
identity()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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