use of org.folio.rest.acq.model.finance.Ledger in project mod-invoice by folio-org.
the class MockServer method handleGetLedgerRecordsById.
private void handleGetLedgerRecordsById(RoutingContext ctx) {
// a3ec5552-c4a4-4a15-a57c-0046db536369
logger.info("handleGetLedgerRecordsById got: GET " + ctx.request().path());
String id = ctx.request().getParam(AbstractHelper.ID);
logger.info("id: " + id);
if (ID_FOR_INTERNAL_SERVER_ERROR.equals(id)) {
serverResponse(ctx, 500, APPLICATION_JSON, Response.Status.INTERNAL_SERVER_ERROR.getReasonPhrase());
} else {
List<Ledger> ledgers = null;
try {
ledgers = new JsonObject(getMockData(LEDGERS_PATH)).mapTo(LedgerCollection.class).getLedgers();
} catch (IOException e) {
ledgers = Collections.emptyList();
}
Optional<Ledger> ledger = ledgers.stream().filter(ledgerP -> ledgerP.getId().equals(id)).findAny();
if (!ledger.isPresent()) {
ledger = ledgers.stream().filter(ledgerP -> ledgerP.getId().equals(EXISTING_LEDGER_ID)).findAny();
}
ledger.get().setId(id);
JsonObject jsonLedger = JsonObject.mapFrom(ledger.get());
addServerRqRsData(HttpMethod.GET, LEDGERS, jsonLedger);
serverResponse(ctx, 200, APPLICATION_JSON, jsonLedger.encodePrettily());
}
}
use of org.folio.rest.acq.model.finance.Ledger in project mod-orders by folio-org.
the class EncumbranceRelationsHoldersBuilder method mapRestrictEncumbranceToHolders.
private List<EncumbranceRelationsHolder> mapRestrictEncumbranceToHolders(List<Ledger> ledgers, List<EncumbranceRelationsHolder> encumbranceHolders) {
Map<String, Ledger> idLedgerMap = ledgers.stream().collect(toMap(Ledger::getId, Function.identity()));
encumbranceHolders.stream().filter(holder -> Objects.nonNull(holder.getLedgerId())).forEach(holder -> {
Ledger ledger = idLedgerMap.get(holder.getLedgerId());
holder.withRestrictEncumbrances(Optional.ofNullable(ledger).map(Ledger::getRestrictEncumbrance).orElse(false));
});
return encumbranceHolders;
}
use of org.folio.rest.acq.model.finance.Ledger in project mod-orders by folio-org.
the class BudgetRestrictionServiceTest method checkEnoughMoneyInBudgetShouldPassIfTransactionsAmountDifferenceLessThanBudgetRemainingAmount.
@Test
void checkEnoughMoneyInBudgetShouldPassIfTransactionsAmountDifferenceLessThanBudgetRemainingAmount() {
String fiscalYearId = UUID.randomUUID().toString();
String fundId = UUID.randomUUID().toString();
String ledgerId = UUID.randomUUID().toString();
String budgetId = UUID.randomUUID().toString();
Transaction existingTransaction = new Transaction().withTransactionType(Transaction.TransactionType.ENCUMBRANCE).withAmount(50d).withFiscalYearId(fiscalYearId).withFromFundId(fundId).withCurrency("USD");
Transaction newTransaction = new Transaction().withTransactionType(Transaction.TransactionType.ENCUMBRANCE).withAmount(60d).withFiscalYearId(fiscalYearId).withFromFundId(fundId).withCurrency("USD");
Budget budget = new Budget().withId(budgetId).withFiscalYearId(fiscalYearId).withFundId(fundId).withAllocated(59d).withAvailable(9d).withTotalFunding(59d).withUnavailable(50d).withAwaitingPayment(50D).withAllowableEncumbrance(150d);
Fund fund = new Fund().withId(fundId).withLedgerId(ledgerId);
Ledger ledger = new Ledger().withId(ledgerId).withRestrictEncumbrance(true);
List<EncumbranceRelationsHolder> holders = new ArrayList<>();
EncumbranceRelationsHolder holder = new EncumbranceRelationsHolder().withOldEncumbrance(existingTransaction).withNewEncumbrance(newTransaction).withBudget(budget).withLedgerId(fund.getLedgerId()).withRestrictEncumbrances(ledger.getRestrictExpenditures()).withCurrentFiscalYearId(fiscalYearId).withCurrency("USD");
holders.add(holder);
assertDoesNotThrow(() -> restrictionService.checkEncumbranceRestrictions(holders));
}
use of org.folio.rest.acq.model.finance.Ledger in project mod-orders by folio-org.
the class MockServer method getLedgersByIds.
private JsonObject getLedgersByIds(List<String> ledgerByFundIds) {
Supplier<List<Ledger>> getFromFile = () -> {
try {
return new JsonObject(getMockData(LEDGERS_PATH)).mapTo(LedgerCollection.class).getLedgers();
} catch (IOException e) {
return Collections.emptyList();
}
};
List<Ledger> ledgers = getMockEntries(LEDGERS, Ledger.class).orElseGet(getFromFile);
if (!ledgerByFundIds.isEmpty()) {
ledgers.removeIf(item -> !ledgerByFundIds.contains(item.getId()));
}
Object record = new LedgerCollection().withLedgers(ledgers).withTotalRecords(ledgers.size());
return JsonObject.mapFrom(record);
}
use of org.folio.rest.acq.model.finance.Ledger in project mod-orders by folio-org.
the class EncumbranceRelationsHoldersBuilderTest method testShouldPopulateHoldersWithCorrespondingLedgerData.
@Test
void testShouldPopulateHoldersWithCorrespondingLedgerData() {
// given
Fund fund1 = new Fund().withId(holder1.getFundId()).withLedgerId(UUID.randomUUID().toString());
Fund fund2 = new Fund().withId(holder2.getFundId()).withLedgerId(UUID.randomUUID().toString());
Fund fund3 = new Fund().withId(holder3.getFundId()).withLedgerId(UUID.randomUUID().toString());
Ledger ledger1 = new Ledger().withId(fund1.getLedgerId()).withRestrictEncumbrance(true);
Ledger ledger2 = new Ledger().withId(fund2.getLedgerId()).withRestrictEncumbrance(true);
Ledger ledger3 = new Ledger().withId(fund3.getLedgerId()).withRestrictEncumbrance(false);
List<EncumbranceRelationsHolder> holders = new ArrayList<>();
holders.add(holder1);
holders.add(holder2);
holders.add(holder3);
when(fundService.getAllFunds(anyCollection(), any())).thenReturn(CompletableFuture.completedFuture(List.of(fund1, fund2, fund3)));
when(ledgerService.getLedgersByIds(anyCollection(), any())).thenReturn(CompletableFuture.completedFuture(List.of(ledger2, ledger1, ledger3)));
// When
encumbranceRelationsHoldersBuilder.withLedgersData(holders, requestContextMock).join();
// Then
assertEquals(ledger1.getId(), holder1.getLedgerId());
assertEquals(ledger1.getRestrictEncumbrance(), holder1.getRestrictEncumbrance());
assertEquals(ledger2.getId(), holder2.getLedgerId());
assertEquals(ledger2.getRestrictEncumbrance(), holder2.getRestrictEncumbrance());
assertEquals(ledger3.getId(), holder3.getLedgerId());
assertEquals(ledger3.getRestrictEncumbrance(), holder3.getRestrictEncumbrance());
}
Aggregations