Search in sources :

Example 16 with RequestEntry

use of org.folio.rest.core.models.RequestEntry in project mod-invoice by folio-org.

the class BudgetExpenseClassService method checkExpenseClass.

private CompletableFuture<Void> checkExpenseClass(InvoiceWorkflowDataHolder holder, RequestContext requestContext) {
    Budget budget = holder.getBudget();
    FundDistribution fundDistribution = holder.getFundDistribution();
    String query = String.format("budgetId==%s and expenseClassId==%s", budget.getId(), fundDistribution.getExpenseClassId());
    RequestEntry requestEntry = new RequestEntry(BUDGET_EXPENSE_CLASS_ENDPOINT).withQuery(query).withOffset(0).withLimit(1);
    return restClient.get(requestEntry, requestContext, BudgetExpenseClassCollection.class).thenAccept(budgetExpenseClasses -> {
        checkExpenseClassAssignedToBudget(holder, budgetExpenseClasses);
        checkExpenseClassActive(holder, budgetExpenseClasses);
    });
}
Also used : FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) Budget(org.folio.rest.acq.model.finance.Budget) RequestEntry(org.folio.rest.core.models.RequestEntry) BudgetExpenseClassCollection(org.folio.rest.acq.model.finance.BudgetExpenseClassCollection)

Example 17 with RequestEntry

use of org.folio.rest.core.models.RequestEntry in project mod-invoice by folio-org.

the class ExpenseClassRetrieveService method getExpenseClassById.

public CompletableFuture<ExpenseClass> getExpenseClassById(String id, RequestContext requestContext) {
    RequestEntry requestEntry = new RequestEntry(EXPENSE_CLASS_BY_ID_ENDPOINT).withId(id);
    return restClient.get(requestEntry, requestContext, ExpenseClass.class).exceptionally(t -> {
        Throwable cause = t.getCause() == null ? t : t.getCause();
        if (HelperUtils.isNotFound(cause)) {
            List<Parameter> parameters = Collections.singletonList(new Parameter().withValue(id).withKey("expenseClass"));
            cause = new HttpException(404, EXPENSE_CLASS_NOT_FOUND.toError().withParameters(parameters));
        }
        throw new CompletionException(cause);
    });
}
Also used : ExpenseClass(org.folio.rest.acq.model.finance.ExpenseClass) CompletionException(java.util.concurrent.CompletionException) Parameter(org.folio.rest.jaxrs.model.Parameter) HttpException(org.folio.invoices.rest.exceptions.HttpException) RequestEntry(org.folio.rest.core.models.RequestEntry)

Example 18 with RequestEntry

use of org.folio.rest.core.models.RequestEntry in project mod-orders by folio-org.

the class InvoiceLineServiceTest method shouldRemoveEncumbranceLinks.

