Search in sources :

Example 1 with CompositeOrderRetrieveHolder

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());
}
Also used : TransactionCollection(org.folio.rest.acq.model.finance.TransactionCollection) FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) CompositeOrderRetrieveHolder(org.folio.models.CompositeOrderRetrieveHolder) Test(org.junit.jupiter.api.Test)

Example 2 with CompositeOrderRetrieveHolder

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();
}
Also used : InOrder(org.mockito.InOrder) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) CompositeOrderRetrieveHolder(org.folio.models.CompositeOrderRetrieveHolder) Test(org.junit.jupiter.api.Test)

Example 3 with CompositeOrderRetrieveHolder

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());
}
Also used : LedgerFiscalYearRolloverErrorCollection(org.folio.rest.acq.model.finance.LedgerFiscalYearRolloverErrorCollection) Fund(org.folio.rest.acq.model.finance.Fund) ReEncumbranceHolder(org.folio.models.ReEncumbranceHolder) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) LedgerFiscalYearRollover(org.folio.rest.jaxrs.model.LedgerFiscalYearRollover) CompositeOrderRetrieveHolder(org.folio.models.CompositeOrderRetrieveHolder) FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) LedgerFiscalYearRolloverCollection(org.folio.rest.jaxrs.model.LedgerFiscalYearRolloverCollection) LedgerFiscalYearRolloverProgress(org.folio.rest.acq.model.finance.LedgerFiscalYearRolloverProgress) LedgerFiscalYearRolloverError(org.folio.rest.acq.model.finance.LedgerFiscalYearRolloverError) Test(org.junit.jupiter.api.Test)

