use of org.folio.models.CompositeOrderRetrieveHolder in project mod-orders by folio-org.
the class TransactionsTotalFieldsPopulateServiceTest method shouldPopulateTotalEncumberedAndTotalExpendedFieldsWithZeroWhenTransactionsNotFound.
@Test
void shouldPopulateTotalEncumberedAndTotalExpendedFieldsWithZeroWhenTransactionsNotFound() {
CompositePurchaseOrder order = new CompositePurchaseOrder().withId(UUID.randomUUID().toString());
CompositeOrderRetrieveHolder holder = new CompositeOrderRetrieveHolder(order).withFiscalYear(new FiscalYear().withId(UUID.randomUUID().toString()));
when(transactionService.getTransactions(anyString(), anyInt(), anyInt(), any())).thenReturn(CompletableFuture.completedFuture(new TransactionCollection()));
CompositeOrderRetrieveHolder resultHolder = populateService.populate(holder, requestContext).join();
assertEquals(0d, resultHolder.getOrder().getTotalExpended());
}
use of org.folio.models.CompositeOrderRetrieveHolder in project mod-orders by folio-org.
the class CombinedOrderDataPopulateServiceTest method shouldShouldCallPopulateServiceAfterHolderDataIsPopulated.
@Test
void shouldShouldCallPopulateServiceAfterHolderDataIsPopulated() {
CompositePurchaseOrder order = new CompositePurchaseOrder().withId(UUID.randomUUID().toString());
CompositeOrderRetrieveHolder holder = new CompositeOrderRetrieveHolder(order);
when(holderBuilder.withCurrentFiscalYear(any(), any())).thenReturn(CompletableFuture.completedFuture(holder));
populateService.populate(holder, requestContext).join();
InOrder inOrder = inOrder(holderBuilder, populateServices);
inOrder.verify(holderBuilder).withCurrentFiscalYear(any(), any());
inOrder.verify(populateServices).stream();
}
use of org.folio.models.CompositeOrderRetrieveHolder in project mod-orders by folio-org.
the class OrderReEncumberServiceTest method testPopulateNeedReEncumberField.
@Test
void testPopulateNeedReEncumberField() {
// given
CompositePurchaseOrder order = getMockAsJson(ORDER_PATH).mapTo(CompositePurchaseOrder.class);
String ledgerId = UUID.randomUUID().toString();
Fund sampleFund = new Fund().withLedgerId(UUID.randomUUID().toString()).withFundStatus(Fund.FundStatus.ACTIVE).withCode(UUID.randomUUID().toString());
LedgerFiscalYearRollover rollover = new LedgerFiscalYearRollover().withId(UUID.randomUUID().toString()).withLedgerId(ledgerId);
LedgerFiscalYearRolloverErrorCollection ledgerFiscalYearRolloverErrors = new LedgerFiscalYearRolloverErrorCollection().withLedgerFiscalYearRolloverErrors(Collections.singletonList(new LedgerFiscalYearRolloverError()));
CompositePoLine line = order.getCompositePoLines().get(0);
FundDistribution fundDistribution1 = line.getFundDistribution().get(0);
String fiscalYearId = UUID.randomUUID().toString();
ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withPurchaseOrder(order).withPoLine(line).withFundDistribution(fundDistribution1).withRollover(rollover).withLedgerId(ledgerId).withCurrentFiscalYearId(fiscalYearId);
FundDistribution fundDistribution2 = line.getFundDistribution().get(1);
ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withPurchaseOrder(order).withPoLine(order.getCompositePoLines().get(0)).withFundDistribution(fundDistribution2).withRollover(rollover).withLedgerId(ledgerId).withCurrentFiscalYearId(fiscalYearId);
FundDistribution fundDistribution3 = line.getFundDistribution().get(1);
ReEncumbranceHolder holder3 = new ReEncumbranceHolder().withPurchaseOrder(order).withPoLine(order.getCompositePoLines().get(0)).withFundDistribution(fundDistribution3).withRollover(rollover).withLedgerId(ledgerId).withCurrentFiscalYearId(fiscalYearId);
List<LedgerFiscalYearRolloverProgress> progresses = Collections.singletonList(success);
List<ReEncumbranceHolder> holders = List.of(holder1, holder2, holder3);
// LedgerFiscalYearRolloverErrorCollection is not empty. Expected "needReEncumber" = true
doReturn(holders).when(spyReEncumbranceHoldersBuilder).buildReEncumbranceHoldersWithOrdersData(any());
doReturn(completedFuture(holders)).when(spyReEncumbranceHoldersBuilder).withFundsData(any(), any());
doReturn(completedFuture(holders)).when(spyReEncumbranceHoldersBuilder).withCurrentFiscalYearData(any(), any());
doReturn(completedFuture(holders)).when(spyReEncumbranceHoldersBuilder).withRollovers(any(), any());
doReturn(completedFuture(progresses)).when(rolloverRetrieveService).getRolloversProgress(anyString(), any());
doReturn(completedFuture(ledgerFiscalYearRolloverErrors)).when(rolloverErrorService).getLedgerFyRolloverErrors(any(), any());
CompositeOrderRetrieveHolder holder = new CompositeOrderRetrieveHolder(order);
CompositePurchaseOrder compOrder = orderReEncumberService.populate(holder, requestContext).join().getOrder();
assertTrue(compOrder.getNeedReEncumber());
// LedgerFiscalYearRolloverErrorCollection is empty. Expected "needReEncumber" = false
doReturn(completedFuture(new LedgerFiscalYearRolloverErrorCollection())).when(rolloverErrorService).getLedgerFyRolloverErrors(any(), any());
compOrder = orderReEncumberService.populate(holder, requestContext).join().getOrder();
assertFalse(compOrder.getNeedReEncumber());
// LedgerFyRollover not exists. Expected "needReEncumber" = false
doReturn(completedFuture(new LedgerFiscalYearRolloverCollection())).when(rolloverRetrieveService).getLedgerFyRollovers(anyString(), anyString(), any());
compOrder = orderReEncumberService.populate(holder, requestContext).join().getOrder();
assertFalse(compOrder.getNeedReEncumber());
}
use of org.folio.models.CompositeOrderRetrieveHolder in project mod-orders by folio-org.
the class PurchaseOrderHelper method getCompositeOrder.
/**
* Gets purchase order by id
*
* @param orderId purchase order uuid
* @return completable future with {@link CompositePurchaseOrder} on success or an exception if processing fails
*/
public CompletableFuture<CompositePurchaseOrder> getCompositeOrder(String orderId, RequestContext requestContext) {
CompletableFuture<CompositePurchaseOrder> future = new CompletableFuture<>();
purchaseOrderStorageService.getPurchaseOrderByIdAsJson(orderId, requestContext).thenApply(HelperUtils::convertToCompositePurchaseOrder).thenAccept(compPO -> protectionService.isOperationRestricted(compPO.getAcqUnitIds(), ProtectedOperationType.READ, requestContext).thenAccept(ok -> purchaseOrderLineService.populateOrderLines(compPO, requestContext).thenCompose(compPOWithLines -> titlesService.fetchNonPackageTitles(compPOWithLines, requestContext)).thenAccept(linesIdTitles -> populateInstanceId(linesIdTitles, compPO.getCompositePoLines())).thenCompose(po -> combinedPopulateService.populate(new CompositeOrderRetrieveHolder(compPO), requestContext)).thenApply(CompositeOrderRetrieveHolder::getOrder).thenAccept(future::complete).exceptionally(t -> {
logger.error("Failed to get lines for order with id={}", orderId, t.getCause());
future.completeExceptionally(t);
return null;
})).exceptionally(t -> {
logger.error("User with id={} is forbidden to view order with id={}", getCurrentUserId(requestContext), orderId, t.getCause());
future.completeExceptionally(t);
return null;
})).exceptionally(t -> {
logger.error("Failed to build composite purchase order with id={}", orderId, t.getCause());
future.completeExceptionally(t);
return null;
});
return future;
}
use of org.folio.models.CompositeOrderRetrieveHolder in project mod-orders by folio-org.
the class CompositeOrderRetrieveHolderBuilderTest method shouldFailWhenWhenRetrieveFiscalYearReturnsDifferentFrom404Status.
@Test
void shouldFailWhenWhenRetrieveFiscalYearReturnsDifferentFrom404Status() {
FundDistribution fundDistribution = new FundDistribution().withFundId(UUID.randomUUID().toString());
CompositePoLine poLine = new CompositePoLine().withFundDistribution(List.of(fundDistribution));
CompositePurchaseOrder order = new CompositePurchaseOrder().withId(UUID.randomUUID().toString()).withCompositePoLines(Collections.singletonList(poLine));
CompositeOrderRetrieveHolder holder = new CompositeOrderRetrieveHolder(order);
CompletableFuture<FiscalYear> failedFuture = new CompletableFuture<>();
HttpException thrownException = new HttpException(500, ErrorCodes.GENERIC_ERROR_CODE);
failedFuture.completeExceptionally(thrownException);
when(fiscalYearService.getCurrentFiscalYearByFundId(anyString(), any())).thenReturn(failedFuture);
CompletionException exception = assertThrows(CompletionException.class, () -> holderBuilder.withCurrentFiscalYear(holder, requestContext).join());
assertEquals(thrownException, exception.getCause());
}
Aggregations