@Test
void shouldRemoveEncumbranceLinks() {
    // Given
    String poLineId1 = UUID.randomUUID().toString();
    String poLineId2 = UUID.randomUUID().toString();
    String encumbrance1Id = UUID.randomUUID().toString();
    String encumbrance2Id = UUID.randomUUID().toString();
    String encumbrance3Id = UUID.randomUUID().toString();
    List<String> transactionIds = List.of(encumbrance1Id, encumbrance2Id, encumbrance3Id);
    String invoiceLineId1 = UUID.randomUUID().toString();
    InvoiceLine invoiceLine1 = new InvoiceLine().withId(invoiceLineId1).withPoLineId(poLineId1).withFundDistributions(List.of(new org.folio.rest.acq.model.invoice.FundDistribution().withEncumbrance(encumbrance1Id))).withAdjustments(List.of(new Adjustment().withFundDistributions(List.of(new org.folio.rest.acq.model.invoice.FundDistribution().withEncumbrance(encumbrance2Id)))));
    String invoiceLineId2 = UUID.randomUUID().toString();
    InvoiceLine invoiceLine2 = new InvoiceLine().withId(invoiceLineId2).withPoLineId(poLineId2).withAdjustments(List.of(new Adjustment().withFundDistributions(List.of(new org.folio.rest.acq.model.invoice.FundDistribution().withEncumbrance(encumbrance3Id)))));
    List<InvoiceLine> invoiceLines = List.of(invoiceLine1, invoiceLine2);
    InvoiceLine expectedInvoiceLine1 = JsonObject.mapFrom(invoiceLine1).mapTo(InvoiceLine.class);
    expectedInvoiceLine1.getFundDistributions().get(0).setEncumbrance(null);
    expectedInvoiceLine1.getAdjustments().get(0).getFundDistributions().get(0).setEncumbrance(null);
    InvoiceLine expectedInvoiceLine2 = JsonObject.mapFrom(invoiceLine2).mapTo(InvoiceLine.class);
    expectedInvoiceLine2.getAdjustments().get(0).getFundDistributions().get(0).setEncumbrance(null);
    when(restClient.put(any(RequestEntry.class), any(InvoiceLine.class), eq(requestContextMock))).thenReturn(CompletableFuture.completedFuture(null));
    when(requestContextMock.getContext()).thenReturn(Vertx.vertx().getOrCreateContext());
    // When
    CompletableFuture<Void> result = invoiceLineService.removeEncumbranceLinks(invoiceLines, transactionIds, requestContextMock);
    assertFalse(result.isCompletedExceptionally());
    result.join();
    // Then
    verify(restClient, times(1)).put(argThat(requestEntry -> invoiceLineId1.equals(requestEntry.getPathParams().get("id"))), eq(expectedInvoiceLine1), eq(requestContextMock));
    verify(restClient, times(1)).put(argThat(requestEntry -> invoiceLineId2.equals(requestEntry.getPathParams().get("id"))), eq(expectedInvoiceLine2), eq(requestContextMock));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) RestClient(org.folio.rest.core.RestClient) BeforeEach(org.junit.jupiter.api.BeforeEach) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CompletableFuture(java.util.concurrent.CompletableFuture) MockitoAnnotations(org.mockito.MockitoAnnotations) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) InvoiceLineCollection(org.folio.rest.acq.model.invoice.InvoiceLineCollection) RequestContext(org.folio.rest.core.models.RequestContext) JsonObject(io.vertx.core.json.JsonObject) InjectMocks(org.mockito.InjectMocks) Vertx(io.vertx.core.Vertx) RequestEntry(org.folio.rest.core.models.RequestEntry) Mockito.times(org.mockito.Mockito.times) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Adjustment(org.folio.rest.acq.model.invoice.Adjustment) HelperUtils.encodeQuery(org.folio.orders.utils.HelperUtils.encodeQuery) InvoiceLine(org.folio.rest.acq.model.invoice.InvoiceLine) LogManager(org.apache.logging.log4j.LogManager) Adjustment(org.folio.rest.acq.model.invoice.Adjustment) InvoiceLine(org.folio.rest.acq.model.invoice.InvoiceLine) RequestEntry(org.folio.rest.core.models.RequestEntry) Test(org.junit.jupiter.api.Test)

Example 19 with RequestEntry

use of org.folio.rest.core.models.RequestEntry in project mod-orders by folio-org.

the class TransactionSummariesService method createOrderTransactionSummary.

public CompletableFuture<OrderTransactionSummary> createOrderTransactionSummary(String id, int number, RequestContext requestContext) {
    OrderTransactionSummary summary = new OrderTransactionSummary().withId(id).withNumTransactions(number);
    RequestEntry requestEntry = new RequestEntry(ENDPOINT);
    return restClient.post(requestEntry, summary, requestContext, OrderTransactionSummary.class);
}
Also used : RequestEntry(org.folio.rest.core.models.RequestEntry) OrderTransactionSummary(org.folio.rest.acq.model.finance.OrderTransactionSummary)

Example 20 with RequestEntry

use of org.folio.rest.core.models.RequestEntry in project mod-orders by folio-org.

the class InventoryManager method getOrCreateHoldingsRecord.