Example 4 with CompositeOrderRetrieveHolder

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;
}
Also used : OrderInvoiceRelationService(org.folio.service.orders.OrderInvoiceRelationService) EN(org.folio.rest.RestConstants.EN) StringUtils(org.apache.commons.lang3.StringUtils) PoLineCommonUtil(org.folio.orders.utils.PoLineCommonUtil) HelperUtils.verifyProtectedFieldsChanged(org.folio.orders.utils.HelperUtils.verifyProtectedFieldsChanged) OpenCompositeOrderFlowValidator(org.folio.service.orders.flows.update.open.OpenCompositeOrderFlowValidator) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) ORDER_CONFIG_MODULE_NAME(org.folio.orders.utils.HelperUtils.ORDER_CONFIG_MODULE_NAME) TagService(org.folio.service.TagService) POProtectedFields.getFieldNamesForOpenOrder(org.folio.orders.utils.POProtectedFields.getFieldNamesForOpenOrder) OrderStatusTransitionUtil.isTransitionToOpen(org.folio.orders.utils.OrderStatusTransitionUtil.isTransitionToOpen) MISSING_ONGOING(org.folio.rest.core.exceptions.ErrorCodes.MISSING_ONGOING) HelperUtils.convertToCompositePurchaseOrder(org.folio.orders.utils.HelperUtils.convertToCompositePurchaseOrder) OrderStatusTransitionUtil.isOrderReopening(org.folio.orders.utils.OrderStatusTransitionUtil.isOrderReopening) UnOpenCompositeOrderManager(org.folio.service.orders.flows.update.unopen.UnOpenCompositeOrderManager) WORKFLOW_STATUS(org.folio.orders.utils.HelperUtils.WORKFLOW_STATUS) Set(java.util.Set) ErrorCodes(org.folio.rest.core.exceptions.ErrorCodes) OrderStatusTransitionUtil.isOrderClosing(org.folio.orders.utils.OrderStatusTransitionUtil.isOrderClosing) HelperUtils.handleGetRequest(org.folio.orders.utils.HelperUtils.handleGetRequest) ConfigurationEntriesService(org.folio.service.configuration.ConfigurationEntriesService) OPEN(org.folio.rest.jaxrs.model.CompositePurchaseOrder.WorkflowStatus.OPEN) CompletionStage(java.util.concurrent.CompletionStage) Logger(org.apache.logging.log4j.Logger) CREATE(org.folio.orders.utils.ProtectedOperationType.CREATE) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) HttpClientInterface(org.folio.rest.tools.client.interfaces.HttpClientInterface) MAX_REPEAT_ON_FAILURE(org.folio.helper.AbstractHelper.MAX_REPEAT_ON_FAILURE) USER_HAS_NO_UNOPEN_PERMISSIONS(org.folio.rest.core.exceptions.ErrorCodes.USER_HAS_NO_UNOPEN_PERMISSIONS) UPDATE(org.folio.orders.utils.ProtectedOperationType.UPDATE) FolioVertxCompletableFuture(org.folio.completablefuture.FolioVertxCompletableFuture) OrderStatusTransitionUtil.isTransitionToClosed(org.folio.orders.utils.OrderStatusTransitionUtil.isTransitionToClosed) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) MAX_IDS_FOR_GET_RQ(org.folio.rest.RestConstants.MAX_IDS_FOR_GET_RQ) ResourcePathResolver.resourcesPath(org.folio.orders.utils.ResourcePathResolver.resourcesPath) APPROVAL_REQUIRED_TO_OPEN(org.folio.rest.core.exceptions.ErrorCodes.APPROVAL_REQUIRED_TO_OPEN) PO_LINE_NUMBER(org.folio.orders.utils.ResourcePathResolver.PO_LINE_NUMBER) HelperUtils(org.folio.orders.utils.HelperUtils) OrderStatusTransitionUtil.isTransitionToApproved(org.folio.orders.utils.OrderStatusTransitionUtil.isTransitionToApproved) OrderStatusTransitionUtil.isTransitionToReopen(org.folio.orders.utils.OrderStatusTransitionUtil.isTransitionToReopen) OKAPI_USERID_HEADER(org.folio.rest.RestVerticle.OKAPI_USERID_HEADER) COMPOSITE_PO_LINES(org.folio.orders.utils.HelperUtils.COMPOSITE_PO_LINES) HelperUtils.combineCqlExpressions(org.folio.orders.utils.HelperUtils.combineCqlExpressions) JsonArray(io.vertx.core.json.JsonArray) OpenCompositeOrderManager(org.folio.service.orders.flows.update.open.OpenCompositeOrderManager) HelperUtils.changeOrderStatus(org.folio.orders.utils.HelperUtils.changeOrderStatus) OrderWorkflowType(org.folio.service.orders.OrderWorkflowType) AcqDesiredPermissions(org.folio.orders.utils.AcqDesiredPermissions) ReOpenCompositeOrderManager(org.folio.service.orders.flows.update.reopen.ReOpenCompositeOrderManager) REASON_CANCELLED(org.folio.orders.utils.HelperUtils.REASON_CANCELLED) Date(java.util.Date) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) PurchaseOrderStorageService(org.folio.service.orders.PurchaseOrderStorageService) HelperUtils.collectResultsOnSuccess(org.folio.orders.utils.HelperUtils.collectResultsOnSuccess) USER_HAS_NO_REOPEN_PERMISSIONS(org.folio.rest.core.exceptions.ErrorCodes.USER_HAS_NO_REOPEN_PERMISSIONS) PoLine(org.folio.rest.jaxrs.model.PoLine) CollectionUtils.isEmpty(org.apache.commons.collections4.CollectionUtils.isEmpty) ASSIGN(org.folio.orders.utils.AcqDesiredPermissions.ASSIGN) MANAGE(org.folio.orders.utils.AcqDesiredPermissions.MANAGE) CompositeOrderRetrieveHolder(org.folio.models.CompositeOrderRetrieveHolder) ReceiptStatus(org.folio.rest.jaxrs.model.CompositePoLine.ReceiptStatus) ProtectionService(org.folio.service.ProtectionService) ListUtils(org.apache.commons.collections4.ListUtils) ONGOING_NOT_ALLOWED(org.folio.rest.core.exceptions.ErrorCodes.ONGOING_NOT_ALLOWED) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) Collection(java.util.Collection) SEARCH_PARAMS(org.folio.helper.AbstractHelper.SEARCH_PARAMS) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) CollectionUtils.isNotEmpty(org.apache.commons.collections4.CollectionUtils.isNotEmpty) PaymentStatus(org.folio.rest.jaxrs.model.CompositePoLine.PaymentStatus) CompositePoLineValidationService(org.folio.service.orders.CompositePoLineValidationService) StreamEx(one.util.streamex.StreamEx) EncumbranceService(org.folio.service.finance.transaction.EncumbranceService) Optional(java.util.Optional) Parameter(org.folio.rest.jaxrs.model.Parameter) CompositeOrderDynamicDataPopulateService(org.folio.service.orders.CompositeOrderDynamicDataPopulateService) AcquisitionsUnitsService(org.folio.service.AcquisitionsUnitsService) ProtectedOperationType(org.folio.orders.utils.ProtectedOperationType) HttpException(org.folio.rest.core.exceptions.HttpException) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) PENDING(org.folio.rest.jaxrs.model.CompositePurchaseOrder.WorkflowStatus.PENDING) USER_HAS_NO_ACQ_PERMISSIONS(org.folio.rest.core.exceptions.ErrorCodes.USER_HAS_NO_ACQ_PERMISSIONS) HashSet(java.util.HashSet) Title(org.folio.rest.jaxrs.model.Title) TitlesService(org.folio.service.titles.TitlesService) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) RequestContext(org.folio.rest.core.models.RequestContext) POProtectedFields.getFieldNames(org.folio.orders.utils.POProtectedFields.getFieldNames) HelperUtils.getPoLineLimit(org.folio.orders.utils.HelperUtils.getPoLineLimit) DELETE(org.folio.orders.utils.ProtectedOperationType.DELETE) EncumbranceWorkflowStrategyFactory(org.folio.service.finance.transaction.EncumbranceWorkflowStrategyFactory) InventoryManager(org.folio.service.inventory.InventoryManager) EncumbranceWorkflowStrategy(org.folio.service.finance.transaction.EncumbranceWorkflowStrategy) PURCHASE_ORDER_STORAGE(org.folio.orders.utils.ResourcePathResolver.PURCHASE_ORDER_STORAGE) Error(org.folio.rest.jaxrs.model.Error) Collectors.toList(java.util.stream.Collectors.toList) USER_HAS_NO_APPROVAL_PERMISSIONS(org.folio.rest.core.exceptions.ErrorCodes.USER_HAS_NO_APPROVAL_PERMISSIONS) HelperUtils.buildQuery(org.folio.orders.utils.HelperUtils.buildQuery) OrderStatusTransitionUtil.isTransitionToPending(org.folio.orders.utils.OrderStatusTransitionUtil.isTransitionToPending) PurchaseOrderCollection(org.folio.rest.jaxrs.model.PurchaseOrderCollection) HttpStatus(org.folio.HttpStatus) PurchaseOrderLineService(org.folio.service.orders.PurchaseOrderLineService) WorkflowStatus(org.folio.rest.jaxrs.model.CompositePurchaseOrder.WorkflowStatus) CompletableFutureRepeater(org.folio.completablefuture.CompletableFutureRepeater) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) FolioVertxCompletableFuture(org.folio.completablefuture.FolioVertxCompletableFuture) CompletableFuture(java.util.concurrent.CompletableFuture) HelperUtils(org.folio.orders.utils.HelperUtils) HelperUtils.convertToCompositePurchaseOrder(org.folio.orders.utils.HelperUtils.convertToCompositePurchaseOrder) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) CompositeOrderRetrieveHolder(org.folio.models.CompositeOrderRetrieveHolder)

Example 5 with CompositeOrderRetrieveHolder

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());
}
Also used : FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) CompletableFuture(java.util.concurrent.CompletableFuture) FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) CompletionException(java.util.concurrent.CompletionException) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) HttpException(org.folio.rest.core.exceptions.HttpException) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) CompositeOrderRetrieveHolder(org.folio.models.CompositeOrderRetrieveHolder) Test(org.junit.jupiter.api.Test)

Aggregations

CompositeOrderRetrieveHolder (org.folio.models.CompositeOrderRetrieveHolder)9 CompositePurchaseOrder (org.folio.rest.jaxrs.model.CompositePurchaseOrder)9 Test (org.junit.jupiter.api.Test)8 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)4 CompletableFuture (java.util.concurrent.CompletableFuture)3 FiscalYear (org.folio.rest.acq.model.finance.FiscalYear)3 HttpException (org.folio.rest.core.exceptions.HttpException)2 FundDistribution (org.folio.rest.jaxrs.model.FundDistribution)2 JsonArray (io.vertx.core.json.JsonArray)1 JsonObject (io.vertx.core.json.JsonObject)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1