in api/src/main/java/org/apache/fineract/cn/accounting/api/v1/client/LedgerManager.java [245:278]
default Stream<AccountEntry> fetchAccountEntriesStream(
final String accountIdentifier,
final String dateRange,
final String message,
final String sortDirection) {
final AccountEntryPage firstPage = this.fetchAccountEntries(
accountIdentifier,
dateRange,
message,
0,
10,
null,
null);
final Integer pageCount = firstPage.getTotalPages();
switch (sortDirection) {
case "ASC":
// Sort column is always date and order always ascending so that the order and adjacency of account
// entries is always stable. This has the advantage that the set of account entries included in the
// stream is set the moment the first call to fetchAccountEntries (above) is made.
return Stream.iterate(0, (i) -> i + 1).limit(pageCount)
.map(i -> this.fetchAccountEntries(accountIdentifier, dateRange, message, i, 10, "transactionDate", "ASC"))
.flatMap(pageI -> pageI.getAccountEntries().stream());
case "DESC":
return Stream.iterate(pageCount - 1, (i) -> i - 1).limit(pageCount)
.map(i -> this.fetchAccountEntries(accountIdentifier, dateRange, message, i, 10, "transactionDate", "ASC"))
.flatMap(pageI -> {
Collections.reverse(pageI.getAccountEntries());
return pageI.getAccountEntries().stream();
});
default:
throw new IllegalArgumentException();
}
}