public CompletableFuture<String> getOrCreateHoldingsRecord(String instanceId, Location location, RequestContext requestContext) {
    if (location.getHoldingId() != null) {
        Context ctx = requestContext.getContext();
        String tenantId = TenantTool.tenantId(requestContext.getHeaders());
        String holdingId = location.getHoldingId();
        RequestEntry requestEntry = new RequestEntry(INVENTORY_LOOKUP_ENDPOINTS.get(HOLDINGS_RECORDS_BY_ID_ENDPOINT)).withId(holdingId);
        CompletableFuture<String> holdingIdFuture;
        var holdingIdKey = String.format(TENANT_SPECIFIC_KEY_FORMAT, tenantId, "getOrCreateHoldingsRecord", holdingId);
        String holdingIdCached = ctx.get(holdingIdKey);
        if (holdingIdCached != null) {
            holdingIdFuture = CompletableFuture.completedFuture(holdingIdCached);
        } else {
            holdingIdFuture = restClient.getAsJsonObject(requestEntry, requestContext).whenComplete((id, err) -> ctx.put(holdingIdKey, id)).thenApply(holdingJson -> {
                var id = HelperUtils.extractId(holdingJson);
                ctx.put(holdingIdKey, id);
                return id;
            });
        }
        return holdingIdFuture.exceptionally(throwable -> {
            if (throwable.getCause() instanceof HttpException && ((HttpException) throwable.getCause()).getCode() == 404) {
                String msg = String.format(HOLDINGS_BY_ID_NOT_FOUND.getDescription(), holdingId);
                Error error = new Error().withCode(HOLDINGS_BY_ID_NOT_FOUND.getCode()).withMessage(msg);
                throw new CompletionException(new HttpException(NOT_FOUND, error));
            } else {
                throw new CompletionException(throwable.getCause());
            }
        });
    } else {
        return createHoldingsRecord(instanceId, location.getLocationId(), PostResponseType.UUID, String.class, requestContext);
    }
}
Also used : Context(io.vertx.core.Context) RequestContext(org.folio.rest.core.models.RequestContext) CheckInPiece(org.folio.rest.jaxrs.model.CheckInPiece) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) HelperUtils.collectResultsOnSuccess(org.folio.orders.utils.HelperUtils.collectResultsOnSuccess) StringUtils(org.apache.commons.lang3.StringUtils) Context(io.vertx.core.Context) StreamEx.ofSubLists(one.util.streamex.StreamEx.ofSubLists) MISSING_INSTANCE_TYPE(org.folio.rest.core.exceptions.ErrorCodes.MISSING_INSTANCE_TYPE) Collections.singletonList(java.util.Collections.singletonList) ISBN_NOT_VALID(org.folio.rest.core.exceptions.ErrorCodes.ISBN_NOT_VALID) PoLineCommonUtil(org.folio.orders.utils.PoLineCommonUtil) HelperUtils.convertIdsToCqlQuery(org.folio.orders.utils.HelperUtils.convertIdsToCqlQuery) Map(java.util.Map) ListUtils(org.apache.commons.collections4.ListUtils) HOLDINGS_BY_ID_NOT_FOUND(org.folio.rest.core.exceptions.ErrorCodes.HOLDINGS_BY_ID_NOT_FOUND) PARTIALLY_RETURNED_COLLECTION(org.folio.rest.core.exceptions.ErrorCodes.PARTIALLY_RETURNED_COLLECTION) JsonObject(io.vertx.core.json.JsonObject) ORDER_CONFIG_MODULE_NAME(org.folio.orders.utils.HelperUtils.ORDER_CONFIG_MODULE_NAME) PieceStorageService(org.folio.service.pieces.PieceStorageService) LANG(org.folio.orders.utils.HelperUtils.LANG) Location(org.folio.rest.jaxrs.model.Location) Collection(java.util.Collection) ErrorCodes(org.folio.rest.core.exceptions.ErrorCodes) CompletionException(java.util.concurrent.CompletionException) HelperUtils.handleGetRequest(org.folio.orders.utils.HelperUtils.handleGetRequest) Collectors(java.util.stream.Collectors) TenantTool(org.folio.rest.tools.utils.TenantTool) Collectors.joining(java.util.stream.Collectors.joining) ConfigurationEntriesService(org.folio.service.configuration.ConfigurationEntriesService) Objects(java.util.Objects) List(java.util.List) CollectionUtils.isNotEmpty(org.apache.commons.collections4.CollectionUtils.isNotEmpty) Logger(org.apache.logging.log4j.Logger) Response(javax.ws.rs.core.Response) PieceItemPair(org.folio.models.PieceItemPair) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) StreamEx(one.util.streamex.StreamEx) HelperUtils.getFirstObjectFromResponse(org.folio.orders.utils.HelperUtils.getFirstObjectFromResponse) Optional(java.util.Optional) Parameter(org.folio.rest.jaxrs.model.Parameter) IntStreamEx(one.util.streamex.IntStreamEx) ITEM_CREATION_FAILED(org.folio.rest.core.exceptions.ErrorCodes.ITEM_CREATION_FAILED) MISSING_INSTANCE_STATUS(org.folio.rest.core.exceptions.ErrorCodes.MISSING_INSTANCE_STATUS) ELECTRONIC_RESOURCE(org.folio.rest.jaxrs.model.CompositePoLine.OrderFormat.ELECTRONIC_RESOURCE) RestClient(org.folio.rest.core.RestClient) HttpException(org.folio.rest.core.exceptions.HttpException) ProductId(org.folio.rest.jaxrs.model.ProductId) CompletableFuture(java.util.concurrent.CompletableFuture) FolioVertxCompletableFuture(org.folio.completablefuture.FolioVertxCompletableFuture) Contributor(org.folio.rest.jaxrs.model.Contributor) CollectionUtils(org.apache.commons.collections4.CollectionUtils) SharedData(io.vertx.core.shareddata.SharedData) ArrayList(java.util.ArrayList) MAX_IDS_FOR_GET_RQ(org.folio.rest.RestConstants.MAX_IDS_FOR_GET_RQ) MISSING_LOAN_TYPE(org.folio.rest.core.exceptions.ErrorCodes.MISSING_LOAN_TYPE) PoLineUpdateHolder(org.folio.models.PoLineUpdateHolder) Title(org.folio.rest.jaxrs.model.Title) HelperUtils.extractId(org.folio.orders.utils.HelperUtils.extractId) CompletableFuture.allOf(java.util.concurrent.CompletableFuture.allOf) RequestContext(org.folio.rest.core.models.RequestContext) ReceivedItem(org.folio.rest.jaxrs.model.ReceivedItem) HelperUtils.isProductIdsExist(org.folio.orders.utils.HelperUtils.isProductIdsExist) Piece(org.folio.rest.jaxrs.model.Piece) HelperUtils(org.folio.orders.utils.HelperUtils) MISSING_CONTRIBUTOR_NAME_TYPE(org.folio.rest.core.exceptions.ErrorCodes.MISSING_CONTRIBUTOR_NAME_TYPE) RequestEntry(org.folio.rest.core.models.RequestEntry) PostResponseType(org.folio.rest.core.PostResponseType) InventoryException(org.folio.rest.core.exceptions.InventoryException) NOT_FOUND(org.folio.rest.RestConstants.NOT_FOUND) Error(org.folio.rest.jaxrs.model.Error) JsonArray(io.vertx.core.json.JsonArray) Collectors.toList(java.util.stream.Collectors.toList) Lock(io.vertx.core.shareddata.Lock) HelperUtils.encodeQuery(org.folio.orders.utils.HelperUtils.encodeQuery) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) CompletionException(java.util.concurrent.CompletionException) Error(org.folio.rest.jaxrs.model.Error) HttpException(org.folio.rest.core.exceptions.HttpException) RequestEntry(org.folio.rest.core.models.RequestEntry)

Aggregations

RequestEntry (org.folio.rest.core.models.RequestEntry)96 JsonObject (io.vertx.core.json.JsonObject)38 CompletableFuture (java.util.concurrent.CompletableFuture)37 RequestContext (org.folio.rest.core.models.RequestContext)33 Test (org.junit.jupiter.api.Test)30 Collections (java.util.Collections)22 List (java.util.List)21 RestClient (org.folio.rest.core.RestClient)21 LogManager (org.apache.logging.log4j.LogManager)20 Logger (org.apache.logging.log4j.Logger)20 Map (java.util.Map)19 CompletionException (java.util.concurrent.CompletionException)19 Transaction (org.folio.rest.acq.model.finance.Transaction)18 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)17 Collectors.toList (java.util.stream.Collectors.toList)16 TenantTool (org.folio.rest.tools.utils.TenantTool)16 Collections.singletonList (java.util.Collections.singletonList)14 UUID (java.util.UUID)14 Collectors.joining (java.util.stream.Collectors.joining)14 Vertx (io.vertx.core.Vertx)13