Search in sources :

Example 21 with RequestEntry

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

the class InventoryManager method createItemInInventory.

/**
 * Creates new entry in the inventory storage based on the PO line data.
 *
 * @param itemData json to post
 * @return id of newly created entity Record
 */
private CompletableFuture<String> createItemInInventory(JsonObject itemData, RequestContext requestContext) {
    CompletableFuture<String> future = new CompletableFuture<>();
    RequestEntry requestEntry = new RequestEntry(ITEM_STOR_ENDPOINT).withQueryParameter(LANG, "en");
    logger.info("Trying to create Item in inventory");
    restClient.post(requestEntry, itemData, PostResponseType.UUID, String.class, requestContext).thenApply(future::complete).exceptionally(throwable -> {
        logger.error(ITEM_CREATION_FAILED.getDescription());
        future.complete(null);
        return null;
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) FolioVertxCompletableFuture(org.folio.completablefuture.FolioVertxCompletableFuture) RequestEntry(org.folio.rest.core.models.RequestEntry)

Example 22 with RequestEntry

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

the class InventoryManager method getItemRecordsByIds.

/**
 * Returns list of item records for specified id's.
 *
 * @param ids List of item id's
 * @return future with list of item records
 */
public CompletableFuture<List<JsonObject>> getItemRecordsByIds(List<String> ids, RequestContext requestContext) {
    String query = convertIdsToCqlQuery(ids);
    RequestEntry requestEntry = new RequestEntry(INVENTORY_LOOKUP_ENDPOINTS.get(ITEMS)).withQuery(query).withOffset(0).withLimit(ids.size());
    return restClient.getAsJsonObject(requestEntry, requestContext).thenApply(response -> extractEntities(response, ITEMS));
}
Also used : RequestEntry(org.folio.rest.core.models.RequestEntry)

Example 23 with RequestEntry

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

the class InventoryManager method createInstanceRecord.

/**
 * Creates Instance Record in Inventory and returns its Id.
 *
 * @param compPOL PO line to create Instance Record for
 * @return id of newly created Instance Record
 */
private CompletableFuture<String> createInstanceRecord(CompositePoLine compPOL, RequestContext requestContext) {
    logger.debug("Start processing instance record");
    JsonObject lookupObj = new JsonObject();
    CompletableFuture<Void> instanceTypeFuture = getEntryId(INSTANCE_TYPES, MISSING_INSTANCE_TYPE, requestContext).thenAccept(lookupObj::mergeIn);
    CompletableFuture<Void> statusFuture = getEntryId(INSTANCE_STATUSES, MISSING_INSTANCE_STATUS, requestContext).thenAccept(lookupObj::mergeIn);
    CompletableFuture<Void> contributorNameTypeIdFuture = verifyContributorNameTypesExist(compPOL.getContributors(), requestContext);
    return CompletableFuture.allOf(instanceTypeFuture, statusFuture, contributorNameTypeIdFuture).thenApply(v -> buildInstanceRecordJsonObject(compPOL, lookupObj)).thenCompose(instanceRecJson -> {
        logger.debug("Instance record to save : {}", instanceRecJson);
        RequestEntry requestEntry = new RequestEntry(INVENTORY_LOOKUP_ENDPOINTS.get(INSTANCES));
        return restClient.post(requestEntry, instanceRecJson, PostResponseType.UUID, String.class, requestContext);
    });
}
Also used : 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) JsonObject(io.vertx.core.json.JsonObject) RequestEntry(org.folio.rest.core.models.RequestEntry)

Example 24 with RequestEntry

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

the class InventoryManager method getInstanceRecord.

/**
 * Returns Id of the Instance Record corresponding to given PO line.
 * Instance record is either retrieved from Inventory or a new one is created if no corresponding Record exists.
 *
 * @param compPOL PO line to retrieve Instance Record Id for
 * @return future with Instance Id
 */
public CompletableFuture<String> getInstanceRecord(CompositePoLine compPOL, boolean isInstanceMatchingDisabled, RequestContext requestContext) {
    // proceed with new Instance Record creation if no productId is provided
    if (!isProductIdsExist(compPOL) || isInstanceMatchingDisabled) {
        return createInstanceRecord(compPOL, requestContext);
    }
    String query = compPOL.getDetails().getProductIds().stream().map(this::buildProductIdQuery).collect(joining(" or "));
    // query contains special characters so must be encoded before submitting
    RequestEntry requestEntry = new RequestEntry(INVENTORY_LOOKUP_ENDPOINTS.get(INSTANCES)).withQuery(query).withOffset(0).withLimit(Integer.MAX_VALUE);
    return restClient.getAsJsonObject(requestEntry, requestContext).thenCompose(instances -> {
        if (!instances.getJsonArray(INSTANCES).isEmpty()) {
            return completedFuture(extractId(getFirstObjectFromResponse(instances, INSTANCES)));
        }
        return createInstanceRecord(compPOL, requestContext);
    });
}
Also used : RequestEntry(org.folio.rest.core.models.RequestEntry)

Example 25 with RequestEntry

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

the class RolloverRetrieveService method getLedgerFyRollovers.

public CompletableFuture<List<LedgerFiscalYearRollover>> getLedgerFyRollovers(String fiscalYeaId, List<String> ledgerIds, RequestContext requestContext) {
    String query = "toFiscalYearId==" + fiscalYeaId + AND + convertIdsToCqlQuery(ledgerIds, "ledgerId");
    RequestEntry requestEntry = new RequestEntry(LEDGER_ROLLOVERS_ENDPOINT).withQuery(query).withOffset(0).withLimit(ledgerIds.size());
    return restClient.get(requestEntry, requestContext, LedgerFiscalYearRolloverCollection.class).thenApply(LedgerFiscalYearRolloverCollection::getLedgerFiscalYearRollovers);
}
Also used : LedgerFiscalYearRolloverCollection(org.folio.rest.jaxrs.model.LedgerFiscalYearRolloverCollection) 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