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;
}
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));
}
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);
});
}
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);
});
}
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);
}
Aggregations